PIbd22_Kuznetsov_A.V._lab8

This commit is contained in:
Anatoliy 2024-06-22 21:11:56 +04:00
parent 8d07b0ca4d
commit a1496cfc61
57 changed files with 1466 additions and 247 deletions

View File

@ -0,0 +1,93 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.StoragesContracts;
using SewingDressesDataModels;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.Serialization.Json;
namespace SewingDressesDatabaseImplement.Implements
{
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);
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute
{
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; }
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;
}
}
}

View File

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

View File

@ -4,6 +4,7 @@ namespace SewingDressesContracts.BindingModels
{ {
public class MessageInfoBindingModel : IMessageInfoModel public class MessageInfoBindingModel : IMessageInfoModel
{ {
public int Id { get; set; }
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

@ -0,0 +1,8 @@
using SewingDressesContracts.BindingModels;
namespace SewingDressesContracts.BusinessLogicsContracts
{
public interface IBackUpLogic
{
void CreateBackUp(BackUpSaveBindingModel model);
}
}

View File

@ -0,0 +1,52 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Unity;
using Unity.Microsoft.Logging;
namespace SewingDressesContracts.DI
{
public class DependencyContainerUnity : IDependencyContainer
{
private readonly IUnityContainer _container;
public DependencyContainerUnity()
{
_container = new UnityContainer();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(configure);
_container.AddExtension(new LoggingExtension(loggerFactory));
}
public void RegisterType<T>(bool isSingle) where T : class
{
if (isSingle)
{
_container.RegisterType<T>(TypeLifetime.Singleton);
}
else
{
_container.RegisterType<T>();
}
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
if (isSingle)
{
_container.RegisterType<T, U>(TypeLifetime.Singleton);
}
else
{
_container.RegisterType<T, U>();
}
}
}
}

View File

@ -0,0 +1,66 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.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>();
}
}

View File

@ -0,0 +1,18 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.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,8 @@
namespace SewingDressesContracts.DI
{
public interface IImplementationExtension
{
public int Priority { get; }
public void RegisterServices();
}
}

View File

@ -0,0 +1,60 @@
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 SewingDressesContracts.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>(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>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
if (isSingle)
{
_serviceCollection.AddSingleton<T, U>();
}
else
{
_serviceCollection.AddTransient<T, U>();
}
_serviceProvider = null;
}
}
}

View File

@ -0,0 +1,46 @@
using System.Reflection;
namespace SewingDressesContracts.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

@ -4,14 +4,16 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Nlog" Version="5.2.8" /> <PackageReference Include="Nlog" Version="5.2.8" />
<PackageReference Include="Nlog.Extensions" Version="1.0.1" /> <PackageReference Include="Nlog.Extensions" Version="1.0.1" />
<PackageReference Include="Nlog.Extensions.Logging" Version="5.3.8" /> <PackageReference Include="Nlog.Extensions.Logging" Version="5.3.8" />
<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,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.StoragesContracts
{
public interface IBackUpInfo
{
List<T>? GetList<T>() where T : class, new();
Type? GetTypeByModelInterface(string modelInterfaceName);
}
}

View File

@ -1,16 +1,18 @@
using System.ComponentModel; using System.ComponentModel;
using SewingDressesContracts.Attributes;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
namespace SewingDressesContracts.ViewModels namespace SewingDressesContracts.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 SewingDressesDataModels.Models; using SewingDressesContracts.Attributes;
using SewingDressesDataModels.Models;
using System.ComponentModel; using System.ComponentModel;
namespace SewingDressesContracts.ViewModels namespace SewingDressesContracts.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: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ComponentName { get; set; } = string.Empty; public string ComponentName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column(title: "Цена", width: 100)]
public double Cost { get; set; } public double Cost { get; set; }
} }
} }

View File

@ -1,15 +1,18 @@
using System.ComponentModel; using System.ComponentModel;
using SewingDressesContracts.Attributes;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
namespace SewingDressesContracts.ViewModels namespace SewingDressesContracts.ViewModels
{ {
public class DressViewModel : IDressModel public class DressViewModel : IDressModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название платья")] [Column(title: "Название платья", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string DressName { get; set; } = string.Empty; public string DressName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column(title: "Цена", width:100)]
public double Price { get; set; } public double Price { get; set; }
[Column(visible:false)]
public Dictionary<int, (IComponentModel, int)> DressComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> DressComponents { get; set; } = new();
} }
} }

View File

