In process

This commit is contained in:
goblinrf 2024-05-12 15:13:03 +04:00
parent e2d10d9bf1
commit d860520b1c
52 changed files with 1275 additions and 471 deletions

View File

@ -0,0 +1,128 @@
using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.StoragesContracts;
using DinerDataModels;
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 DinerBusinessLogic.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)
{
//проверка на то, является ли тип интерфейсом и унаследован ли он от IId
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;
}
//три строчки ниже - сериализация файлов в json
var jsonFormatter = new DataContractJsonSerializer(typeof(List<T>));
using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
jsonFormatter.WriteObject(fs, records);
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.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,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.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 DinerContracts.BindingModels
{
public class BackUpSaveBinidngModel
{
public string FolderName { get; set; } = string.Empty;
}
}

View File

@ -8,6 +8,7 @@ namespace DinerContracts.BindingModels
{ {
public class MailConfigBindingModel public class MailConfigBindingModel
{ {
public int Id { get; set; }
public string MailLogin { get; set; } = string.Empty; public string MailLogin { get; set; } = string.Empty;
public string MailPassword { get; set; } = string.Empty; public string MailPassword { get; set; } = string.Empty;

View File

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

View File

@ -0,0 +1,63 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.DI
{
/// <summary>
/// Менеджер для работы с зависимостями
/// </summary>
public class DependencyManager
{
private readonly IDependencyContainer _dependencyManager;
private static DependencyManager? _manager;
private static readonly object _locjObject = new();
private DependencyManager()
{
_dependencyManager = new UnityDependencyContainer();
}
public static DependencyManager Instance
{
get
{
if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } }
return _manager;
}
}
//Иницализация библиотек, в которых идут установки зависомстей
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,25 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.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,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.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 DinerContracts.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 DinerContracts.DI
{
public static partial 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.Microsoft.Logging;
using Unity;
namespace DinerContracts.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

@ -13,6 +13,8 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<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,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.StoragesContracts
{
public interface IBackUpInfo
{
List<T>? GetList<T>() where T : class, new();
Type? GetTypeByModelInterface(string modelInterfaceName);
}
}

View File

@ -1,21 +1,17 @@
using DinerDataModels.Models; using DinerContracts.Attributes;
using System; using DinerDataModels.Models;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.ViewModels namespace DinerContracts.ViewModels
{ {
public class ClientViewModel : IClientModel public class ClientViewModel : IClientModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("ФИО клиента")] [Column(title: "ФИО клиента", width: 150)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта)")] [Column(title: "Логие (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")] [Column(title: "Пароль", width: 150)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
} }
} }

View File

@ -1,14 +1,16 @@
using System.ComponentModel; using System.ComponentModel;
using DinerDataModels.Models; using DinerDataModels.Models;
using DinerContracts.Attributes;
namespace DinerContracts.ViewModels namespace DinerContracts.ViewModels
{ {
public class ComponentViewModel : IComponentModel public class ComponentViewModel : IComponentModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название компонента")] [Column(title: "Название компонента", width: 150)]
public string ComponentName { get; set; } = string.Empty; public string ComponentName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column(title: "Цена", width: 150)]
public double Cost { get; set; } public double Cost { get; set; }
} }
} }

View File

@ -1,22 +1,24 @@
using DinerDataModels.Models; using DinerContracts.Attributes;
using DinerDataModels.Models;
using System.ComponentModel; using System.ComponentModel;
namespace DinerContracts.ViewModels namespace DinerContracts.ViewModels
{ {
public class ImplementerViewModel : IImplementerModel public class ImplementerViewModel : IImplementerModel
{ {
public int Id { get; set; } [Column(visible: false)]
public int Id { get; set; }
[DisplayName("ФИО исполнителя")] [Column(title: "ФИО исполнителя", width: 150)]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Пароль")] [Column(title: "Пароль", width: 150)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[DisplayName("Стаж")] [Column(title: "Стаж", width: 150)]
public int WorkExperience { get; set; } public int WorkExperience { get; set; }
[DisplayName("Квалификация")] [Column(title: "Квалификация", width: 150)]
public int Qualification { get; set; } public int Qualification { get; set; }
} }
} }

View File

@ -1,23 +1,24 @@
using System.ComponentModel; using DinerContracts.Attributes;
using System.ComponentModel;
namespace DinerContracts.ViewModels namespace DinerContracts.ViewModels
{ {
public class MessageInfoViewModel public class MessageInfoViewModel
{ {
[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("Отправитель")] [DisplayName("Отправитель")]
public string SenderName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty;
[DisplayName("Дата отправки")] [Column(title: "Дата отправки", width: 150)]
public DateTime DateDelivery { get; set; } = DateTime.Now; public DateTime DateDelivery { get; set; } = DateTime.Now;
[DisplayName("Заголовок")] [Column(title: "Заголовок", width: 150)]
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
[DisplayName("Текст")] [Column(title: "Текст", width: 150)]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
} }
} }

View File

