Начал 3 лабу
This commit is contained in:
parent
3350a62021
commit
a046a94b03
18
Component/BusinessLogics/BusinessLogics.csproj
Normal file
18
Component/BusinessLogics/BusinessLogics.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
163
Component/BusinessLogics/BusinessLogics/AuthorLogic.cs
Normal file
163
Component/BusinessLogics/BusinessLogics/AuthorLogic.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogics.BusinessLogics
|
||||
{
|
||||
public class AuthorLogic : IAuthorLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IAuthorStorage _authorStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="authorStorage"></param>
|
||||
public AuthorLogic(ILogger<AuthorLogic> logger, IAuthorStorage authorStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_authorStorage = authorStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<AuthorViewModel>? ReadList(AuthorSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Author.Id: {Id}", model?.Id);
|
||||
|
||||
var list = model == null ? _authorStorage.GetFullList() : _authorStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public AuthorViewModel? ReadElement(AuthorSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Author.Id: {Id}", model?.Id);
|
||||
|
||||
var element = _authorStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Author.Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(AuthorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Author.Id: {Id}", model.Id);
|
||||
|
||||
if (_authorStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(AuthorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Author.Id: {Id}", model.Id);
|
||||
|
||||
if (_authorStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(AuthorBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Author.Id: {Id}", model.Id);
|
||||
|
||||
if (_authorStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверить модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
private void CheckModel(AuthorBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Не указано имя автора", nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Author.Id: {Id}", model.Id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
166
Component/BusinessLogics/BusinessLogics/BookLogic.cs
Normal file
166
Component/BusinessLogics/BusinessLogics/BookLogic.cs
Normal file
@ -0,0 +1,166 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace BusinessLogics.BusinessLogics
|
||||
{
|
||||
public class BookLogic : IBookLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IBookStorage _bookStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="bookStorage"></param>
|
||||
public BookLogic(ILogger<BookLogic> logger, IBookStorage bookStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_bookStorage = bookStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<BookViewModel>? ReadList(BookSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Book.Id: {Id}", model?.Id);
|
||||
|
||||
var list = model == null ? _bookStorage.GetFullList() : _bookStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public BookViewModel? ReadElement(BookSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Book.Id: {Id}", model?.Id);
|
||||
|
||||
var element = _bookStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Book.Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(BookBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Book.Id: {Id}", model.Id);
|
||||
|
||||
if (_bookStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(BookBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Book.Id: {Id}", model.Id);
|
||||
|
||||
if (_bookStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(BookBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Book.Id: {Id}", model.Id);
|
||||
|
||||
if (_bookStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(BookBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.TitleFullName))
|
||||
{
|
||||
throw new ArgumentNullException("Не указано название", nameof(model.TitleFullName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Author))
|
||||
{
|
||||
throw new ArgumentNullException("Не указано имя автора", nameof(model.Author));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.PicturePath))
|
||||
{
|
||||
throw new ArgumentNullException("Не указана обложка", nameof(model.PicturePath));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Book.Id: {Id}", model.Id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,9 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34622.214
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentProgramming", "ComponentProgramming\ComponentProgramming.csproj", "{FB9A0617-7B07-4C05-8588-053F7B6BD336}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentProgramming", "ComponentProgramming\ComponentProgramming.csproj", "{FB9A0617-7B07-4C05-8588-053F7B6BD336}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{CE26A22D-CD9A-43C4-9B26-3398D3E4A9A6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Forms", "Forms\Forms.csproj", "{CE26A22D-CD9A-43C4-9B26-3398D3E4A9A6}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{172C0E1D-6496-44A6-A752-E3DF81C0E83F} = {172C0E1D-6496-44A6-A752-E3DF81C0E83F}
|
||||
{715750BA-3D98-41B2-9656-B835CAC9ABE1} = {715750BA-3D98-41B2-9656-B835CAC9ABE1}
|
||||
{73587558-DB1E-4822-A660-FF4A06C820AC} = {73587558-DB1E-4822-A660-FF4A06C820AC}
|
||||
{F8096447-96B0-41DF-9E45-81E4AF283B01} = {F8096447-96B0-41DF-9E45-81E4AF283B01}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogics", "BusinessLogics\BusinessLogics.csproj", "{F8096447-96B0-41DF-9E45-81E4AF283B01}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{715750BA-3D98-41B2-9656-B835CAC9ABE1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{73587558-DB1E-4822-A660-FF4A06C820AC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "DataModels\DataModels.csproj", "{172C0E1D-6496-44A6-A752-E3DF81C0E83F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -21,6 +35,22 @@ Global
|
||||
{CE26A22D-CD9A-43C4-9B26-3398D3E4A9A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CE26A22D-CD9A-43C4-9B26-3398D3E4A9A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CE26A22D-CD9A-43C4-9B26-3398D3E4A9A6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F8096447-96B0-41DF-9E45-81E4AF283B01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F8096447-96B0-41DF-9E45-81E4AF283B01}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F8096447-96B0-41DF-9E45-81E4AF283B01}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F8096447-96B0-41DF-9E45-81E4AF283B01}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{715750BA-3D98-41B2-9656-B835CAC9ABE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{715750BA-3D98-41B2-9656-B835CAC9ABE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{715750BA-3D98-41B2-9656-B835CAC9ABE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{715750BA-3D98-41B2-9656-B835CAC9ABE1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{73587558-DB1E-4822-A660-FF4A06C820AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{73587558-DB1E-4822-A660-FF4A06C820AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{73587558-DB1E-4822-A660-FF4A06C820AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{73587558-DB1E-4822-A660-FF4A06C820AC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{172C0E1D-6496-44A6-A752-E3DF81C0E83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{172C0E1D-6496-44A6-A752-E3DF81C0E83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{172C0E1D-6496-44A6-A752-E3DF81C0E83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{172C0E1D-6496-44A6-A752-E3DF81C0E83F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,10 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
23
Component/Contracts/BindingModels/AuthorBindingModel.cs
Normal file
23
Component/Contracts/BindingModels/AuthorBindingModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DataModels.Models;
|
||||
|
||||
namespace Contracts.BindingModels
|
||||
{
|
||||
public class AuthorBindingModel : IAuthorModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Имя автора
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
}
|
38
Component/Contracts/BindingModels/BookBindingModel.cs
Normal file
38
Component/Contracts/BindingModels/BookBindingModel.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BindingModels
|
||||
{
|
||||
public class BookBindingModel : IBookModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string TitleFullName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Обложка
|
||||
/// </summary>
|
||||
public string PicturePath { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Автор
|
||||
/// </summary>
|
||||
public string Author { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Дата издания
|
||||
/// </summary>
|
||||
public DateTime BookDate { get; set; }
|
||||
}
|
||||
|
||||
}
|
50
Component/Contracts/BusinessLogicsContracts/IAuthorLogic.cs
Normal file
50
Component/Contracts/BusinessLogicsContracts/IAuthorLogic.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IAuthorLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<AuthorViewModel>? ReadList(AuthorSearchModel? model);
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
AuthorViewModel? ReadElement(AuthorSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Create(AuthorBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Update(AuthorBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Delete(AuthorBindingModel model);
|
||||
}
|
||||
|
||||
}
|
52
Component/Contracts/BusinessLogicsContracts/IBookLogic.cs
Normal file
52
Component/Contracts/BusinessLogicsContracts/IBookLogic.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BusinessLogicsContracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для описания работы бизнес-логики для сущности "Счет"
|
||||
/// </summary>
|
||||
public interface IBookLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<BookViewModel>? ReadList(BookSearchModel? model);
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
BookViewModel? ReadElement(BookSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Create(BookBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Update(BookBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Delete(BookBindingModel model);
|
||||
}
|
||||
}
|
13
Component/Contracts/Contracts.csproj
Normal file
13
Component/Contracts/Contracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
16
Component/Contracts/SearchModels/AuthorSearchModel.cs
Normal file
16
Component/Contracts/SearchModels/AuthorSearchModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class AuthorSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
}
|
19
Component/Contracts/SearchModels/BookSearchModel.cs
Normal file
19
Component/Contracts/SearchModels/BookSearchModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class BookSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? TitleFullName { get; set; }
|
||||
|
||||
public string Author { get; set; }
|
||||
|
||||
public DateTime BookDate { get; set; }
|
||||
}
|
||||
}
|
26
Component/Contracts/StorageContracts/IAuthorStorage.cs
Normal file
26
Component/Contracts/StorageContracts/IAuthorStorage.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.StorageContracts
|
||||
{
|
||||
public interface IAuthorStorage
|
||||
{
|
||||
List<AuthorViewModel> GetFullList();
|
||||
|
||||
List<AuthorViewModel> GetFilteredList(AuthorSearchModel model);
|
||||
|
||||
AuthorViewModel? GetElement(AuthorSearchModel model);
|
||||
|
||||
AuthorViewModel? Insert(AuthorBindingModel model);
|
||||
|
||||
AuthorViewModel? Update(AuthorBindingModel model);
|
||||
|
||||
AuthorViewModel? Delete(AuthorBindingModel model);
|
||||
}
|
||||
}
|
27
Component/Contracts/StorageContracts/IBookStorage.cs
Normal file
27
Component/Contracts/StorageContracts/IBookStorage.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.StorageContracts
|
||||
{
|
||||
public interface IBookStorage
|
||||
{
|
||||
List<BookViewModel> GetFullList();
|
||||
|
||||
List<BookViewModel> GetFilteredList(BookSearchModel model);
|
||||
|
||||
BookViewModel? GetElement(BookSearchModel model);
|
||||
|
||||
BookViewModel? Insert(BookBindingModel model);
|
||||
|
||||
BookViewModel? Update(BookBindingModel model);
|
||||
|
||||
BookViewModel? Delete(BookBindingModel model);
|
||||
}
|
||||
|
||||
}
|
17
Component/Contracts/ViewModels/AuthorViewModel.cs
Normal file
17
Component/Contracts/ViewModels/AuthorViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class AuthorViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя автора")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
}
|
26
Component/Contracts/ViewModels/BookViewModel.cs
Normal file
26
Component/Contracts/ViewModels/BookViewModel.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class BookViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string TitleFullName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Автор")]
|
||||
public string Author { get; set; } = string.Empty;
|
||||
|
||||
public string PicturePath { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата издания")]
|
||||
public DateTime BookDate { get; set; }
|
||||
|
||||
}
|
||||
}
|
9
Component/DataModels/DataModels.csproj
Normal file
9
Component/DataModels/DataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
20
Component/DataModels/IId.cs
Normal file
20
Component/DataModels/IId.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для идентификатора
|
||||
/// </summary>
|
||||
public interface IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
}
|
||||
|
||||
}
|
21
Component/DataModels/Models/IAuthorModel.cs
Normal file
21
Component/DataModels/Models/IAuthorModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для сущности "Автор"
|
||||
/// </summary>
|
||||
public interface IAuthorModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Имя автора
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
}
|
||||
|
||||
}
|
36
Component/DataModels/Models/IBookModel.cs
Normal file
36
Component/DataModels/Models/IBookModel.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для сущности "Книга"
|
||||
/// </summary>
|
||||
public interface IBookModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
string TitleFullName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Обложка
|
||||
/// </summary>
|
||||
string PicturePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Автор
|
||||
/// </summary>
|
||||
string Author { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата издания
|
||||
/// </summary>
|
||||
DateTime BookDate { get; }
|
||||
}
|
||||
|
||||
}
|
51
Component/DatabaseImplement/Database.cs
Normal file
51
Component/DatabaseImplement/Database.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using DatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseImplement
|
||||
{
|
||||
public class Database : DbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры подключения к базе данных
|
||||
/// </summary>
|
||||
///
|
||||
//private string _dbConnectionString = "Host=localhost;Port=5432;Database=COPLabWorks;Username=postgres;Password=1111";
|
||||
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
//{
|
||||
//if (optionsBuilder.IsConfigured == false)
|
||||
//{
|
||||
// optionsBuilder.UseNpgsql(_dbConnectionString);
|
||||
// }
|
||||
// base.OnConfiguring(optionsBuilder);
|
||||
//}
|
||||
/// <summary>
|
||||
/// Подключение к базе данных
|
||||
/// </summary>
|
||||
/// <param name="optionsBuilder"></param>
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-ETBGTEE;Initial Catalog=AccountingLibrary; Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True ");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Таблица "Книги"
|
||||
/// </summary>
|
||||
public virtual DbSet<Book> Books { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Таблица "Авторы"
|
||||
/// </summary>
|
||||
public virtual DbSet<Author> Authors { get; set; }
|
||||
}
|
||||
|
||||
}
|
23
Component/DatabaseImplement/DatabaseImplement.csproj
Normal file
23
Component/DatabaseImplement/DatabaseImplement.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
126
Component/DatabaseImplement/Implements/AuthorStorage.cs
Normal file
126
Component/DatabaseImplement/Implements/AuthorStorage.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using DatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseImplement.Implements
|
||||
{
|
||||
public class AuthorStorage : IAuthorStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список элементов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AuthorViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.Authors
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить фильтрованный список элементов
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<AuthorViewModel> GetFilteredList(AuthorSearchModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
// Фильтрация по названию типа
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return context.Authors
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public AuthorViewModel? GetElement(AuthorSearchModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Authors
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public AuthorViewModel? Insert(AuthorBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var newAuthor = Author.Create(model);
|
||||
if (newAuthor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Authors.Add(newAuthor);
|
||||
context.SaveChanges();
|
||||
return newAuthor.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public AuthorViewModel? Update(AuthorBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var orderType = context.Authors
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id));
|
||||
if (orderType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
orderType.Update(model);
|
||||
context.SaveChanges();
|
||||
return orderType.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public AuthorViewModel? Delete(AuthorBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var orderType = context.Authors
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id));
|
||||
if (orderType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Authors.Remove(orderType);
|
||||
context.SaveChanges();
|
||||
return orderType.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
135
Component/DatabaseImplement/Implements/BookStorage.cs
Normal file
135
Component/DatabaseImplement/Implements/BookStorage.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using DatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseImplement.Implements
|
||||
{
|
||||
public class BookStorage : IBookStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список элементов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<BookViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.Books
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить фильтрованный список элементов
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<BookViewModel> GetFilteredList(BookSearchModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
// Фильтрация по названию
|
||||
if (!string.IsNullOrEmpty(model.TitleFullName))
|
||||
{
|
||||
return context.Books
|
||||
.Where(x => x.TitleFullName.Contains(model.TitleFullName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Фильтрация по автору
|
||||
if (!string.IsNullOrEmpty(model.Author))
|
||||
{
|
||||
return context.Books
|
||||
.Where(x => x.Author.Contains(model.Author))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public BookViewModel? GetElement(BookSearchModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Books
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public BookViewModel? Insert(BookBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var newBook = Book.Create(model);
|
||||
if (newBook == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Books.Add(newBook);
|
||||
context.SaveChanges();
|
||||
return newBook.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public BookViewModel? Update(BookBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var Book = context.Books
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id));
|
||||
if (Book == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Book.Update(model);
|
||||
context.SaveChanges();
|
||||
return Book.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public BookViewModel? Delete(BookBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var Book = context.Books
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id));
|
||||
if (Book == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Books.Remove(Book);
|
||||
context.SaveChanges();
|
||||
return Book.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
75
Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.Designer.cs
generated
Normal file
75
Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
[Migration("20241029174234_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.Author", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.Book", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Author")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("BookDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("PicturePath")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("TitleFullName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Authors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Authors", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Books",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
TitleFullName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
PicturePath = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Author = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
BookDate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Books", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Authors");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Books");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
partial class DatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.Author", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.Book", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Author")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("BookDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("PicturePath")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("TitleFullName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
67
Component/DatabaseImplement/Models/Author.cs
Normal file
67
Component/DatabaseImplement/Models/Author.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseImplement.Models
|
||||
{
|
||||
public class Author
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public static Author? Create(AuthorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Author
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
|
||||
public static Author? Create(AuthorViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Author
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(AuthorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Name = model.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить модель отображения
|
||||
/// </summary>
|
||||
public AuthorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
76
Component/DatabaseImplement/Models/Book.cs
Normal file
76
Component/DatabaseImplement/Models/Book.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.ViewModels;
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseImplement.Models
|
||||
{
|
||||
public class Book : IBookModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string TitleFullName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string PicturePath { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Author { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime BookDate { get; private set; }
|
||||
|
||||
public static Book? Create(BookBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Book
|
||||
{
|
||||
Id = model.Id,
|
||||
TitleFullName = model.TitleFullName,
|
||||
PicturePath = model.PicturePath,
|
||||
Author = model.Author,
|
||||
BookDate = model.BookDate,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
public void Update(BookBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TitleFullName = model.TitleFullName;
|
||||
PicturePath = model.PicturePath;
|
||||
Author = model.Author;
|
||||
BookDate = model.BookDate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить модель отображения
|
||||
/// </summary>
|
||||
public BookViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
TitleFullName = TitleFullName,
|
||||
PicturePath = PicturePath,
|
||||
Author = Author,
|
||||
BookDate = BookDate,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -75,10 +75,10 @@ namespace TestForm
|
||||
("Weight", "Weight")
|
||||
};
|
||||
|
||||
if (pdfTable1.createTable(new DataForTable<CharacterInfo>(path, "Table", heights, merges, headers, charactersinfo)))
|
||||
{
|
||||
MessageBox.Show("Success");
|
||||
}
|
||||
//if (pdfTable1.createTable(new DataForTable<CharacterInfo>(path, "Table", heights, merges, headers, charactersinfo)))
|
||||
//{
|
||||
// MessageBox.Show("Success");
|
||||
//}
|
||||
}
|
||||
|
||||
private void PdfChart_Click(object sender, EventArgs e)
|
||||
|
39
Component/Forms/FormAuthor.Designer.cs
generated
Normal file
39
Component/Forms/FormAuthor.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormAuthor
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "FormAuthor";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
20
Component/Forms/FormAuthor.cs
Normal file
20
Component/Forms/FormAuthor.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormAuthor : Form
|
||||
{
|
||||
public FormAuthor()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
120
Component/Forms/FormAuthor.resx
Normal file
120
Component/Forms/FormAuthor.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
58
Component/Forms/FormMain.Designer.cs
generated
Normal file
58
Component/Forms/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
controlDataGridView1 = new COP_V6.ControlDataGridView();
|
||||
SuspendLayout();
|
||||
//
|
||||
// controlDataGridView1
|
||||
//
|
||||
controlDataGridView1.Dock = DockStyle.Fill;
|
||||
controlDataGridView1.Location = new Point(0, 0);
|
||||
controlDataGridView1.Name = "controlDataGridView1";
|
||||
controlDataGridView1.Size = new Size(800, 450);
|
||||
controlDataGridView1.TabIndex = 0;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(controlDataGridView1);
|
||||
Name = "FormMain";
|
||||
Text = "FormMain";
|
||||
Load += FormMain_Load;
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private COP_V6.ControlDataGridView controlDataGridView1;
|
||||
}
|
||||
}
|
68
Component/Forms/FormMain.cs
Normal file
68
Component/Forms/FormMain.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using BusinessLogics.BusinessLogics;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Contracts.ViewModels;
|
||||
using COP_V6;
|
||||
using DatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly IBookLogic _bookLogic;
|
||||
private readonly IAuthorLogic _authorLogic;
|
||||
public FormMain(IBookLogic bookLogic, IAuthorLogic authorLogic)
|
||||
{
|
||||
_bookLogic = bookLogic;
|
||||
_authorLogic = authorLogic;
|
||||
InitializeComponent();
|
||||
|
||||
List<Parameters> parameters = new List<Parameters>()
|
||||
{
|
||||
new Parameters("Идентификатор", 100, true, "Id"),
|
||||
new Parameters("Название", 100, true, "Name"),
|
||||
new Parameters("Автор", 100, true, "Surname"),
|
||||
new Parameters("Дата издания", 150, true, "Age")
|
||||
};
|
||||
controlDataGridView1.CreateColumns(parameters);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadMain();
|
||||
|
||||
}
|
||||
private void LoadMain()
|
||||
{
|
||||
controlDataGridView1.ClearCol();
|
||||
try
|
||||
{
|
||||
var books = _bookLogic.ReadList(null);
|
||||
if (books == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var book in books)
|
||||
{
|
||||
|
||||
controlDataGridView1.SetObject<BookViewModel>(book);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Component/Forms/FormMain.resx
Normal file
120
Component/Forms/FormMain.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -2,14 +2,29 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComponentProgramming" Version="1.0.0" />
|
||||
<PackageReference Include="Components" Version="1.0.0" />
|
||||
<PackageReference Include="COP_V6" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.14" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BusinessLogics\BusinessLogics.csproj" />
|
||||
<ProjectReference Include="..\ComponentProgramming\ComponentProgramming.csproj" />
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,9 +1,23 @@
|
||||
using TestForm;
|
||||
using BusinessLogics.BusinessLogics;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Contracts.StorageContracts;
|
||||
using DatabaseImplement.Implements;
|
||||
using Forms;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
namespace Forms
|
||||
namespace WinForms
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// IoC-êîíòåéíåð
|
||||
/// </summary>
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -13,7 +27,38 @@ namespace Forms
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Êîíôèãóðàöèÿ ñåðâèñîâ
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
// Ëîããåð
|
||||
services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
|
||||
// IoC-êîíòåéíåð, õðàíèëèùà
|
||||
services.AddTransient<IBookStorage, BookStorage>();
|
||||
services.AddTransient<IAuthorStorage, AuthorStorage>();
|
||||
|
||||
// IoC-êîíòåéíåð, áèçíåñ-ëîãèêà
|
||||
services.AddTransient<IBookLogic, BookLogic>();
|
||||
services.AddTransient<IAuthorLogic, AuthorLogic>();
|
||||
|
||||
// IoC-êîíòåéíåð, ôîðìû îòîáðàæåíèÿ
|
||||
services.AddTransient<FormMain>();
|
||||
//services.AddTransient<FormBook>();
|
||||
//services.AddTransient<FormAuthor>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user