@ -1,4 +1,5 @@
using SewingDressesDataModels.Models; using SewingDressesContracts.Attributes;
using SewingDressesDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -10,14 +11,15 @@ namespace SewingDressesContracts.ViewModels
{ {
public class ImplementViewModel : IImplementModel public class ImplementViewModel : IImplementModel
{ {
[Column(visible:false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Имя исполнителя")] [Column(title: "Имя исполнителя", width: 150)]
public string ImplementFIO { get; set; } = string.Empty; public string ImplementFIO { 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,20 +1,24 @@
using SewingDressesDataModels.Models; using SewingDressesContracts.Attributes;
using SewingDressesDataModels.Models;
using System.ComponentModel; using System.ComponentModel;
namespace SewingDressesContracts.ViewModels namespace SewingDressesContracts.ViewModels
{ {
public class MessageInfoViewModel : IMessageInfoModel public class MessageInfoViewModel : IMessageInfoModel
{ {
[Column(visible: false)]
public string MessageId { get; set; } = string.Empty; public string MessageId { get; set; } = string.Empty;
[Column(visible: false)]
public int? ClientId { get; set; } public int? ClientId { get; set; }
[DisplayName("Имя отправителя")] [Column(title: "Имя отправителя", width: 150)]
public string SenderName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty;
[DisplayName("Дата доставки")] [Column(title: "Дата доставки", width: 100)]
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
[DisplayName("Тема письма")] [Column(title: "Тема письма", width: 150)]
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
[DisplayName("Внутренности письма")] [Column(title: "Внутренности письма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
[Column(visible: false)]
public int Id { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using System.ComponentModel; using System.ComponentModel;
using SewingDressesContracts.Attributes;
using SewingDressesDataModels.Enums; using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
@ -6,26 +7,29 @@ namespace SewingDressesContracts.ViewModels
{ {
public class OrderViewModel : IOrderModel public class OrderViewModel : IOrderModel
{ {
[DisplayName("Номер")] [Column(title: "Номер", width: 70)]
public int Id { get; set; } public int Id { get; set; }
[Column(visible: false)]
public int DressId { get; set; } public int DressId { get; set; }
[Column(visible: false)]
public int? ImplementId { get; set; } public int? ImplementId { get; set; }
[Column(visible: false)]
public int ClientId { get; set; } public int ClientId { get; set; }
[DisplayName("Имя клиента")] [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? ImplementFIO { get; set; } = string.Empty; public string? ImplementFIO { get; set; } = string.Empty;
[DisplayName("Платье")] [Column(title: "Платье", width: 150)]
public string DressName { get; set; } = string.Empty; public string DressName { get; set; } = string.Empty;
[DisplayName("Количество")] [Column(title: "Количество", width: 100)]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [Column(title:"Сумма", width: 70)]
public double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Статус")] [Column(title: "Статус", width: 100)]
public OrderStatus Status { get; set; } public OrderStatus Status { get; set; }
[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

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

View File

@ -0,0 +1,22 @@
using SewingDressesContracts.DI;
using SewingDressesDatabaseImplement.Implements;
using SewingDressesDatabaseImplement.Models;
using SewingDressesContracts.StoragesContracts;
namespace SewingDressesDatabaseImplement
{
public class DatabaseImplementationExtension : IImplementationExtension
{
public int Priority => 2;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementStorage, ImplementStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IDressStorage, DressStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,301 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SewingDressesDatabaseImplement;
#nullable disable
namespace SewingDressesDatabaseImplement.Migrations
{
[DbContext(typeof(SewingDressesDatabase))]
[Migration("20240621163736_inmig")]
partial class inmig
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.16")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DressName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Dresses");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DressId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("DressId");
b.ToTable("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implements");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageId")
.HasColumnType("nvarchar(450)");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("ClientId")
.HasColumnType("int");
b.Property<DateTime>("DateDelivery")
.HasColumnType("datetime2");
b.Property<int>("Id")
.HasColumnType("int");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DressId")
.HasColumnType("int");
b.Property<int?>("ImplementId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("DressId");
b.HasIndex("ImplementId");
b.ToTable("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component")
.WithMany("DressComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
.WithMany("Components")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Dress");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.MessageInfo", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client")
.WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
.WithMany("Orders")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement")
.WithMany("Orders")
.HasForeignKey("ImplementId");
b.Navigation("Client");
b.Navigation("Dress");
b.Navigation("Implement");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b =>
{
b.Navigation("Messages");
b.Navigation("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Navigation("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b =>
{
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,215 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SewingDressesDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class inmig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Dresses",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DressName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Dresses", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Implements",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ImplementFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
WorkExperience = table.Column<int>(type: "int", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
Qualification = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Implements", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
{
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
Id = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: true),
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
Body = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Messages", x => x.MessageId);
table.ForeignKey(
name: "FK_Messages_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "DressComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DressId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DressComponents", x => x.Id);
table.ForeignKey(
name: "FK_DressComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DressComponents_Dresses_DressId",
column: x => x.DressId,
principalTable: "Dresses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DressId = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false),
ImplementId = table.Column<int>(type: "int", nullable: true),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Dresses_DressId",
column: x => x.DressId,
principalTable: "Dresses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Implements_ImplementId",
column: x => x.ImplementId,
principalTable: "Implements",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_DressComponents_ComponentId",
table: "DressComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_DressComponents_DressId",
table: "DressComponents",
column: "DressId");
migrationBuilder.CreateIndex(
name: "IX_Messages_ClientId",
table: "Messages",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_DressId",
table: "Orders",
column: "DressId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ImplementId",
table: "Orders",
column: "ImplementId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DressComponents");
migrationBuilder.DropTable(
name: "Messages");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Dresses");
migrationBuilder.DropTable(
name: "Implements");
}
}
}

View File

@ -155,6 +155,9 @@ namespace SewingDressesDatabaseImplement.Migrations
b.Property<DateTime>("DateDelivery") b.Property<DateTime>("DateDelivery")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int>("Id")
.HasColumnType("int");
b.Property<string>("SenderName") b.Property<string>("SenderName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");

View File

@ -0,0 +1,27 @@
using SewingDressesContracts.StoragesContracts;
using SewingDressesDatabaseImplement.Models;
namespace SewingDressesDatabaseImplement.Models
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
using var context = new SewingDressesDatabase();
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

@ -4,17 +4,23 @@ using SewingDressesDatabaseImplement.Models;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace SewingDressesDatabaseImplement.Models namespace SewingDressesDatabaseImplement.Models
{ {
[DataContract]
public class Client : IClientModel public class Client : IClientModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
[DataMember]
public string ClientFIO { get; private set; } = string.Empty; public string ClientFIO { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Email { get; private set; } = string.Empty; public string Email { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")] [ForeignKey("ClientId")]

View File

@ -3,15 +3,20 @@ using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace SewingDressesDatabaseImplement.Models namespace SewingDressesDatabaseImplement.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<DressComponent> DressComponents { get; set; } = new(); public virtual List<DressComponent> DressComponents { get; set; } = new();

View File

@ -3,19 +3,24 @@ using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace SewingDressesDatabaseImplement.Models namespace SewingDressesDatabaseImplement.Models
{ {
[DataContract]
public class Dress : IDressModel public class Dress : IDressModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
[DataMember]
public string DressName { get; set; } = string.Empty; public string DressName { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public double Price { get; set; } public double Price { get; set; }
private Dictionary<int, (IComponentModel, int)>? _dressComponents = null; private Dictionary<int, (IComponentModel, int)>? _dressComponents = null;
[NotMapped] [NotMapped]
[DataMember]
public Dictionary<int, (IComponentModel, int)> DressComponents public Dictionary<int, (IComponentModel, int)> DressComponents
{ {
get get

View File

@ -6,21 +6,28 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SewingDressesDatabaseImplement.Models namespace SewingDressesDatabaseImplement.Models
{ {
[DataContract]
public class Implement : IImplementModel public class Implement : IImplementModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
[DataMember]
public string ImplementFIO { get; private set; } = string.Empty; public string ImplementFIO { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public int WorkExperience { get; private set; } public int WorkExperience { get; private set; }
[Required] [Required]
[DataMember]
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public int Qualification { get; private set; } public int Qualification { get; private set; }
[ForeignKey("ImplementId")] [ForeignKey("ImplementId")]
public virtual List<Order>? Orders { get; set; } = new(); public virtual List<Order>? Orders { get; set; } = new();

View File

@ -2,21 +2,30 @@
using SewingDressesContracts.ViewModels; using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace SewingDressesDatabaseImplement.Models namespace SewingDressesDatabaseImplement.Models
{ {
[DataContract]
public class MessageInfo : IMessageInfoModel public class MessageInfo : IMessageInfoModel
{ {
public int Id { get; set; }
[Key] [Key]
[DataMember]
public string MessageId { get; private set; } = string.Empty; public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; } public int? ClientId { get; private set; }
[Required] [Required]
[DataMember]
public string SenderName { get; private set; } = string.Empty; public string SenderName { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public DateTime DateDelivery { get; private set; } public DateTime DateDelivery { get; private set; }
[Required] [Required]
[DataMember]
public string Subject { get; private set; } = string.Empty; public string Subject { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Body { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty;
public virtual Client? Client { get; private set; } public virtual Client? Client { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model) public static MessageInfo? Create(MessageInfoBindingModel model)

View File

@ -4,25 +4,36 @@ using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace SewingDressesDatabaseImplement.Models namespace SewingDressesDatabaseImplement.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 DressId { get; private set; } public int DressId { get; private set; }
[Required] [Required]
[DataMember]
public int ClientId { get; private set; } public int ClientId { get; private set; }
[DataMember]
public int? ImplementId { get; private set; } public int? ImplementId { 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; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
[DataMember]
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public virtual Dress Dress { get; set; } public virtual Dress Dress { get; set; }
public virtual Client Client { get; set; } public virtual Client Client { get; set; }

View File

@ -8,7 +8,7 @@ namespace SewingDressesDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-J8AJ26MV\SQLEXPRESS;Initial Catalog=DressAtelierDatabaseFull30;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-J8AJ26MV\SQLEXPRESS;Initial Catalog=DressAtelierDatabaseFull3512345;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -4,7 +4,6 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -23,4 +22,7 @@
<ProjectReference Include="..\SewingDressesDataModels\SewingDressesDataModels.csproj" /> <ProjectReference Include="..\SewingDressesDataModels\SewingDressesDataModels.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project> </Project>

View File

@ -0,0 +1,21 @@
using SewingDressesContracts.DI;
using SewingDressesContracts.StoragesContracts;
using SewingDressesFileImplement.Implements;
namespace SewingDressesFileImplement
{
public class FileImplementationExtension : IImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementStorage, ImplementStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IDressStorage, DressStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

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

View File

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

View File

@ -1,14 +1,19 @@
using SewingDressesContracts.BindingModels; using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels; using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq; using System.Xml.Linq;
namespace SewingDressesFileImplement.Models namespace SewingDressesFileImplement.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; private set; } public double Cost { get; private set; }
public static Component? Create(ComponentBindingModel model) public static Component? Create(ComponentBindingModel model)
{ {

View File

@ -1,18 +1,24 @@
using SewingDressesContracts.BindingModels; using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels; using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq; using System.Xml.Linq;
namespace SewingDressesFileImplement.Models namespace SewingDressesFileImplement.Models
{ {
[DataContract]
public class Dress : IDressModel public class Dress : IDressModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string DressName { get; private set; } = string.Empty; public string DressName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; } public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new(); public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _dressComponents = null; private Dictionary<int, (IComponentModel, int)>? _dressComponents = null;
[DataMember]
public Dictionary<int, (IComponentModel, int)> DressComponents public Dictionary<int, (IComponentModel, int)> DressComponents
{ {
get get

View File

@ -5,18 +5,25 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace SewingDressesFileImplement.Models namespace SewingDressesFileImplement.Models
{ {
[DataContract]
public class Implement : IImplementModel public class Implement : IImplementModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[DataMember]
public string ImplementFIO { get; set; } = string.Empty; public string ImplementFIO { get; set; } = string.Empty;
[DataMember]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[DataMember]
public int WorkExperience { get; set; } public int WorkExperience { get; set; }
[DataMember]
public int Qualification { get; set; } public int Qualification { get; set; }
public static Implement? Create(ImplementBindingModel? model) public static Implement? Create(ImplementBindingModel? model)
{ {

View File

@ -1,22 +1,26 @@
using SewingDressesContracts.BindingModels; using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels; using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq; using System.Xml.Linq;
namespace SewingDressesFileImplement.Models namespace SewingDressesFileImplement.Models
{ {
[DataContract]
public class MessageInfo : IMessageInfoModel public class MessageInfo : IMessageInfoModel
{ {
public int Id { get; set; }
[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; }
[DataMember]
public string SenderName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
[DataMember]
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
[DataMember]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel? model) public static MessageInfo? Create(MessageInfoBindingModel? model)

View File

@ -3,20 +3,31 @@ using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Enums; using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models; using SewingDressesDataModels.Models;
using System.Data; using System.Data;
using System.Runtime.Serialization;
using System.Xml.Linq; using System.Xml.Linq;
namespace SewingDressesFileImplement.Models namespace SewingDressesFileImplement.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 DressId { get; private set; } public int DressId { get; private set; }
[DataMember]
public int ClientId { get; private set; } public int ClientId { get; private set; }
[DataMember]
public int? ImplementId { get; private set; } public int? ImplementId { 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; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
[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

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

View File

@ -0,0 +1,22 @@
using SewingDressesContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesListImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
throw new NotImplementedException();
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,26 @@
using SewingDressesContracts.DI;
using SewingDressesContracts.StoragesContracts;
using SewingDressesListImplement.Implements;
namespace SewingDressesListImplement
{
public class ListImplementationExtension : IImplementationExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage,
ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage,
ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementStorage,
ImplementStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage,
MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage,
OrderStorage>();
DependencyManager.Instance.RegisterType<IDressStorage,
DressStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -6,6 +6,7 @@ namespace SewingDressesListImplement.Models
{ {
public class MessageInfo : IMessageInfoModel public class MessageInfo : IMessageInfoModel
{ {
public int Id { get; set; }
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

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

View File

@ -58,14 +58,7 @@ namespace SewingDressesView
{ {
try try
{ {
var list = _clientLogic.ReadList(null); dataGridView.FillAndConfigGrid(_clientLogic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Password"].Visible = false;
}
_logger.LogInformation("Load clients"); _logger.LogInformation("Load clients");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels; using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts; using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.DI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -26,29 +27,25 @@ namespace SewingDressesView
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ComponentForm)); var form = DependencyManager.Instance.Resolve<ComponentForm>();
if (service is ComponentForm form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{
LoadData();
}
} }
} }
private void buttonChange_Click(object sender, EventArgs e) private void buttonChange_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ComponentForm)); var form = DependencyManager.Instance.Resolve<ComponentForm>();
if (service is ComponentForm form) form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }
@ -94,13 +91,7 @@ namespace SewingDressesView
{ {
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("Load components"); _logger.LogInformation("Load components");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -0,0 +1,45 @@
using SewingDressesContracts.Attributes;
namespace SewingDressesView
{
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

@ -4,6 +4,7 @@ using SewingDressesDataModels.Models;
using SewingDressesContracts.SearchModels; using SewingDressesContracts.SearchModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels; using SewingDressesContracts.BindingModels;
using SewingDressesContracts.DI;
namespace SewingDressesView namespace SewingDressesView
{ {
@ -27,26 +28,24 @@ namespace SewingDressesView
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(DressComponentForm)); var form = DependencyManager.Instance.Resolve<DressComponentForm>();
if (service is DressComponentForm form)
if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ComponentModel == null)
{ {
if (form.ComponentModel == null) return;
{
return;
}
_logger.LogInformation("Add new component: {ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count);
if (_dressComponents.ContainsKey(form.Id))
{
_dressComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_dressComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
} }
_logger.LogInformation("Add new component: {ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count);
if (_dressComponents.ContainsKey(form.Id))
{
_dressComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_dressComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
} }
} }
@ -55,10 +54,7 @@ namespace SewingDressesView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = var form = DependencyManager.Instance.Resolve<DressComponentForm>();
Program.ServiceProvider?.GetService(typeof(DressComponentForm));
if (service is DressComponentForm form)
{
int id = int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
@ -73,7 +69,7 @@ namespace SewingDressesView
_dressComponents[form.Id] = (form.ComponentModel, form.Count); _dressComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData(); LoadData();
} }
}
} }
} }

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels; using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts; using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.DI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -26,29 +27,25 @@ namespace SewingDressesView
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(DressForm)); var form = DependencyManager.Instance.Resolve<DressForm>();
if (service is DressForm form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{
LoadData();
}
} }
} }
private void buttonChange_Click(object sender, EventArgs e) private void buttonChange_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(DressForm)); var form = DependencyManager.Instance.Resolve<DressForm>();
if (service is DressForm form) form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }
@ -94,14 +91,7 @@ namespace SewingDressesView
{ {
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["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["DressComponents"].Visible = false;
}
_logger.LogInformation("Load components"); _logger.LogInformation("Load components");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -11,6 +11,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 SewingDressesContracts.DI;
namespace SewingDressesView namespace SewingDressesView
{ {
@ -28,13 +29,7 @@ namespace SewingDressesView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillAndConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
}
_logger.LogInformation("Loading employees");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -44,14 +39,12 @@ namespace SewingDressesView
} }
private void buttonCreate_Click(object sender, EventArgs e) private void buttonCreate_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ImplementForm)); var form = DependencyManager.Instance.Resolve<ImplementForm>();
if (service is ImplementForm form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{
LoadData();
}
} }
} }
private void ImplementsForm_Load(object sender, EventArgs e) private void ImplementsForm_Load(object sender, EventArgs e)
@ -63,15 +56,13 @@ namespace SewingDressesView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ImplementForm)); var form = DependencyManager.Instance.Resolve<ImplementForm>();
if (service is ImplementForm form) form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }

View File

@ -33,14 +33,7 @@ namespace SewingDressesView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillAndConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Loading materials"); _logger.LogInformation("Loading materials");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -44,6 +44,7 @@
компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem();
списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
запускРаботToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem();
создатьБэкапToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -55,12 +56,12 @@
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29; dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(804, 447); dataGridView.Size = new Size(1145, 447);
dataGridView.TabIndex = 0; dataGridView.TabIndex = 0;
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Location = new Point(854, 62); buttonCreate.Location = new Point(1183, 44);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(194, 37); buttonCreate.Size = new Size(194, 37);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
@ -70,7 +71,7 @@
// //
// buttonOrderGive // buttonOrderGive
// //
buttonOrderGive.Location = new Point(854, 142); buttonOrderGive.Location = new Point(1183, 124);
buttonOrderGive.Name = "buttonOrderGive"; buttonOrderGive.Name = "buttonOrderGive";
buttonOrderGive.Size = new Size(194, 37); buttonOrderGive.Size = new Size(194, 37);
buttonOrderGive.TabIndex = 4; buttonOrderGive.TabIndex = 4;
@ -80,7 +81,7 @@
// //
// buttonOrderUpdate // buttonOrderUpdate
// //
buttonOrderUpdate.Location = new Point(854, 219); buttonOrderUpdate.Location = new Point(1183, 201);
buttonOrderUpdate.Name = "buttonOrderUpdate"; buttonOrderUpdate.Name = "buttonOrderUpdate";
buttonOrderUpdate.Size = new Size(194, 37); buttonOrderUpdate.Size = new Size(194, 37);
buttonOrderUpdate.TabIndex = 5; buttonOrderUpdate.TabIndex = 5;
@ -91,10 +92,10 @@
// menuStrip1 // menuStrip1
// //
menuStrip1.ImageScalingSize = new Size(20, 20); menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, создатьБэкапToolStripMenuItem });
menuStrip1.Location = new Point(0, 0); menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1"; menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(1096, 28); menuStrip1.Size = new Size(1389, 28);
menuStrip1.TabIndex = 6; menuStrip1.TabIndex = 6;
menuStrip1.Text = "menuStrip1"; menuStrip1.Text = "menuStrip1";
// //
@ -108,35 +109,35 @@
// компонентыToolStripMenuItem // компонентыToolStripMenuItem
// //
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem"; компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Size = new Size(216, 26);
компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
// //
// платьяToolStripMenuItem // платьяToolStripMenuItem
// //
платьяToolStripMenuItem.Name = "платьяToolStripMenuItem"; платьяToolStripMenuItem.Name = "платьяToolStripMenuItem";
платьяToolStripMenuItem.Size = new Size(224, 26); платьяToolStripMenuItem.Size = new Size(216, 26);
платьяToolStripMenuItem.Text = "Платья"; платьяToolStripMenuItem.Text = "Платья";
платьяToolStripMenuItem.Click += DressesToolStripMenuItem_Click; платьяToolStripMenuItem.Click += DressesToolStripMenuItem_Click;
// //
// clientsToolStripMenuItem // clientsToolStripMenuItem
// //
clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
clientsToolStripMenuItem.Size = new Size(224, 26); clientsToolStripMenuItem.Size = new Size(216, 26);
clientsToolStripMenuItem.Text = "Клиенты"; clientsToolStripMenuItem.Text = "Клиенты";
clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click;
// //
// исполнителиToolStripMenuItem // исполнителиToolStripMenuItem
// //
исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem"; исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem";
исполнителиToolStripMenuItem.Size = new Size(224, 26); исполнителиToolStripMenuItem.Size = new Size(216, 26);
исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Text = "Исполнители";
исполнителиToolStripMenuItem.Click += ImplementToolStripMenuItem_Click; исполнителиToolStripMenuItem.Click += ImplementToolStripMenuItem_Click;
// //
// почтовыеПисьмаToolStripMenuItem // почтовыеПисьмаToolStripMenuItem
// //
почтовыеПисьмаToolStripMenuItem.Name = "почтовыеПисьмаToolStripMenuItem"; почтовыеПисьмаToolStripMenuItem.Name = "почтовыеПисьмаToolStripMenuItem";
почтовыеПисьмаToolStripMenuItem.Size = new Size(224, 26); почтовыеПисьмаToolStripMenuItem.Size = new Size(216, 26);
почтовыеПисьмаToolStripMenuItem.Text = "ПочтовыеПисьма"; почтовыеПисьмаToolStripMenuItem.Text = "ПочтовыеПисьма";
почтовыеПисьмаToolStripMenuItem.Click += emailsToolStripMenuItem_Click; почтовыеПисьмаToolStripMenuItem.Click += emailsToolStripMenuItem_Click;
// //
@ -175,11 +176,18 @@
запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРаботToolStripMenuItem.Text = "Запуск работ";
запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
// //
// создатьБэкапToolStripMenuItem
//
создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem";
создатьБэкапToolStripMenuItem.Size = new Size(122, 24);
создатьБэкапToolStripMenuItem.Text = "Создать бэкап";
создатьБэкапToolStripMenuItem.Click += СоздатьБекапToolStripMenuItem_Click;
//
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1096, 493); ClientSize = new Size(1389, 493);
Controls.Add(buttonOrderUpdate); Controls.Add(buttonOrderUpdate);
Controls.Add(buttonOrderGive); Controls.Add(buttonOrderGive);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
@ -214,5 +222,6 @@
private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem почтовыеПисьмаToolStripMenuItem; private ToolStripMenuItem почтовыеПисьмаToolStripMenuItem;
private ToolStripMenuItem создатьБэкапToolStripMenuItem;
} }
} }

View File

@ -3,6 +3,8 @@ using SewingDressesContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Windows.Forms; using System.Windows.Forms;
using SewingDressesBusinessLogic.BusinessLogic; using SewingDressesBusinessLogic.BusinessLogic;
using SewingDressesDatabaseImplement.Implements;
using SewingDressesContracts.DI;
namespace SewingDressesView namespace SewingDressesView
{ {
@ -12,26 +14,21 @@ namespace SewingDressesView
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess; private readonly IWorkProcess _workProcess;
public MainForm(ILogger<MainForm> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) private readonly IBackUpLogic _backUpLogic;
public MainForm(ILogger<MainForm> 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 LoadData() private void LoadData()
{ {
try try
{ {
var list = _orderLogic.ReadList(null); dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["DressId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementId"].Visible = false;
}
_logger.LogInformation("Load orders"); _logger.LogInformation("Load orders");
} }
catch (Exception ex) catch (Exception ex)
@ -42,30 +39,24 @@ namespace SewingDressesView
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ComponentsForm)); var form = DependencyManager.Instance.Resolve<ComponentsForm>();
if (service is ComponentsForm form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void DressesToolStripMenuItem_Click(object sender, EventArgs e) private void DressesToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(DressesForm)); var form = DependencyManager.Instance.Resolve<DressesForm>();
if (service is DressesForm form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void buttonCreate_Click(object sender, EventArgs e) private void buttonCreate_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(OrderForm)); var form = DependencyManager.Instance.Resolve<OrderForm>();
if (service is OrderForm form) form.ShowDialog();
{ LoadData();
form.ShowDialog();
LoadData();
}
} }
@ -104,19 +95,15 @@ namespace SewingDressesView
} }
private void ComponentProductsToolStripMenuItemReport_Click(object sender, EventArgs e) private void ComponentProductsToolStripMenuItemReport_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ReportDressComponentsForm)); var form = DependencyManager.Instance.Resolve<ReportDressComponentsForm>();
if (service is ReportDressComponentsForm form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void OrdersToolStripMenuItemReport_Click(object sender, EventArgs e) private void OrdersToolStripMenuItemReport_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ReportOrdersForm)); var form = DependencyManager.Instance.Resolve<ReportOrdersForm>();
if (service is ReportOrdersForm form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void DressesToolStripMenuItemReport_Click(object sender, EventArgs e) private void DressesToolStripMenuItemReport_Click(object sender, EventArgs e)
@ -134,35 +121,54 @@ namespace SewingDressesView
private void clientsToolStripMenuItem_Click(object sender, EventArgs e) private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ClientsForm)); var form = DependencyManager.Instance.Resolve<ClientsForm>();
if (service is ClientsForm form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void ImplementToolStripMenuItem_Click(object sender, EventArgs e) private void ImplementToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(ImplementsForm)); var form = DependencyManager.Instance.Resolve<ImplementsForm>();
if (service is ImplementsForm form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{ {
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementLogic)) as IImplementLogic)!, _orderLogic); _workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementLogic>(), _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void emailsToolStripMenuItem_Click(object sender, EventArgs e) private void emailsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(MailForm)); var form = DependencyManager.Instance.Resolve<MailForm>();
if (service is MailForm form) form.ShowDialog();
}
private void СоздатьБекапToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{ {
form.ShowDialog(); 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);
} }
} }
} }
} }

View File

@ -5,27 +5,23 @@ using SewingDressesDatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using System.Drawing;
using SewingDressesBusinessLogic.OfficePackage; using SewingDressesBusinessLogic.OfficePackage;
using SewingDressesBusinessLogic.OfficePackage.Implements; using SewingDressesBusinessLogic.OfficePackage.Implements;
using SewingDressesBusinessLogic.MailWorker; using SewingDressesBusinessLogic.MailWorker;
using SewingDressesContracts.DI;
namespace SewingDressesView namespace SewingDressesView
{ {
internal static class Program internal static class Program
{ {
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
[STAThread] [STAThread]
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
var services = new ServiceCollection(); InitDependencies();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
try try
{ {
var mailSender = _serviceProvider.GetService<AbstractMailWorker>(); var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
mailSender?.MailConfig(new() mailSender?.MailConfig(new()
{ {
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
@ -39,54 +35,51 @@ namespace SewingDressesView
} }
catch (Exception ex) catch (Exception ex)
{ {
var logger = _serviceProvider.GetService<ILogger>(); var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
} }
Application.Run(_serviceProvider.GetRequiredService<MainForm>()); Application.Run(DependencyManager.Instance.Resolve<MainForm>());
} }
private static void ConfigureServices(ServiceCollection services) private static void InitDependencies()
{ {
services.AddLogging(option => DependencyManager.InitDependency();
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDressStorage, DressStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementStorage, ImplementStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>(); DependencyManager.Instance.AddLogging(option =>
services.AddTransient<IOrderLogic, OrderLogic>(); {
services.AddTransient<IDressLogic, DressLogic>(); option.SetMinimumLevel(LogLevel.Information);
services.AddTransient<IReportLogic, ReportLogic>(); option.AddNLog("nlog.config");
services.AddTransient<IClientLogic, ClientLogic>(); });
services.AddTransient<IImplementLogic, ImplementLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>(); DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<IDressLogic, DressLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IImplementLogic, ImplementLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<MainForm>(); DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<ComponentForm>(); DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
services.AddTransient<ComponentsForm>(); DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<OrderForm>();
services.AddTransient<DressForm>(); DependencyManager.Instance.RegisterType<MainForm>();
services.AddTransient<DressComponentForm>(); DependencyManager.Instance.RegisterType<ClientsForm>();
services.AddTransient<ClientsForm>(); DependencyManager.Instance.RegisterType<ComponentForm>();
services.AddTransient<DressesForm>(); DependencyManager.Instance.RegisterType<ComponentsForm>();
services.AddTransient<ReportDressComponentsForm>(); DependencyManager.Instance.RegisterType<DressComponentForm>();
services.AddTransient<ReportOrdersForm>(); DependencyManager.Instance.RegisterType<DressesForm>();
services.AddTransient<ImplementForm>(); DependencyManager.Instance.RegisterType<DressForm>();
services.AddTransient<ImplementsForm>(); DependencyManager.Instance.RegisterType<ImplementForm>();
services.AddTransient<MailForm>(); DependencyManager.Instance.RegisterType<ImplementsForm>();
} DependencyManager.Instance.RegisterType<MailForm>();
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck(); DependencyManager.Instance.RegisterType<OrderForm>();
DependencyManager.Instance.RegisterType<ReportDressComponentsForm>();
DependencyManager.Instance.RegisterType<ReportOrdersForm>();
}
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
} }
} }