@ -1,32 +1,36 @@
using System.ComponentModel; using System.ComponentModel;
using DinerDataModels.Models; using DinerDataModels.Models;
using DinerDataModels.Enum; using DinerDataModels.Enum;
using DinerContracts.Attributes;
namespace DinerContracts.ViewModels namespace DinerContracts.ViewModels
{ {
public class OrderViewModel : IOrderModel public class OrderViewModel : IOrderModel
{ {
[DisplayName("Номер")] [Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[Column(visible: false)]
public int ClientId { get; set; } public int ClientId { get; set; }
[Column(visible: false)]
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[Column(visible: false)]
public int SnackId { get; set; } public int SnackId { get; set; }
[DisplayName("Изделие")]
public string SnackName { get; set; } = string.Empty;
[DisplayName("Клиент")] [Column(title: "Изделие", width: 150)]
public string SnackName { get; set; } = string.Empty;
[Column(title: "ФИО клиента", width: 150)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Исполнитель")] [Column(title: "ФИО исполнителя", width: 150)]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Количество")] [Column(title: "Количество", width: 150)]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [Column(title: "Сумма", width: 150)]
public double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Статус")] [Column(title: "Статус", width: 150)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")] [Column(title: "Дата создания", width: 150)]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")] [Column(title: "Дата выполнения", width: 150)]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
} }
} }

View File

@ -1,15 +1,18 @@
using DinerDataModels.Models; using DinerContracts.Attributes;
using DinerDataModels.Models;
using System.ComponentModel; using System.ComponentModel;
namespace DinerContracts.ViewModels namespace DinerContracts.ViewModels
{ {
public class SnackViewModel : ISnackModel public class SnackViewModel : ISnackModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название изделия")] [Column(title: "Навание изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string SnackName { get; set; } = string.Empty; public string SnackName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column(title: "Цена", width: 150)]
public double Price { get; set; } public double Price { get; set; }
[Column(visible: false)]
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new();
} }

View File

@ -0,0 +1,37 @@
using DinerContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerListImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
var source = DataListSingleton.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

@ -0,0 +1,33 @@
using DinerContracts.DI;
using DinerContracts.StoragesContracts;
using DinerListImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerListImplement
{
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<ISnackStorage, SnackStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -4,6 +4,7 @@ using DinerDataModels.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;

View File

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

@ -36,13 +36,7 @@ namespace Diner
_logger.LogInformation("Загрузка клиентов"); _logger.LogInformation("Загрузка клиентов");
try try
{ {
var list = _clientLogic.ReadList(null); dataGridView.FillandConfigGrid(_clientLogic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Успешная загрузка клиентов"); _logger.LogInformation("Успешная загрузка клиентов");
} }

View File

@ -1,6 +1,7 @@
using DinerContracts.BindingModels; using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts; using DinerContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using DinerContracts.DI;
namespace Diner namespace Diner
{ {
@ -22,13 +23,7 @@ namespace Diner
{ {
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)
@ -40,29 +35,24 @@ namespace Diner
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK)
{
LoadData(); LoadData();
}
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) form.Id =
{
form.Id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
}
} }
} }
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)

View File

@ -10,6 +10,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 DinerContracts.DI;
namespace Diner namespace Diner
{ {
@ -36,16 +37,9 @@ namespace Diner
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null) _logger.LogInformation("Загрузка исполнителей");
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -57,9 +51,9 @@ namespace Diner
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -72,20 +66,17 @@ namespace Diner
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var form = DependencyManager.Instance.Resolve<FormImplementer>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (service is FormImplementer form) if (form.ShowDialog() == DialogResult.OK)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData(); LoadData();
}
} }
} }
} }
private void ButtonDelete_Click(object sender, EventArgs e) private void ButtonDelete_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)

View File

