From a046a94b0311ba6fe5268a0a2981b9ab1ad5d475 Mon Sep 17 00:00:00 2001 From: Stepan Date: Wed, 30 Oct 2024 01:08:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=203=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/BusinessLogics.csproj | 18 ++ .../BusinessLogics/AuthorLogic.cs | 163 +++++++++++++++++ .../BusinessLogics/BookLogic.cs | 166 ++++++++++++++++++ Component/Component.sln | 34 +++- .../ComponentProgramming.csproj | 3 +- .../BindingModels/AuthorBindingModel.cs | 23 +++ .../BindingModels/BookBindingModel.cs | 38 ++++ .../BusinessLogicsContracts/IAuthorLogic.cs | 50 ++++++ .../BusinessLogicsContracts/IBookLogic.cs | 52 ++++++ Component/Contracts/Contracts.csproj | 13 ++ .../SearchModels/AuthorSearchModel.cs | 16 ++ .../Contracts/SearchModels/BookSearchModel.cs | 19 ++ .../StorageContracts/IAuthorStorage.cs | 26 +++ .../StorageContracts/IBookStorage.cs | 27 +++ .../Contracts/ViewModels/AuthorViewModel.cs | 17 ++ .../Contracts/ViewModels/BookViewModel.cs | 26 +++ Component/DataModels/DataModels.csproj | 9 + Component/DataModels/IId.cs | 20 +++ Component/DataModels/Models/IAuthorModel.cs | 21 +++ Component/DataModels/Models/IBookModel.cs | 36 ++++ Component/DatabaseImplement/Database.cs | 51 ++++++ .../DatabaseImplement.csproj | 23 +++ .../Implements/AuthorStorage.cs | 126 +++++++++++++ .../Implements/BookStorage.cs | 135 ++++++++++++++ .../20241029174234_InitialCreate.Designer.cs | 75 ++++++++ .../20241029174234_InitialCreate.cs | 54 ++++++ .../Migrations/DatabaseModelSnapshot.cs | 72 ++++++++ Component/DatabaseImplement/Models/Author.cs | 67 +++++++ Component/DatabaseImplement/Models/Book.cs | 76 ++++++++ Component/Forms/Form1.cs | 8 +- Component/Forms/FormAuthor.Designer.cs | 39 ++++ Component/Forms/FormAuthor.cs | 20 +++ Component/Forms/FormAuthor.resx | 120 +++++++++++++ Component/Forms/FormMain.Designer.cs | 58 ++++++ Component/Forms/FormMain.cs | 68 +++++++ Component/Forms/FormMain.resx | 120 +++++++++++++ Component/Forms/Forms.csproj | 17 +- Component/Forms/Program.cs | 51 +++++- 38 files changed, 1946 insertions(+), 11 deletions(-) create mode 100644 Component/BusinessLogics/BusinessLogics.csproj create mode 100644 Component/BusinessLogics/BusinessLogics/AuthorLogic.cs create mode 100644 Component/BusinessLogics/BusinessLogics/BookLogic.cs create mode 100644 Component/Contracts/BindingModels/AuthorBindingModel.cs create mode 100644 Component/Contracts/BindingModels/BookBindingModel.cs create mode 100644 Component/Contracts/BusinessLogicsContracts/IAuthorLogic.cs create mode 100644 Component/Contracts/BusinessLogicsContracts/IBookLogic.cs create mode 100644 Component/Contracts/Contracts.csproj create mode 100644 Component/Contracts/SearchModels/AuthorSearchModel.cs create mode 100644 Component/Contracts/SearchModels/BookSearchModel.cs create mode 100644 Component/Contracts/StorageContracts/IAuthorStorage.cs create mode 100644 Component/Contracts/StorageContracts/IBookStorage.cs create mode 100644 Component/Contracts/ViewModels/AuthorViewModel.cs create mode 100644 Component/Contracts/ViewModels/BookViewModel.cs create mode 100644 Component/DataModels/DataModels.csproj create mode 100644 Component/DataModels/IId.cs create mode 100644 Component/DataModels/Models/IAuthorModel.cs create mode 100644 Component/DataModels/Models/IBookModel.cs create mode 100644 Component/DatabaseImplement/Database.cs create mode 100644 Component/DatabaseImplement/DatabaseImplement.csproj create mode 100644 Component/DatabaseImplement/Implements/AuthorStorage.cs create mode 100644 Component/DatabaseImplement/Implements/BookStorage.cs create mode 100644 Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.Designer.cs create mode 100644 Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.cs create mode 100644 Component/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs create mode 100644 Component/DatabaseImplement/Models/Author.cs create mode 100644 Component/DatabaseImplement/Models/Book.cs create mode 100644 Component/Forms/FormAuthor.Designer.cs create mode 100644 Component/Forms/FormAuthor.cs create mode 100644 Component/Forms/FormAuthor.resx create mode 100644 Component/Forms/FormMain.Designer.cs create mode 100644 Component/Forms/FormMain.cs create mode 100644 Component/Forms/FormMain.resx diff --git a/Component/BusinessLogics/BusinessLogics.csproj b/Component/BusinessLogics/BusinessLogics.csproj new file mode 100644 index 0000000..3654258 --- /dev/null +++ b/Component/BusinessLogics/BusinessLogics.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + diff --git a/Component/BusinessLogics/BusinessLogics/AuthorLogic.cs b/Component/BusinessLogics/BusinessLogics/AuthorLogic.cs new file mode 100644 index 0000000..b0ea2f3 --- /dev/null +++ b/Component/BusinessLogics/BusinessLogics/AuthorLogic.cs @@ -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 + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Хранилище + /// + private readonly IAuthorStorage _authorStorage; + + /// + /// Конструктор + /// + /// + /// + public AuthorLogic(ILogger logger, IAuthorStorage authorStorage) + { + _logger = logger; + _authorStorage = authorStorage; + } + + /// + /// Получить список записией + /// + /// + /// + public List? 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; + } + + /// + /// Получить отдельную запись + /// + /// + /// + /// + 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; + } + + /// + /// Создать запись + /// + /// + /// + 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; + } + + /// + /// Изменить запись + /// + /// + /// + 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; + } + + /// + /// Удалить запись + /// + /// + /// + 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; + } + + /// + /// Проверить модель + /// + /// + /// + /// + 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); + } + } + +} diff --git a/Component/BusinessLogics/BusinessLogics/BookLogic.cs b/Component/BusinessLogics/BusinessLogics/BookLogic.cs new file mode 100644 index 0000000..387543c --- /dev/null +++ b/Component/BusinessLogics/BusinessLogics/BookLogic.cs @@ -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 + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Хранилище + /// + private readonly IBookStorage _bookStorage; + + /// + /// Конструктор + /// + /// + /// + public BookLogic(ILogger logger, IBookStorage bookStorage) + { + _logger = logger; + _bookStorage = bookStorage; + } + + /// + /// Получить список записией + /// + /// + /// + public List? 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; + } + + /// + /// Получить отдельную запись + /// + /// + /// + /// + 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; + } + + /// + /// Создать запись + /// + /// + /// + 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; + } + + /// + /// Изменить запись + /// + /// + /// + 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; + } + + /// + /// Удалить запись + /// + /// + /// + 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); + } + } + +} diff --git a/Component/Component.sln b/Component/Component.sln index 1c24d74..eb685c2 100644 --- a/Component/Component.sln +++ b/Component/Component.sln @@ -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 diff --git a/Component/ComponentProgramming/ComponentProgramming.csproj b/Component/ComponentProgramming/ComponentProgramming.csproj index 6e54887..6065014 100644 --- a/Component/ComponentProgramming/ComponentProgramming.csproj +++ b/Component/ComponentProgramming/ComponentProgramming.csproj @@ -1,10 +1,11 @@  - net6.0-windows + net8.0-windows enable true enable + True diff --git a/Component/Contracts/BindingModels/AuthorBindingModel.cs b/Component/Contracts/BindingModels/AuthorBindingModel.cs new file mode 100644 index 0000000..086adec --- /dev/null +++ b/Component/Contracts/BindingModels/AuthorBindingModel.cs @@ -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 + { + /// + /// Идентификатор + /// + public int Id { get; set; } + + /// + /// Имя автора + /// + public string Name { get; set; } = string.Empty; + + } +} diff --git a/Component/Contracts/BindingModels/BookBindingModel.cs b/Component/Contracts/BindingModels/BookBindingModel.cs new file mode 100644 index 0000000..aaf9fcd --- /dev/null +++ b/Component/Contracts/BindingModels/BookBindingModel.cs @@ -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 + { + /// + /// Идентификатор + /// + public int Id { get; set; } + + /// + /// Название + /// + public string TitleFullName { get; set; } = string.Empty; + + /// + /// Обложка + /// + public string PicturePath { get; set; } = string.Empty; + + /// + /// Автор + /// + public string Author { get; set; } = string.Empty; + + /// + /// Дата издания + /// + public DateTime BookDate { get; set; } + } + +} diff --git a/Component/Contracts/BusinessLogicsContracts/IAuthorLogic.cs b/Component/Contracts/BusinessLogicsContracts/IAuthorLogic.cs new file mode 100644 index 0000000..5b85293 --- /dev/null +++ b/Component/Contracts/BusinessLogicsContracts/IAuthorLogic.cs @@ -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 + { + /// + /// Получить список записией + /// + /// + /// + List? ReadList(AuthorSearchModel? model); + + /// + /// Получить отдельную запись + /// + /// + /// + AuthorViewModel? ReadElement(AuthorSearchModel model); + + /// + /// Создать запись + /// + /// + /// + bool Create(AuthorBindingModel model); + + /// + /// Изменить запись + /// + /// + /// + bool Update(AuthorBindingModel model); + + /// + /// Удалить запись + /// + /// + /// + bool Delete(AuthorBindingModel model); + } + +} diff --git a/Component/Contracts/BusinessLogicsContracts/IBookLogic.cs b/Component/Contracts/BusinessLogicsContracts/IBookLogic.cs new file mode 100644 index 0000000..428a5d5 --- /dev/null +++ b/Component/Contracts/BusinessLogicsContracts/IBookLogic.cs @@ -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 +{ + /// + /// Интерфейс для описания работы бизнес-логики для сущности "Счет" + /// + public interface IBookLogic + { + /// + /// Получить список записией + /// + /// + /// + List? ReadList(BookSearchModel? model); + + /// + /// Получить отдельную запись + /// + /// + /// + BookViewModel? ReadElement(BookSearchModel model); + + /// + /// Создать запись + /// + /// + /// + bool Create(BookBindingModel model); + + /// + /// Изменить запись + /// + /// + /// + bool Update(BookBindingModel model); + + /// + /// Удалить запись + /// + /// + /// + bool Delete(BookBindingModel model); + } +} diff --git a/Component/Contracts/Contracts.csproj b/Component/Contracts/Contracts.csproj new file mode 100644 index 0000000..f1b5623 --- /dev/null +++ b/Component/Contracts/Contracts.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Component/Contracts/SearchModels/AuthorSearchModel.cs b/Component/Contracts/SearchModels/AuthorSearchModel.cs new file mode 100644 index 0000000..ea7e867 --- /dev/null +++ b/Component/Contracts/SearchModels/AuthorSearchModel.cs @@ -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; } + } + +} diff --git a/Component/Contracts/SearchModels/BookSearchModel.cs b/Component/Contracts/SearchModels/BookSearchModel.cs new file mode 100644 index 0000000..589ff67 --- /dev/null +++ b/Component/Contracts/SearchModels/BookSearchModel.cs @@ -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; } + } +} diff --git a/Component/Contracts/StorageContracts/IAuthorStorage.cs b/Component/Contracts/StorageContracts/IAuthorStorage.cs new file mode 100644 index 0000000..a8e168e --- /dev/null +++ b/Component/Contracts/StorageContracts/IAuthorStorage.cs @@ -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 GetFullList(); + + List GetFilteredList(AuthorSearchModel model); + + AuthorViewModel? GetElement(AuthorSearchModel model); + + AuthorViewModel? Insert(AuthorBindingModel model); + + AuthorViewModel? Update(AuthorBindingModel model); + + AuthorViewModel? Delete(AuthorBindingModel model); + } +} diff --git a/Component/Contracts/StorageContracts/IBookStorage.cs b/Component/Contracts/StorageContracts/IBookStorage.cs new file mode 100644 index 0000000..71b3020 --- /dev/null +++ b/Component/Contracts/StorageContracts/IBookStorage.cs @@ -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 GetFullList(); + + List GetFilteredList(BookSearchModel model); + + BookViewModel? GetElement(BookSearchModel model); + + BookViewModel? Insert(BookBindingModel model); + + BookViewModel? Update(BookBindingModel model); + + BookViewModel? Delete(BookBindingModel model); + } + +} diff --git a/Component/Contracts/ViewModels/AuthorViewModel.cs b/Component/Contracts/ViewModels/AuthorViewModel.cs new file mode 100644 index 0000000..a925ddc --- /dev/null +++ b/Component/Contracts/ViewModels/AuthorViewModel.cs @@ -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; + } + +} diff --git a/Component/Contracts/ViewModels/BookViewModel.cs b/Component/Contracts/ViewModels/BookViewModel.cs new file mode 100644 index 0000000..9aa6fd2 --- /dev/null +++ b/Component/Contracts/ViewModels/BookViewModel.cs @@ -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; } + + } +} diff --git a/Component/DataModels/DataModels.csproj b/Component/DataModels/DataModels.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/Component/DataModels/DataModels.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/Component/DataModels/IId.cs b/Component/DataModels/IId.cs new file mode 100644 index 0000000..9747669 --- /dev/null +++ b/Component/DataModels/IId.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataModels +{ + /// + /// Интерфейс для идентификатора + /// + public interface IId + { + /// + /// Идентификатор + /// + int Id { get; } + } + +} diff --git a/Component/DataModels/Models/IAuthorModel.cs b/Component/DataModels/Models/IAuthorModel.cs new file mode 100644 index 0000000..de925ea --- /dev/null +++ b/Component/DataModels/Models/IAuthorModel.cs @@ -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 +{ + /// + /// Интерфейс для сущности "Автор" + /// + public interface IAuthorModel : IId + { + /// + /// Имя автора + /// + string Name { get; } + } + +} diff --git a/Component/DataModels/Models/IBookModel.cs b/Component/DataModels/Models/IBookModel.cs new file mode 100644 index 0000000..04e7112 --- /dev/null +++ b/Component/DataModels/Models/IBookModel.cs @@ -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 +{ + /// + /// Интерфейс для сущности "Книга" + /// + public interface IBookModel : IId + { + /// + /// Название + /// + string TitleFullName { get; } + + /// + /// Обложка + /// + string PicturePath { get; } + + /// + /// Автор + /// + string Author { get; } + + /// + /// Дата издания + /// + DateTime BookDate { get; } + } + +} diff --git a/Component/DatabaseImplement/Database.cs b/Component/DatabaseImplement/Database.cs new file mode 100644 index 0000000..0842016 --- /dev/null +++ b/Component/DatabaseImplement/Database.cs @@ -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 + { + /// + /// Параметры подключения к базе данных + /// + /// + //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); + //} + /// + /// Подключение к базе данных + /// + /// + + 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); + } + + /// + /// Таблица "Книги" + /// + public virtual DbSet Books { get; set; } + + /// + /// Таблица "Авторы" + /// + public virtual DbSet Authors { get; set; } + } + +} diff --git a/Component/DatabaseImplement/DatabaseImplement.csproj b/Component/DatabaseImplement/DatabaseImplement.csproj new file mode 100644 index 0000000..e07154b --- /dev/null +++ b/Component/DatabaseImplement/DatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Component/DatabaseImplement/Implements/AuthorStorage.cs b/Component/DatabaseImplement/Implements/AuthorStorage.cs new file mode 100644 index 0000000..fe982ea --- /dev/null +++ b/Component/DatabaseImplement/Implements/AuthorStorage.cs @@ -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 + { + /// + /// Получить полный список элементов + /// + /// + public List GetFullList() + { + using var context = new Database(); + return context.Authors + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получить фильтрованный список элементов + /// + /// + /// + public List 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(); + } + + /// + /// Получить элемент + /// + /// + /// + 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; + } + + /// + /// Добавить элемент + /// + /// + /// + 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; + } + + /// + /// Редактировать элемент + /// + /// + /// + 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; + } + + /// + /// Удалить элемент + /// + /// + /// + 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; + } + } + +} diff --git a/Component/DatabaseImplement/Implements/BookStorage.cs b/Component/DatabaseImplement/Implements/BookStorage.cs new file mode 100644 index 0000000..efd41e2 --- /dev/null +++ b/Component/DatabaseImplement/Implements/BookStorage.cs @@ -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 + { + /// + /// Получить полный список элементов + /// + /// + public List GetFullList() + { + using var context = new Database(); + return context.Books + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получить фильтрованный список элементов + /// + /// + /// + public List 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(); + } + + /// + /// Получить элемент + /// + /// + /// + 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; + } + + /// + /// Добавить элемент + /// + /// + /// + 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; + } + + /// + /// Редактировать элемент + /// + /// + /// + 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; + } + + /// + /// Удалить элемент + /// + /// + /// + 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; + } + } + +} diff --git a/Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.Designer.cs b/Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.Designer.cs new file mode 100644 index 0000000..6f8127c --- /dev/null +++ b/Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.Designer.cs @@ -0,0 +1,75 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("BookDate") + .HasColumnType("datetime2"); + + b.Property("PicturePath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TitleFullName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.cs b/Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.cs new file mode 100644 index 0000000..ecb196e --- /dev/null +++ b/Component/DatabaseImplement/Migrations/20241029174234_InitialCreate.cs @@ -0,0 +1,54 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Authors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Authors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TitleFullName = table.Column(type: "nvarchar(max)", nullable: false), + PicturePath = table.Column(type: "nvarchar(max)", nullable: false), + Author = table.Column(type: "nvarchar(max)", nullable: false), + BookDate = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Authors"); + + migrationBuilder.DropTable( + name: "Books"); + } + } +} diff --git a/Component/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs b/Component/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs new file mode 100644 index 0000000..6980864 --- /dev/null +++ b/Component/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -0,0 +1,72 @@ +// +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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("BookDate") + .HasColumnType("datetime2"); + + b.Property("PicturePath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TitleFullName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Component/DatabaseImplement/Models/Author.cs b/Component/DatabaseImplement/Models/Author.cs new file mode 100644 index 0000000..75acec2 --- /dev/null +++ b/Component/DatabaseImplement/Models/Author.cs @@ -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; + } + + /// + /// Получить модель отображения + /// + public AuthorViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + }; + } + +} diff --git a/Component/DatabaseImplement/Models/Book.cs b/Component/DatabaseImplement/Models/Book.cs new file mode 100644 index 0000000..058b0df --- /dev/null +++ b/Component/DatabaseImplement/Models/Book.cs @@ -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, + }; + } + + /// + /// Изменить модель + /// + /// + public void Update(BookBindingModel model) + { + if (model == null) + { + return; + } + + TitleFullName = model.TitleFullName; + PicturePath = model.PicturePath; + Author = model.Author; + BookDate = model.BookDate; + } + + /// + /// Получить модель отображения + /// + public BookViewModel GetViewModel => new() + { + Id = Id, + TitleFullName = TitleFullName, + PicturePath = PicturePath, + Author = Author, + BookDate = BookDate, + }; + + } +} diff --git a/Component/Forms/Form1.cs b/Component/Forms/Form1.cs index 6c57406..5b969ea 100644 --- a/Component/Forms/Form1.cs +++ b/Component/Forms/Form1.cs @@ -75,10 +75,10 @@ namespace TestForm ("Weight", "Weight") }; - if (pdfTable1.createTable(new DataForTable(path, "Table", heights, merges, headers, charactersinfo))) - { - MessageBox.Show("Success"); - } + //if (pdfTable1.createTable(new DataForTable(path, "Table", heights, merges, headers, charactersinfo))) + //{ + // MessageBox.Show("Success"); + //} } private void PdfChart_Click(object sender, EventArgs e) diff --git a/Component/Forms/FormAuthor.Designer.cs b/Component/Forms/FormAuthor.Designer.cs new file mode 100644 index 0000000..17a20f1 --- /dev/null +++ b/Component/Forms/FormAuthor.Designer.cs @@ -0,0 +1,39 @@ +namespace Forms +{ + partial class FormAuthor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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 + } +} \ No newline at end of file diff --git a/Component/Forms/FormAuthor.cs b/Component/Forms/FormAuthor.cs new file mode 100644 index 0000000..540e8ca --- /dev/null +++ b/Component/Forms/FormAuthor.cs @@ -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(); + } + } +} diff --git a/Component/Forms/FormAuthor.resx b/Component/Forms/FormAuthor.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Component/Forms/FormAuthor.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Component/Forms/FormMain.Designer.cs b/Component/Forms/FormMain.Designer.cs new file mode 100644 index 0000000..48287bf --- /dev/null +++ b/Component/Forms/FormMain.Designer.cs @@ -0,0 +1,58 @@ +namespace Forms +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Component/Forms/FormMain.cs b/Component/Forms/FormMain.cs new file mode 100644 index 0000000..3b392c1 --- /dev/null +++ b/Component/Forms/FormMain.cs @@ -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 = new List() + { + 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(book); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Component/Forms/FormMain.resx b/Component/Forms/FormMain.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Component/Forms/FormMain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Component/Forms/Forms.csproj b/Component/Forms/Forms.csproj index 48c8eb5..044f013 100644 --- a/Component/Forms/Forms.csproj +++ b/Component/Forms/Forms.csproj @@ -2,14 +2,29 @@ WinExe - net6.0-windows + net8.0-windows enable true enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Component/Forms/Program.cs b/Component/Forms/Program.cs index 99bf841..c529e12 100644 --- a/Component/Forms/Program.cs +++ b/Component/Forms/Program.cs @@ -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; + + /// + /// IoC- + /// + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -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()); + } + + /// + /// + /// + /// + private static void ConfigureServices(ServiceCollection services) + { + // + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + + // IoC-, + services.AddTransient(); + services.AddTransient(); + + // IoC-, - + services.AddTransient(); + services.AddTransient(); + + // IoC-, + services.AddTransient(); + //services.AddTransient(); + //services.AddTransient(); } } } \ No newline at end of file