@ -37,17 +37,9 @@ namespace Diner
try try
{ {
var list = _messageLogic.ReadList(null); dataGridView.FillandConfigGrid(_messageLogic.ReadList(null));
if (list != null) _logger.LogInformation("Успешная загрузка писем");
{
dataGridView.DataSource = list;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Успешная загрузка писем");
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -20,198 +20,209 @@
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain));
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonCreateOrder = new Button(); buttonCreateOrder = new Button();
buttonIssuedOrder = new Button(); buttonIssuedOrder = new Button();
buttonRef = new Button(); buttonRef = new Button();
toolStrip = new ToolStrip(); toolStrip = new ToolStrip();
manualsToolStripLabel = new ToolStripDropDownButton(); manualsToolStripLabel = new ToolStripDropDownButton();
componentsToolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem();
snacksToolStripMenuItem = new ToolStripMenuItem(); snacksToolStripMenuItem = new ToolStripMenuItem();
clientsToolStripMenuItem = new ToolStripMenuItem(); clientsToolStripMenuItem = new ToolStripMenuItem();
исполнителиToolStripMenuItem = new ToolStripMenuItem(); исполнителиToolStripMenuItem = new ToolStripMenuItem();
manualsStripDropDownButton = new ToolStripDropDownButton(); manualsStripDropDownButton = new ToolStripDropDownButton();
listComponentsToolStripMenuItem = new ToolStripMenuItem(); listComponentsToolStripMenuItem = new ToolStripMenuItem();
componentSnacksToolStripMenuItem = new ToolStripMenuItem(); componentSnacksToolStripMenuItem = new ToolStripMenuItem();
ordersToolStripMenuItem = new ToolStripMenuItem(); ordersToolStripMenuItem = new ToolStripMenuItem();
toolStripDropDownButton1 = new ToolStripDropDownButton(); toolStripDropDownButton1 = new ToolStripDropDownButton();
workWithClientsToolStripMenuItem = new ToolStripMenuItem(); toolStripDropDownButtonMails = new ToolStripDropDownButton();
toolStripDropDownButtonMails = new ToolStripDropDownButton(); workWithClientsToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); toolStripDropDownButtonBackup = new ToolStripDropDownButton();
toolStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); toolStrip.SuspendLayout();
// SuspendLayout();
// dataGridView //
// // dataGridView
dataGridView.BackgroundColor = SystemColors.ButtonHighlight; //
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
dataGridView.Location = new Point(0, 27); dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Name = "dataGridView"; dataGridView.Location = new Point(0, 27);
dataGridView.RowHeadersWidth = 51; dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 29; dataGridView.RowHeadersWidth = 51;
dataGridView.Size = new Size(986, 421); dataGridView.RowTemplate.Height = 29;
dataGridView.TabIndex = 0; dataGridView.Size = new Size(986, 421);
// dataGridView.TabIndex = 0;
// buttonCreateOrder //
// // buttonCreateOrder
buttonCreateOrder.Location = new Point(1040, 88); //
buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Location = new Point(1040, 88);
buttonCreateOrder.Size = new Size(202, 29); buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.TabIndex = 1; buttonCreateOrder.Size = new Size(202, 29);
buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.TabIndex = 1;
buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.Click += ButtonCreateOrder_Click; buttonCreateOrder.UseVisualStyleBackColor = true;
// buttonCreateOrder.Click += ButtonCreateOrder_Click;
// buttonIssuedOrder //
// // buttonIssuedOrder
buttonIssuedOrder.Location = new Point(1040, 159); //
buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Location = new Point(1040, 159);
buttonIssuedOrder.Size = new Size(202, 29); buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.TabIndex = 4; buttonIssuedOrder.Size = new Size(202, 29);
buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.TabIndex = 4;
buttonIssuedOrder.UseVisualStyleBackColor = true; buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.Click += ButtonIssuedOrder_Click; buttonIssuedOrder.UseVisualStyleBackColor = true;
// buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
// buttonRef //
// // buttonRef
buttonRef.Location = new Point(1040, 233); //
buttonRef.Name = "buttonRef"; buttonRef.Location = new Point(1040, 233);
buttonRef.Size = new Size(202, 29); buttonRef.Name = "buttonRef";
buttonRef.TabIndex = 5; buttonRef.Size = new Size(202, 29);
buttonRef.Text = "Обновить список"; buttonRef.TabIndex = 5;
buttonRef.UseVisualStyleBackColor = true; buttonRef.Text = "Обновить список";
buttonRef.Click += ButtonRef_Click; buttonRef.UseVisualStyleBackColor = true;
// buttonRef.Click += ButtonRef_Click;
// toolStrip //
// // toolStrip
toolStrip.ImageScalingSize = new Size(20, 20); //
toolStrip.Items.AddRange(new ToolStripItem[] { manualsToolStripLabel, manualsStripDropDownButton, toolStripDropDownButton1, toolStripDropDownButtonMails }); toolStrip.ImageScalingSize = new Size(20, 20);
toolStrip.Location = new Point(0, 0); toolStrip.Items.AddRange(new ToolStripItem[] { manualsToolStripLabel, manualsStripDropDownButton, toolStripDropDownButton1, toolStripDropDownButtonMails, toolStripDropDownButtonBackup });
toolStrip.Name = "toolStrip"; toolStrip.Location = new Point(0, 0);
toolStrip.Size = new Size(1280, 27); toolStrip.Name = "toolStrip";
toolStrip.TabIndex = 6; toolStrip.Size = new Size(1280, 27);
toolStrip.Text = "toolStrip1"; toolStrip.TabIndex = 6;
// toolStrip.Text = "toolStrip1";
// manualsToolStripLabel //
// // manualsToolStripLabel
manualsToolStripLabel.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, snacksToolStripMenuItem, clientsToolStripMenuItem, исполнителиToolStripMenuItem }); //
manualsToolStripLabel.Name = "manualsToolStripLabel"; manualsToolStripLabel.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, snacksToolStripMenuItem, clientsToolStripMenuItem, исполнителиToolStripMenuItem });
manualsToolStripLabel.Size = new Size(117, 24); manualsToolStripLabel.Name = "manualsToolStripLabel";
manualsToolStripLabel.Text = "Справочники"; manualsToolStripLabel.Size = new Size(117, 24);
// manualsToolStripLabel.Text = "Справочники";
// componentsToolStripMenuItem //
// // componentsToolStripMenuItem
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; //
componentsToolStripMenuItem.Size = new Size(185, 26); componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
componentsToolStripMenuItem.Text = "Компоненты"; componentsToolStripMenuItem.Size = new Size(224, 26);
componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; componentsToolStripMenuItem.Text = "Компоненты";
// componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click;
// snacksToolStripMenuItem //
// // snacksToolStripMenuItem
snacksToolStripMenuItem.Name = "snacksToolStripMenuItem"; //
snacksToolStripMenuItem.Size = new Size(185, 26); snacksToolStripMenuItem.Name = "snacksToolStripMenuItem";
snacksToolStripMenuItem.Text = "Закуски"; snacksToolStripMenuItem.Size = new Size(224, 26);
snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click; snacksToolStripMenuItem.Text = "Закуски";
// snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click;
// clientsToolStripMenuItem //
// // clientsToolStripMenuItem
clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; //
clientsToolStripMenuItem.Size = new Size(185, 26); clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
clientsToolStripMenuItem.Text = "Клиенты"; clientsToolStripMenuItem.Size = new Size(224, 26);
clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; clientsToolStripMenuItem.Text = "Клиенты";
// clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
// исполнителиToolStripMenuItem //
// // исполнителиToolStripMenuItem
исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem"; //
исполнителиToolStripMenuItem.Size = new Size(185, 26); исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem";
исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Size = new Size(224, 26);
исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; исполнителиToolStripMenuItem.Text = "Исполнители";
// исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click;
// manualsStripDropDownButton //
// // manualsStripDropDownButton
manualsStripDropDownButton.DropDownItems.AddRange(new ToolStripItem[] { listComponentsToolStripMenuItem, componentSnacksToolStripMenuItem, ordersToolStripMenuItem }); //
manualsStripDropDownButton.Name = "manualsStripDropDownButton"; manualsStripDropDownButton.DropDownItems.AddRange(new ToolStripItem[] { listComponentsToolStripMenuItem, componentSnacksToolStripMenuItem, ordersToolStripMenuItem });
manualsStripDropDownButton.Size = new Size(73, 24); manualsStripDropDownButton.Name = "manualsStripDropDownButton";
manualsStripDropDownButton.Text = "Отчеты"; manualsStripDropDownButton.Size = new Size(73, 24);
// manualsStripDropDownButton.Text = "Отчеты";
// listComponentsToolStripMenuItem //
// // listComponentsToolStripMenuItem
listComponentsToolStripMenuItem.Name = "listComponentsToolStripMenuItem"; //
listComponentsToolStripMenuItem.Size = new Size(267, 26); listComponentsToolStripMenuItem.Name = "listComponentsToolStripMenuItem";
listComponentsToolStripMenuItem.Text = "Список закусок"; listComponentsToolStripMenuItem.Size = new Size(267, 26);
listComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; listComponentsToolStripMenuItem.Text = "Список закусок";
// listComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
// componentSnacksToolStripMenuItem //
// // componentSnacksToolStripMenuItem
componentSnacksToolStripMenuItem.Name = "componentSnacksToolStripMenuItem"; //
componentSnacksToolStripMenuItem.Size = new Size(267, 26); componentSnacksToolStripMenuItem.Name = "componentSnacksToolStripMenuItem";
componentSnacksToolStripMenuItem.Text = "Закуски по компонентам"; componentSnacksToolStripMenuItem.Size = new Size(267, 26);
componentSnacksToolStripMenuItem.Click += ComponentSnacksToolStripMenuItem_Click; componentSnacksToolStripMenuItem.Text = "Закуски по компонентам";
// componentSnacksToolStripMenuItem.Click += ComponentSnacksToolStripMenuItem_Click;
// ordersToolStripMenuItem //
// // ordersToolStripMenuItem
ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; //
ordersToolStripMenuItem.Size = new Size(267, 26); ordersToolStripMenuItem.Name = "ordersToolStripMenuItem";
ordersToolStripMenuItem.Text = "Список заказов"; ordersToolStripMenuItem.Size = new Size(267, 26);
ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; ordersToolStripMenuItem.Text = "Список заказов";
// ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
// toolStripDropDownButton1 //
// // toolStripDropDownButton1
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; //
toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image");
toolStripDropDownButton1.Name = "toolStripDropDownButton1"; toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
toolStripDropDownButton1.Size = new Size(114, 24); toolStripDropDownButton1.Name = "toolStripDropDownButton1";
toolStripDropDownButton1.Text = "Запуск работ"; toolStripDropDownButton1.Size = new Size(114, 24);
toolStripDropDownButton1.Click += WorkProcessToolStripDropDownButton1_Click; toolStripDropDownButton1.Text = "Запуск работ";
// toolStripDropDownButton1.Click += WorkProcessToolStripDropDownButton1_Click;
// workWithClientsToolStripMenuItem //
// // toolStripDropDownButtonMails
workWithClientsToolStripMenuItem.Name = "workWithClientsToolStripMenuItem"; //
workWithClientsToolStripMenuItem.Size = new Size(32, 19); toolStripDropDownButtonMails.DisplayStyle = ToolStripItemDisplayStyle.Text;
// toolStripDropDownButtonMails.Image = (Image)resources.GetObject("toolStripDropDownButtonMails.Image");
// toolStripDropDownButtonMails toolStripDropDownButtonMails.ImageTransparentColor = Color.Magenta;
// toolStripDropDownButtonMails.Name = "toolStripDropDownButtonMails";
toolStripDropDownButtonMails.DisplayStyle = ToolStripItemDisplayStyle.Text; toolStripDropDownButtonMails.Size = new Size(77, 24);
toolStripDropDownButtonMails.Image = (Image)resources.GetObject("toolStripDropDownButtonMails.Image"); toolStripDropDownButtonMails.Text = "Письма";
toolStripDropDownButtonMails.ImageTransparentColor = Color.Magenta; toolStripDropDownButtonMails.Click += WorkProcessToolStripDropDownButtonMails_Click;
toolStripDropDownButtonMails.Name = "toolStripDropDownButtonMails"; //
toolStripDropDownButtonMails.Size = new Size(77, 24); // workWithClientsToolStripMenuItem
toolStripDropDownButtonMails.Text = "Письма"; //
toolStripDropDownButtonMails.Click += WorkProcessToolStripDropDownButtonMails_Click; workWithClientsToolStripMenuItem.Name = "workWithClientsToolStripMenuItem";
// workWithClientsToolStripMenuItem.Size = new Size(32, 19);
// FormMain //
// // toolStripDropDownButtonBackup
AutoScaleDimensions = new SizeF(8F, 20F); //
AutoScaleMode = AutoScaleMode.Font; toolStripDropDownButtonBackup.DisplayStyle = ToolStripItemDisplayStyle.Text;
ClientSize = new Size(1280, 450); toolStripDropDownButtonBackup.Image = (Image)resources.GetObject("toolStripDropDownButtonBackup.Image");
Controls.Add(toolStrip); toolStripDropDownButtonBackup.ImageTransparentColor = Color.Magenta;
Controls.Add(buttonRef); toolStripDropDownButtonBackup.Name = "toolStripDropDownButtonBackup";
Controls.Add(buttonIssuedOrder); toolStripDropDownButtonBackup.Size = new Size(122, 24);
Controls.Add(buttonCreateOrder); toolStripDropDownButtonBackup.Text = "Создать бэкап";
Controls.Add(dataGridView); toolStripDropDownButtonBackup.Click += WorkProcessToolStripDropDownButtonBackup_Click;
Name = "FormMain"; //
Text = "Закусочная"; // FormMain
Load += FormMain_Load; //
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); AutoScaleDimensions = new SizeF(8F, 20F);
toolStrip.ResumeLayout(false); AutoScaleMode = AutoScaleMode.Font;
toolStrip.PerformLayout(); ClientSize = new Size(1280, 450);
ResumeLayout(false); Controls.Add(toolStrip);
PerformLayout(); Controls.Add(buttonRef);
} Controls.Add(buttonIssuedOrder);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Name = "FormMain";
Text = "Закусочная";
Load += FormMain_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
toolStrip.ResumeLayout(false);
toolStrip.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion #endregion
private DataGridView dataGridView; private DataGridView dataGridView;
private Button buttonCreateOrder; private Button buttonCreateOrder;
private Button buttonIssuedOrder; private Button buttonIssuedOrder;
private Button buttonRef; private Button buttonRef;
@ -228,5 +239,6 @@
private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripDropDownButton toolStripDropDownButton1; private ToolStripDropDownButton toolStripDropDownButton1;
private ToolStripDropDownButton toolStripDropDownButtonMails; private ToolStripDropDownButton toolStripDropDownButtonMails;
} private ToolStripDropDownButton toolStripDropDownButtonBackup;
}
} }

View File

@ -2,6 +2,8 @@
using DinerContracts.BusinessLogicsContracts; using DinerContracts.BusinessLogicsContracts;
using DinerDataModels.Enum; using DinerDataModels.Enum;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using DinerContracts.DI;
using Org.BouncyCastle.Asn1.X509;
namespace Diner namespace Diner
{ {
@ -13,35 +15,27 @@ namespace Diner
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess; 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(); 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)
{ {
LoadData(); LoadData();
} }
private void LoadData() private void LoadData()
{ {
// прописать логику
try try
{ {
var list = _orderLogic.ReadList(null); dataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
if (list != null) _logger.LogInformation("Загрузка заказов");
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SnackId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["SnackName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -51,28 +45,20 @@ namespace Diner
} }
private void ComponentToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var form = DependencyManager.Instance.Resolve<FormComponents>();
if (service is FormComponents form) form.ShowDialog();
{ }
form.ShowDialog();
}
}
private void ProductToolStripMenuItem_Click(object sender, EventArgs e) private void ProductToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSnacks)); var form = DependencyManager.Instance.Resolve<FormSnacks>();
if (service is FormSnacks form) form.ShowDialog();
{ }
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e) private void ButtonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
if (service is FormCreateOrder form) form.ShowDialog();
{ LoadData();
form.ShowDialog();
LoadData();
}
} }
@ -118,54 +104,61 @@ namespace Diner
private void ComponentSnacksToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentSnacksToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportSnackComponents)); var form = DependencyManager.Instance.Resolve<FormReportSnackComponents>();
if (service is FormReportSnackComponents form) form.ShowDialog();
{ }
form.ShowDialog();
}
}
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); var form = DependencyManager.Instance.Resolve<FormReportOrders>();
if (service is FormReportOrders form) form.ShowDialog();
{ }
form.ShowDialog();
}
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormClients)); var form = DependencyManager.Instance.Resolve<FormClients>();
form.ShowDialog();
if (service is FormClients form) }
{
form.ShowDialog();
}
}
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); var form = DependencyManager.Instance.Resolve<FormImplementers>();
form.ShowDialog();
if (service is FormImplementers form)
{
form.ShowDialog();
}
} }
private void WorkProcessToolStripDropDownButton1_Click(object sender, EventArgs e) private void WorkProcessToolStripDropDownButton1_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); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void WorkProcessToolStripDropDownButtonMails_Click(object sender, EventArgs e) private void WorkProcessToolStripDropDownButtonMails_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormMails)); var form = DependencyManager.Instance.Resolve<FormMails>();
if (service is FormMails form) form.ShowDialog();
}
private void WorkProcessToolStripDropDownButtonBackup_Click(object sender, EventArgs e)
{
try
{ {
form.ShowDialog();
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

@ -133,6 +133,17 @@
</value> </value>
</data> </data>
<data name="toolStripDropDownButtonMails.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="toolStripDropDownButtonMails.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw
6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV
vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC
U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T
luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM
qgAAAABJRU5ErkJggg==
</value>
</data>
<data name="toolStripDropDownButtonBackup.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEISURBVEhL3ZErDsJAGIR7DlA47oArV8CDR9RiSDAQPBcA YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEISURBVEhL3ZErDsJAGIR7DlA47oArV8CDR9RiSDAQPBcA

View File

@ -2,6 +2,7 @@
using DinerContracts.BusinessLogicsContracts; using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels; using DinerContracts.SearchModels;
using DinerDataModels.Models; using DinerDataModels.Models;
using DinerContracts.DI;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Diner namespace Diner
@ -70,11 +71,8 @@ namespace Diner
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = var form = DependencyManager.Instance.Resolve<FormSnackComponent>();
Program.ServiceProvider?.GetService(typeof(FormSnackComponent)); if (form.ShowDialog() == DialogResult.OK)
if (service is FormSnackComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
{ {
@ -92,18 +90,15 @@ namespace Diner
form.Count)); form.Count));
} }
LoadData(); LoadData();
}
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = var form = DependencyManager.Instance.Resolve<FormSnackComponent>();
Program.ServiceProvider?.GetService(typeof(FormSnackComponent)); int id =
if (service is FormSnackComponent form)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
form.Count = _productComponents[id].Item2; form.Count = _productComponents[id].Item2;
@ -118,7 +113,6 @@ namespace Diner
LoadData(); LoadData();
} }
} }
}
} }
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {

View File

@ -1,6 +1,7 @@
using DinerContracts.BindingModels; using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts; using DinerContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using DinerContracts.DI;
namespace Diner namespace Diner
{ {
@ -19,18 +20,10 @@ namespace Diner
{ {
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["SnackName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["SnackComponents"].Visible = false;
}
_logger.LogInformation("Загрузка компонентов"); _logger.LogInformation("Загрузка компонентов");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -41,32 +34,26 @@ namespace Diner
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSnack)); var form = DependencyManager.Instance.Resolve<FormSnack>();
if (form.ShowDialog() == DialogResult.OK)
if (service is FormSnack form)
{ {
if (form.ShowDialog() == DialogResult.OK)
{
LoadData(); LoadData();
}
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSnack)); var form = DependencyManager.Instance.Resolve<FormSnack>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (service is FormSnack form) if (form.ShowDialog() == DialogResult.OK)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
} }
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {

View File

@ -9,13 +9,13 @@ using DinerBusinessLogic.OfficePackage;
using DinerBusinessLogic.OfficePackage.Implements; using DinerBusinessLogic.OfficePackage.Implements;
using DinerBusinessLogic.MailWorker; using DinerBusinessLogic.MailWorker;
using DinerContracts.BindingModels; using DinerContracts.BindingModels;
using DinerContracts.DI;
namespace Diner namespace Diner
{ {
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>
@ -26,73 +26,71 @@ namespace Diner
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
var services = new ServiceCollection(); var services = new ServiceCollection();
ConfigureServices(services); InitDependency();
_serviceProvider = services.BuildServiceProvider(); try
try {
{ var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
var mailSender = _serviceProvider.GetService<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, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty,
SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) });
});
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
} }
catch (Exception ex) catch (Exception ex)
{ {
var logger = _serviceProvider.GetService<ILogger>(); var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
}
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
}
Application.Run(_serviceProvider.GetRequiredService<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.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config"); option.AddNLog("nlog.config");
}); });
services.AddTransient<IClientStorage, DinerDataBaseImplement.Implements.ClientStorage>(); DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
services.AddTransient<IComponentStorage, DinerDataBaseImplement.Implements.ComponentStorage>(); DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
services.AddTransient<IOrderStorage, DinerDataBaseImplement.Implements.OrderStorage>(); DependencyManager.Instance.RegisterType<ISnackLogic, SnackLogic>();
services.AddTransient<ISnackStorage, DinerDataBaseImplement.Implements.SnackStorage>(); DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
services.AddTransient<IImplementerStorage, DinerDataBaseImplement.Implements.ImplementerStorage>(); DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
services.AddTransient<IMessageInfoStorage, DinerDataBaseImplement.Implements.MessageInfoStorage>(); DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
services.AddTransient<IClientLogic, ClientLogic>(); DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<IComponentLogic, ComponentLogic>(); DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
services.AddTransient<IOrderLogic, OrderLogic>(); DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<ISnackLogic, SnackLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>(); DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<FormMain>(); DependencyManager.Instance.RegisterType<FormMain>();
services.AddTransient<FormComponent>(); DependencyManager.Instance.RegisterType<FormComponent>();
services.AddTransient<FormComponents>(); DependencyManager.Instance.RegisterType<FormComponents>();
services.AddTransient<FormCreateOrder>(); DependencyManager.Instance.RegisterType<FormCreateOrder>();
services.AddTransient<FormSnack>(); DependencyManager.Instance.RegisterType<FormSnack>();
services.AddTransient<FormSnackComponent>(); DependencyManager.Instance.RegisterType<FormSnackComponent>();
services.AddTransient<FormSnacks>(); DependencyManager.Instance.RegisterType<FormSnack>();
services.AddTransient<FormReportSnackComponents>(); DependencyManager.Instance.RegisterType<FormReportSnackComponents>();
services.AddTransient<FormReportOrders>(); DependencyManager.Instance.RegisterType<FormReportOrders>();
services.AddTransient<FormClients>(); DependencyManager.Instance.RegisterType<FormClients>();
services.AddTransient<FormImplementers>(); DependencyManager.Instance.RegisterType<FormImplementer>();
services.AddTransient<FormImplementer>(); DependencyManager.Instance.RegisterType<FormImplementers>();
services.AddTransient<FormMails>(); 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

@ -0,0 +1,33 @@
using DinerContracts.DI;
using DinerContracts.StoragesContracts;
using DinerDataBaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDataBaseImplement
{
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<ISnackStorage, SnackStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

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

@ -8,20 +8,26 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using DinerContracts.BindingModels; using DinerContracts.BindingModels;
using DinerContracts.ViewModels; using DinerContracts.ViewModels;
using System.Runtime.Serialization;
namespace DinerDataBaseImplement.Models namespace DinerDataBaseImplement.Models
{ {
[DataContract]
public class Client : IClientModel public class Client : IClientModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[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;
[ForeignKey("ClientId")] [ForeignKey("ClientId")]

View File

@ -3,15 +3,20 @@ using DinerContracts.ViewModels;
using DinerDataModels.Models; using DinerDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace DinerDataBaseImplement.Models namespace DinerDataBaseImplement.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<SnackComponent> SnackComponents { get; set; } = new(); public virtual List<SnackComponent> SnackComponents { get; set; } = new();

View File

@ -8,24 +8,31 @@ 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 DinerDataBaseImplement.Models namespace DinerDataBaseImplement.Models
{ {
public class Implementer : IImplementerModel [DataContract]
public class Implementer : IImplementerModel
{ {
public int Id { get; set; } [DataMember]
public int Id { get; set; }
[Required] [Required]
public string ImplementerFIO { get; set; } = string.Empty; [DataMember]
public string ImplementerFIO { get; set; } = string.Empty;
[Required] [Required]
public string Password { get; set; } = string.Empty; [DataMember]
public string Password { get; set; } = string.Empty;
[Required] [Required]
public int WorkExperience { get; set; } [DataMember]
public int WorkExperience { get; set; }
[Required] [Required]
public int Qualification { get; set; } [DataMember]
public int Qualification { get; set; }
[ForeignKey("ImplementerId")] [ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; set; } = new(); public virtual List<Order> Orders { get; set; } = new();

View File

@ -7,12 +7,15 @@ 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 DinerDataBaseImplement.Models namespace DinerDataBaseImplement.Models
{ {
[DataContract]
public class MessageInfo : IMessageInfoModel public class MessageInfo : IMessageInfoModel
{ {
[Key] [Key]
[DataMember]
public string MessageId { get; set; } = string.Empty; public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; } public int? ClientId { get; set; }

View File

@ -4,27 +4,37 @@ using DinerContracts.ViewModels;
using DinerDataModels.Enum; using DinerDataModels.Enum;
using DinerDataModels.Models; using DinerDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Xml.Linq; using System.Xml.Linq;
namespace DinerDataBaseImplement.Models namespace DinerDataBaseImplement.Models
{ {
[DataContract]
public class Order : IOrderModel public class Order : IOrderModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
[DataMember]
public int ClientId { get; private set; } public int ClientId { get; private set; }
[DataMember]
public int? ImplementerId { get; private set; } public int? ImplementerId { get; private set; }
[Required] [Required]
[DataMember]
public int SnackId { get; private set; } public int SnackId { get; private set; }
[Required] [Required]
[DataMember]
public int Count { get; private set; } public int Count { get; private set; }
[Required] [Required]
[DataMember]
public double Sum { get; private set; } public double Sum { get; private set; }
[Required] [Required]
[DataMember]
public OrderStatus Status { get; private set; } public OrderStatus Status { get; private set; }
[Required] [Required]
[DataMember]
public DateTime DateCreate { get; private set; } public DateTime DateCreate { get; private set; }
[DataMember]
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public virtual Snack Snack { get; set; } public virtual Snack Snack { get; set; }

View File

@ -3,18 +3,24 @@ using DinerContracts.ViewModels;
using DinerDataModels.Models; using DinerDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace DinerDataBaseImplement.Models namespace DinerDataBaseImplement.Models
{ {
[DataContract]
public class Snack : ISnackModel public class Snack : ISnackModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
[DataMember]
public string SnackName { get; set; } = string.Empty; public string SnackName { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public double Price { get; set; } public double Price { get; set; }
private Dictionary<int, (IComponentModel, int)>? _snackComponents = null; private Dictionary<int, (IComponentModel, int)>? _snackComponents = null;
[NotMapped] [NotMapped]
[DataMember]
public Dictionary<int, (IComponentModel, int)> SnackComponents public Dictionary<int, (IComponentModel, int)> SnackComponents
{ {
get get

View File

@ -1,12 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DinerDataBaseImplement.Models namespace DinerDataBaseImplement.Models
{ {
[DataContract]
public class SnackComponent public class SnackComponent
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" /> <ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" />
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" /> <ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />
<ProjectReference Include="..\DinerDataBaseImplement\DinerDataBaseImplement.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,33 @@
using DinerContracts.DI;
using DinerContracts.StoragesContracts;
using DinerDataBaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerFileImplement
{
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<ISnackStorage, SnackStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,37 @@
using DinerContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
var source = DataFileSingleton.GetInstance();
return (List<T>?)source.GetType().GetProperties()
.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))
?.GetValue(source);
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
var assembly = typeof(BackUpInfo).Assembly;
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
{
return type;
}
}
return null;
}
}
}

View File

@ -7,17 +7,20 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace DinerFileImplement.Models namespace DinerFileImplement.Models
{ {
[DataContract]
internal class Client : IClientModel internal class Client : IClientModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[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;
public static Client? Create(ClientBindingModel model) public static Client? Create(ClientBindingModel model)

View File

@ -2,13 +2,18 @@
using DinerContracts.ViewModels; using DinerContracts.ViewModels;
using DinerDataModels.Models; using DinerDataModels.Models;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace DinerFileImplement.Models namespace DinerFileImplement.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

@ -7,20 +7,23 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace DinerFileImplement.Models namespace DinerFileImplement.Models
{ {
public class Implementer : IImplementerModel [DataContract]
public class Implementer : IImplementerModel
{ {
public int Id { get; private set; } 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 string ImplementerFIO { get; private set; } = string.Empty; public int Qualification { get; private set; }
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel model) public static Implementer? Create(ImplementerBindingModel model)
{ {

View File

@ -9,27 +9,29 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace DinerDataBaseImplement.Models namespace DinerDataBaseImplement.Models
{ {
[DataContract]
public class MessageInfo : IMessageInfoModel public class MessageInfo : IMessageInfoModel
{ {
[Key] [DataMember]
public string MessageId { get; set; } = string.Empty; public string MessageId { get; set; } = string.Empty;
[DataMember]
public int? ClientId { get; set; } public int? ClientId { get; set; }
[Required] [DataMember]
public string SenderName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty;
[Required] [DataMember]
public DateTime DateDelivery { get; set; } = DateTime.Now; public DateTime DateDelivery { get; set; } = DateTime.Now;
[Required] [DataMember]
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
[Required] [DataMember]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;

View File

@ -4,24 +4,30 @@ using DinerDataModels.Enum;
using DinerDataModels.Models; using DinerDataModels.Models;
using System.Reflection; using System.Reflection;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace DinerFileImplement.Models namespace DinerFileImplement.Models
{ {
[DataContract]
public class Order : IOrderModel public class Order : IOrderModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public int SnackID { get; private set; } public int SnackID { get; private set; }
[DataMember]
public int ClientId { get; private set; } public int ClientId { get; private 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; } public OrderStatus Status { get; private set; }
[DataMember]
public DateTime DateCreate { get; private set; } public DateTime DateCreate { get; private set; }
[DataMember]
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {

View File

@ -2,15 +2,22 @@
using DinerContracts.ViewModels; using DinerContracts.ViewModels;
using DinerDataModels.Models; using DinerDataModels.Models;
using System.Xml.Linq; using System.Xml.Linq;
using System.Runtime.Serialization;
namespace DinerFileImplement.Models namespace DinerFileImplement.Models
{ {
[DataContract]
public class Snack : ISnackModel public class Snack : ISnackModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string SnackName { get; private set; } = string.Empty; public string SnackName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; } public double Price { get; private set; }
[DataMember]
public Dictionary<int, int> Components { get; private set; } = new(); public Dictionary<int, int> Components { get; private set; } = new();
[DataMember]
private Dictionary<int, (IComponentModel, int)>? _snackComponents = null; private Dictionary<int, (IComponentModel, int)>? _snackComponents = null;
public Dictionary<int, (IComponentModel, int)> SnackComponents public Dictionary<int, (IComponentModel, int)> SnackComponents
{ {