diff --git a/BookShop/BookShopBusinessLogic/BusinessLogics/AuthorLogic.cs b/BookShop/BookShopBusinessLogic/BusinessLogics/AuthorLogic.cs index 6e90f84..c2afdfd 100644 --- a/BookShop/BookShopBusinessLogic/BusinessLogics/AuthorLogic.cs +++ b/BookShop/BookShopBusinessLogic/BusinessLogics/AuthorLogic.cs @@ -4,21 +4,23 @@ using BookShopContracts.SearchModels; using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopBusinessLogic.BusinessLogics { public class AuthorLogic : IAuthorLogic { private readonly ILogger _logger; - private readonly IAuthorStorage _authorStorage; - public AuthorLogic(ILogger logger, IAuthorStorage authorStorage) { _logger = logger; _authorStorage = authorStorage; } - public bool Create(AuthorBindingModel model) { CheckModel(model); diff --git a/BookShop/BookShopBusinessLogic/BusinessLogics/BookLogic.cs b/BookShop/BookShopBusinessLogic/BusinessLogics/BookLogic.cs index cfa2ec9..3e92197 100644 --- a/BookShop/BookShopBusinessLogic/BusinessLogics/BookLogic.cs +++ b/BookShop/BookShopBusinessLogic/BusinessLogics/BookLogic.cs @@ -4,21 +4,23 @@ using BookShopContracts.SearchModels; using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopBusinessLogic.BusinessLogics { public class BookLogic : IBookLogic { private readonly ILogger _logger; - private readonly IBookStorage _bookStorage; - public BookLogic(ILogger logger, IBookStorage bookStorage) { _logger = logger; _bookStorage = bookStorage; } - public bool Create(BookBindingModel model) { CheckModel(model); @@ -81,7 +83,6 @@ namespace BookShopBusinessLogic.BusinessLogics { return _bookStorage.TestReadList(num); } - public bool Update(BookBindingModel model) { CheckModel(model); diff --git a/BookShop/BookShopBusinessLogic/BusinessLogics/ClientLogic.cs b/BookShop/BookShopBusinessLogic/BusinessLogics/ClientLogic.cs index aa17753..99345c6 100644 --- a/BookShop/BookShopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/BookShop/BookShopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -4,21 +4,23 @@ using BookShopContracts.SearchModels; using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopBusinessLogic.BusinessLogics { public class ClientLogic : IClientLogic { private readonly ILogger _logger; - private readonly IClientStorage _clientStorage; - public ClientLogic(ILogger logger, IClientStorage clientStorage) { _logger = logger; _clientStorage = clientStorage; } - public bool Create(ClientBindingModel model) { CheckModel(model); diff --git a/BookShop/BookShopBusinessLogic/BusinessLogics/GenreLogic.cs b/BookShop/BookShopBusinessLogic/BusinessLogics/GenreLogic.cs index 2fa7d78..efd7855 100644 --- a/BookShop/BookShopBusinessLogic/BusinessLogics/GenreLogic.cs +++ b/BookShop/BookShopBusinessLogic/BusinessLogics/GenreLogic.cs @@ -5,20 +5,23 @@ using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using BookShopDataModels.Models; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopBusinessLogic.BusinessLogics { public class GenreLogic : IGenreLogic { private readonly ILogger _logger; - private readonly IGenreStorage _genreStorage; public GenreLogic(ILogger logger, IGenreStorage genreStorage) { _logger = logger; _genreStorage = genreStorage; } - public bool Create(GenreBindingModel model) { CheckModel(model); diff --git a/BookShop/BookShopBusinessLogic/BusinessLogics/OrderLogic.cs b/BookShop/BookShopBusinessLogic/BusinessLogics/OrderLogic.cs index b3c3c20..1921908 100644 --- a/BookShop/BookShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BookShop/BookShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -4,13 +4,17 @@ using BookShopContracts.SearchModels; using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic { private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; public OrderLogic(ILogger logger, IOrderStorage orderStorage) @@ -75,7 +79,6 @@ namespace BookShopBusinessLogic.BusinessLogics _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. Id: { BookId}", model.Id, model.Sum, model.BookId); } - public OrderViewModel? ReadElement(OrderSearchModel model) { if (model == null) diff --git a/BookShop/BookShopContracts/BindingModels/AuthorBindingModel.cs b/BookShop/BookShopContracts/BindingModels/AuthorBindingModel.cs index 3852329..55d38c8 100644 --- a/BookShop/BookShopContracts/BindingModels/AuthorBindingModel.cs +++ b/BookShop/BookShopContracts/BindingModels/AuthorBindingModel.cs @@ -1,15 +1,17 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BindingModels { public class AuthorBindingModel : IAuthorModel { public int Id { get; set; } - public string AuthorSurname { get; set; } = string.Empty; - public string AuthorName { get; set; } = string.Empty; - public string AuthorPatronymic { get; set; } = string.Empty; } } diff --git a/BookShop/BookShopContracts/BindingModels/BookBindingModel.cs b/BookShop/BookShopContracts/BindingModels/BookBindingModel.cs index 46ac549..75a7cb7 100644 --- a/BookShop/BookShopContracts/BindingModels/BookBindingModel.cs +++ b/BookShop/BookShopContracts/BindingModels/BookBindingModel.cs @@ -1,5 +1,10 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BindingModels { @@ -7,18 +12,13 @@ namespace BookShopContracts.BindingModels { public int Id { get; set; } [DisplayName("Название")] - public string BookName { get; set; } = string.Empty; [DisplayName("Стоимость")] - public double Cost { get; set; } [DisplayName("Количество")] - public int Count { get; set; } [DisplayName("Жанр")] - public int GenreId { get; set; } - public Dictionary BookAuthors { get; diff --git a/BookShop/BookShopContracts/BindingModels/ClientBindingModel.cs b/BookShop/BookShopContracts/BindingModels/ClientBindingModel.cs index 0511f11..4785273 100644 --- a/BookShop/BookShopContracts/BindingModels/ClientBindingModel.cs +++ b/BookShop/BookShopContracts/BindingModels/ClientBindingModel.cs @@ -1,17 +1,19 @@ -using BookShopDataModels.Models; +using BookShopContracts.BusinessLogicsContracts; +using BookShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BindingModels { public class ClientBindingModel : IClientModel { public int Id { get; set; } - public string ClientSurname { get; set; } = string.Empty; - public string ClientName { get; set; } = string.Empty; - public string ClientPatronymic { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; } diff --git a/BookShop/BookShopContracts/BindingModels/GenreBindingModel.cs b/BookShop/BookShopContracts/BindingModels/GenreBindingModel.cs index cfbe329..8e64276 100644 --- a/BookShop/BookShopContracts/BindingModels/GenreBindingModel.cs +++ b/BookShop/BookShopContracts/BindingModels/GenreBindingModel.cs @@ -1,11 +1,15 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BindingModels { public class GenreBindingModel : IGenreModel { public int Id { get; set; } - public string GenreName { get; set; } = string.Empty; } } diff --git a/BookShop/BookShopContracts/BindingModels/OrderBindingModel.cs b/BookShop/BookShopContracts/BindingModels/OrderBindingModel.cs index 781cafc..b537d3b 100644 --- a/BookShop/BookShopContracts/BindingModels/OrderBindingModel.cs +++ b/BookShop/BookShopContracts/BindingModels/OrderBindingModel.cs @@ -1,23 +1,21 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BindingModels { public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int BookId { get; set; } - public string BookName { get; set; } = string.Empty; - public int ClientId { get; set; } - public string ClientName { get; set; } = string.Empty; - public int Count { get; set; } - public double Sum { get; set; } - public DateTime DateCreate { get; set; } = DateTime.Now; } } diff --git a/BookShop/BookShopContracts/BusinessLogicsContracts/IAuthorLogic.cs b/BookShop/BookShopContracts/BusinessLogicsContracts/IAuthorLogic.cs index 954b9e9..2d6ef67 100644 --- a/BookShop/BookShopContracts/BusinessLogicsContracts/IAuthorLogic.cs +++ b/BookShop/BookShopContracts/BusinessLogicsContracts/IAuthorLogic.cs @@ -1,19 +1,20 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.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/BookShop/BookShopContracts/BusinessLogicsContracts/IBookLogic.cs b/BookShop/BookShopContracts/BusinessLogicsContracts/IBookLogic.cs index 3122f0a..abab755 100644 --- a/BookShop/BookShopContracts/BusinessLogicsContracts/IBookLogic.cs +++ b/BookShop/BookShopContracts/BusinessLogicsContracts/IBookLogic.cs @@ -1,23 +1,22 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BusinessLogicsContracts { public interface IBookLogic { List? ReadList(BookSearchModel? model); - BookViewModel? ReadElement(BookSearchModel model); - bool Create(BookBindingModel model); - bool Update(BookBindingModel model); - bool Delete(BookBindingModel model); - string TestInsertList(int num); - string TestReadList(int num); } } diff --git a/BookShop/BookShopContracts/BusinessLogicsContracts/IClientLogic.cs b/BookShop/BookShopContracts/BusinessLogicsContracts/IClientLogic.cs index 79f00f8..de8dcb6 100644 --- a/BookShop/BookShopContracts/BusinessLogicsContracts/IClientLogic.cs +++ b/BookShop/BookShopContracts/BusinessLogicsContracts/IClientLogic.cs @@ -1,19 +1,20 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BusinessLogicsContracts { public interface IClientLogic { List? ReadList(ClientSearchModel? model); - ClientViewModel? ReadElement(ClientSearchModel model); - bool Create(ClientBindingModel model); - bool Update(ClientBindingModel model); - bool Delete(ClientBindingModel model); } } diff --git a/BookShop/BookShopContracts/BusinessLogicsContracts/IGenreLogic.cs b/BookShop/BookShopContracts/BusinessLogicsContracts/IGenreLogic.cs index d4e65ee..91cdcbc 100644 --- a/BookShop/BookShopContracts/BusinessLogicsContracts/IGenreLogic.cs +++ b/BookShop/BookShopContracts/BusinessLogicsContracts/IGenreLogic.cs @@ -1,19 +1,20 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BusinessLogicsContracts { public interface IGenreLogic { List? ReadList(GenreSearchModel? model); - GenreViewModel? ReadElement(GenreSearchModel model); - bool Create(GenreBindingModel model); - bool Update(GenreBindingModel model); - bool Delete(GenreBindingModel model); } } diff --git a/BookShop/BookShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BookShop/BookShopContracts/BusinessLogicsContracts/IOrderLogic.cs index e3c01e3..227fdf9 100644 --- a/BookShop/BookShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/BookShop/BookShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,15 +1,18 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.BusinessLogicsContracts { public interface IOrderLogic { List? ReadList(OrderSearchModel? model); - OrderViewModel? ReadElement(OrderSearchModel model); - bool Create(OrderBindingModel model); } } diff --git a/BookShop/BookShopContracts/SearchModels/AuthorSearchModel.cs b/BookShop/BookShopContracts/SearchModels/AuthorSearchModel.cs index 2f68560..850a415 100644 --- a/BookShop/BookShopContracts/SearchModels/AuthorSearchModel.cs +++ b/BookShop/BookShopContracts/SearchModels/AuthorSearchModel.cs @@ -1,11 +1,15 @@ -namespace BookShopContracts.SearchModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopContracts.SearchModels { public class AuthorSearchModel { public int? Id { get; set; } - public string? AuthorSurname { get; set; } - public string? AuthorName { get; set; } } } diff --git a/BookShop/BookShopContracts/SearchModels/BookSearchModel.cs b/BookShop/BookShopContracts/SearchModels/BookSearchModel.cs index cb59529..f94bdab 100644 --- a/BookShop/BookShopContracts/SearchModels/BookSearchModel.cs +++ b/BookShop/BookShopContracts/SearchModels/BookSearchModel.cs @@ -1,9 +1,14 @@ -namespace BookShopContracts.SearchModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopContracts.SearchModels { public class BookSearchModel { public int? Id { get; set; } - public string? BookName { get; set; } } } diff --git a/BookShop/BookShopContracts/SearchModels/ClientSearchModel.cs b/BookShop/BookShopContracts/SearchModels/ClientSearchModel.cs index 290cb22..b77faf6 100644 --- a/BookShop/BookShopContracts/SearchModels/ClientSearchModel.cs +++ b/BookShop/BookShopContracts/SearchModels/ClientSearchModel.cs @@ -1,15 +1,17 @@ -namespace BookShopContracts.SearchModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopContracts.SearchModels { public class ClientSearchModel { public int? Id { get; set; } - public string? ClientSurname { get; set; } - public string? ClientName { get; set; } - public string? ClientPatronymic { get; set; } - public string? Email { get; set; } } } diff --git a/BookShop/BookShopContracts/SearchModels/GenreSearchModel.cs b/BookShop/BookShopContracts/SearchModels/GenreSearchModel.cs index 8fa1747..56dfb30 100644 --- a/BookShop/BookShopContracts/SearchModels/GenreSearchModel.cs +++ b/BookShop/BookShopContracts/SearchModels/GenreSearchModel.cs @@ -1,9 +1,14 @@ -namespace BookShopContracts.SearchModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopContracts.SearchModels { public class GenreSearchModel { public int? Id { get; set; } - public string? GenreName { get; set; } } } diff --git a/BookShop/BookShopContracts/SearchModels/OrderSearchModel.cs b/BookShop/BookShopContracts/SearchModels/OrderSearchModel.cs index 15e39c8..0a98be1 100644 --- a/BookShop/BookShopContracts/SearchModels/OrderSearchModel.cs +++ b/BookShop/BookShopContracts/SearchModels/OrderSearchModel.cs @@ -1,11 +1,15 @@ -namespace BookShopContracts.SearchModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } - public int? ClientId { get; set; } - public DateTime? DateCreate { get; set; } } } diff --git a/BookShop/BookShopContracts/StoragesContracts/IAuthorStorage.cs b/BookShop/BookShopContracts/StoragesContracts/IAuthorStorage.cs index 35086b7..82a0d8f 100644 --- a/BookShop/BookShopContracts/StoragesContracts/IAuthorStorage.cs +++ b/BookShop/BookShopContracts/StoragesContracts/IAuthorStorage.cs @@ -1,21 +1,21 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.StoragesContracts { 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/BookShop/BookShopContracts/StoragesContracts/IBookStorage.cs b/BookShop/BookShopContracts/StoragesContracts/IBookStorage.cs index aba342f..f225710 100644 --- a/BookShop/BookShopContracts/StoragesContracts/IBookStorage.cs +++ b/BookShop/BookShopContracts/StoragesContracts/IBookStorage.cs @@ -1,25 +1,23 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.StoragesContracts { 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); - string TestInsertList(int num); - string TestReadList(int num); } } diff --git a/BookShop/BookShopContracts/StoragesContracts/IClientStorage.cs b/BookShop/BookShopContracts/StoragesContracts/IClientStorage.cs index 209ba24..6c89641 100644 --- a/BookShop/BookShopContracts/StoragesContracts/IClientStorage.cs +++ b/BookShop/BookShopContracts/StoragesContracts/IClientStorage.cs @@ -1,21 +1,21 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.StoragesContracts { public interface IClientStorage { List GetFullList(); - List GetFilteredList(ClientSearchModel model); - ClientViewModel? GetElement(ClientSearchModel model); - ClientViewModel? Insert(ClientBindingModel model); - ClientViewModel? Update(ClientBindingModel model); - ClientViewModel? Delete(ClientBindingModel model); } } diff --git a/BookShop/BookShopContracts/StoragesContracts/IGenreStorage.cs b/BookShop/BookShopContracts/StoragesContracts/IGenreStorage.cs index 93b6a2c..7df52b5 100644 --- a/BookShop/BookShopContracts/StoragesContracts/IGenreStorage.cs +++ b/BookShop/BookShopContracts/StoragesContracts/IGenreStorage.cs @@ -1,21 +1,21 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.StoragesContracts { public interface IGenreStorage { List GetFullList(); - List GetFilteredList(GenreSearchModel model); - GenreViewModel? GetElement(GenreSearchModel model); - GenreViewModel? Insert(GenreBindingModel model); - GenreViewModel? Update(GenreBindingModel model); - GenreViewModel? Delete(GenreBindingModel model); } } diff --git a/BookShop/BookShopContracts/StoragesContracts/IOrderStorage.cs b/BookShop/BookShopContracts/StoragesContracts/IOrderStorage.cs index dfb05d5..203352e 100644 --- a/BookShop/BookShopContracts/StoragesContracts/IOrderStorage.cs +++ b/BookShop/BookShopContracts/StoragesContracts/IOrderStorage.cs @@ -1,17 +1,19 @@ using BookShopContracts.BindingModels; using BookShopContracts.SearchModels; using BookShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.StoragesContracts { public interface IOrderStorage { List GetFullList(); - List GetFilteredList(OrderSearchModel model); - OrderViewModel? GetElement(OrderSearchModel model); - OrderViewModel? Insert(OrderBindingModel model); } } diff --git a/BookShop/BookShopContracts/ViewModels/AuthorViewModel.cs b/BookShop/BookShopContracts/ViewModels/AuthorViewModel.cs index 831e81b..083258f 100644 --- a/BookShop/BookShopContracts/ViewModels/AuthorViewModel.cs +++ b/BookShop/BookShopContracts/ViewModels/AuthorViewModel.cs @@ -1,5 +1,10 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.ViewModels { @@ -7,13 +12,10 @@ namespace BookShopContracts.ViewModels { public int Id { get; set; } [DisplayName("Фамилия автора")] - public string AuthorSurname { get; set; } = string.Empty; [DisplayName("Имя автора")] - public string AuthorName { get; set; } = string.Empty; [DisplayName("Отчество автора")] - public string AuthorPatronymic { get; set; } = string.Empty; } } diff --git a/BookShop/BookShopContracts/ViewModels/BookViewModel.cs b/BookShop/BookShopContracts/ViewModels/BookViewModel.cs index 18402c6..92c563d 100644 --- a/BookShop/BookShopContracts/ViewModels/BookViewModel.cs +++ b/BookShop/BookShopContracts/ViewModels/BookViewModel.cs @@ -1,5 +1,10 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.ViewModels { @@ -7,18 +12,12 @@ namespace BookShopContracts.ViewModels { public int Id { get; set; } [DisplayName("Название")] - public string BookName { get; set; } = string.Empty; [DisplayName("Стоимость")] - public double Cost { get; set; } - public int Count { get; set; } - public int GenreId { get; set; } - public string GenreName { get; set; } = string.Empty; - public Dictionary BookAuthors { get; set; } = new(); } } diff --git a/BookShop/BookShopContracts/ViewModels/ClientViewModel.cs b/BookShop/BookShopContracts/ViewModels/ClientViewModel.cs index 3c27a74..a98c649 100644 --- a/BookShop/BookShopContracts/ViewModels/ClientViewModel.cs +++ b/BookShop/BookShopContracts/ViewModels/ClientViewModel.cs @@ -1,6 +1,11 @@ using BookShopContracts.BusinessLogicsContracts; using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.ViewModels { @@ -8,16 +13,12 @@ namespace BookShopContracts.ViewModels { public int Id { get; set; } [DisplayName("Фамилия клиента")] - public string ClientSurname { get; set; } = string.Empty; [DisplayName("Имя клиента")] - public string ClientName { get; set; } = string.Empty; [DisplayName("Отчество клиента")] - public string ClientPatronymic { get; set; } = string.Empty; - [DisplayName("Электронная почта клиента")] - + [DisplayName("Почта клиента")] public string Email { get; set; } = string.Empty; } } diff --git a/BookShop/BookShopContracts/ViewModels/GenreViewModel.cs b/BookShop/BookShopContracts/ViewModels/GenreViewModel.cs index 575b225..fed19f0 100644 --- a/BookShop/BookShopContracts/ViewModels/GenreViewModel.cs +++ b/BookShop/BookShopContracts/ViewModels/GenreViewModel.cs @@ -1,5 +1,10 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.ViewModels { @@ -7,7 +12,6 @@ namespace BookShopContracts.ViewModels { public int Id { get; set; } [DisplayName("Жанр")] - public string GenreName { get; set; } = string.Empty; } } diff --git a/BookShop/BookShopContracts/ViewModels/OrderViewModel.cs b/BookShop/BookShopContracts/ViewModels/OrderViewModel.cs index c521531..1f24f54 100644 --- a/BookShop/BookShopContracts/ViewModels/OrderViewModel.cs +++ b/BookShop/BookShopContracts/ViewModels/OrderViewModel.cs @@ -1,29 +1,27 @@ using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopContracts.ViewModels { public class OrderViewModel: IOrderModel { public int Id { get; set; } - public int BookId { get; set; } [DisplayName("Название книги")] - public string BookName { get; set; } = string.Empty; - public int ClientId { get; set; } [DisplayName("Фамилия клиента")] - public string ClientSurname {get; set; } = string.Empty; [DisplayName("Количество")] - public int Count { get; set; } [DisplayName("Сумма")] - public double Sum { get; set; } [DisplayName("Дата заказа")] - public DateTime DateCreate { get; set; } = DateTime.Now; } } diff --git a/BookShop/BookShopDataBaseImplement/BookShopDataBaseImplement.csproj b/BookShop/BookShopDataBaseImplement/BookShopDataBaseImplement.csproj index f9d44cf..f4eb208 100644 --- a/BookShop/BookShopDataBaseImplement/BookShopDataBaseImplement.csproj +++ b/BookShop/BookShopDataBaseImplement/BookShopDataBaseImplement.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -19,4 +20,10 @@ + + + Never + + + diff --git a/BookShop/BookShopDataBaseImplement/BookShopDatabase.cs b/BookShop/BookShopDataBaseImplement/BookShopDatabase.cs index c8be76a..29302a9 100644 --- a/BookShop/BookShopDataBaseImplement/BookShopDatabase.cs +++ b/BookShop/BookShopDataBaseImplement/BookShopDatabase.cs @@ -9,15 +9,15 @@ namespace BookShopDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql(@"Host=192.168.56.101;Port=5432;Database=SUBD_Lab2;Username=postgres;Password=postgres"); + optionsBuilder.UseNpgsql(@"Host=192.168.56.101;Port=5432;Database=BookShopOnline;Username=postgres;Password=1092010"); } base.OnConfiguring(optionsBuilder); - } - public virtual DbSet Authors { set; get; } - public virtual DbSet Books { set; get; } - public virtual DbSet BookAuthors { set; get; } - public virtual DbSet Orders { set; get; } - public virtual DbSet Clients { set; get; } - public virtual DbSet Genres { set; get; } - } + } + public virtual DbSet Authors { set; get; } + public virtual DbSet Books { set; get; } + public virtual DbSet BookAuthors { set; get; } + public virtual DbSet Orders { set; get; } + public virtual DbSet Clients { set; get; } + public virtual DbSet Genres { set; get; } + } } diff --git a/BookShop/BookShopDataBaseImplement/Implements/AuthorStorage.cs b/BookShop/BookShopDataBaseImplement/Implements/AuthorStorage.cs index 774b108..ee6196e 100644 --- a/BookShop/BookShopDataBaseImplement/Implements/AuthorStorage.cs +++ b/BookShop/BookShopDataBaseImplement/Implements/AuthorStorage.cs @@ -3,6 +3,11 @@ using BookShopContracts.SearchModels; using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using BookShopDataBaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Implements { diff --git a/BookShop/BookShopDataBaseImplement/Implements/BookStorage.cs b/BookShop/BookShopDataBaseImplement/Implements/BookStorage.cs index 1196e07..d47dab8 100644 --- a/BookShop/BookShopDataBaseImplement/Implements/BookStorage.cs +++ b/BookShop/BookShopDataBaseImplement/Implements/BookStorage.cs @@ -4,7 +4,12 @@ using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using BookShopDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Implements { diff --git a/BookShop/BookShopDataBaseImplement/Implements/ClientStorage.cs b/BookShop/BookShopDataBaseImplement/Implements/ClientStorage.cs index 2ffb529..7cb0a8b 100644 --- a/BookShop/BookShopDataBaseImplement/Implements/ClientStorage.cs +++ b/BookShop/BookShopDataBaseImplement/Implements/ClientStorage.cs @@ -3,6 +3,11 @@ using BookShopContracts.SearchModels; using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using BookShopDataBaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Implements { diff --git a/BookShop/BookShopDataBaseImplement/Implements/GenreStorage.cs b/BookShop/BookShopDataBaseImplement/Implements/GenreStorage.cs index 1c7f7db..3f85db0 100644 --- a/BookShop/BookShopDataBaseImplement/Implements/GenreStorage.cs +++ b/BookShop/BookShopDataBaseImplement/Implements/GenreStorage.cs @@ -4,7 +4,12 @@ using BookShopContracts.StoragesContracts; using BookShopContracts.ViewModels; using BookShopDataBaseImplement.Models; using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Implements { diff --git a/BookShop/BookShopDataBaseImplement/Migrations/20230512083316_Initial.Designer.cs b/BookShop/BookShopDataBaseImplement/Migrations/20230513100358_Sec.Designer.cs similarity index 99% rename from BookShop/BookShopDataBaseImplement/Migrations/20230512083316_Initial.Designer.cs rename to BookShop/BookShopDataBaseImplement/Migrations/20230513100358_Sec.Designer.cs index 3bc2ca4..d929d82 100644 --- a/BookShop/BookShopDataBaseImplement/Migrations/20230512083316_Initial.Designer.cs +++ b/BookShop/BookShopDataBaseImplement/Migrations/20230513100358_Sec.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace BookShopDataBaseImplement.Migrations { [DbContext(typeof(BookShopDatabase))] - [Migration("20230512083316_Initial")] - partial class Initial + [Migration("20230513100358_Sec")] + partial class Sec { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/BookShop/BookShopDataBaseImplement/Migrations/20230512083316_Initial.cs b/BookShop/BookShopDataBaseImplement/Migrations/20230513100358_Sec.cs similarity index 99% rename from BookShop/BookShopDataBaseImplement/Migrations/20230512083316_Initial.cs rename to BookShop/BookShopDataBaseImplement/Migrations/20230513100358_Sec.cs index 14cec87..211bbe1 100644 --- a/BookShop/BookShopDataBaseImplement/Migrations/20230512083316_Initial.cs +++ b/BookShop/BookShopDataBaseImplement/Migrations/20230513100358_Sec.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace BookShopDataBaseImplement.Migrations { /// - public partial class Initial : Migration + public partial class Sec : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/BookShop/BookShopDataBaseImplement/Models/Author.cs b/BookShop/BookShopDataBaseImplement/Models/Author.cs index e0913ec..d001715 100644 --- a/BookShop/BookShopDataBaseImplement/Models/Author.cs +++ b/BookShop/BookShopDataBaseImplement/Models/Author.cs @@ -1,8 +1,13 @@ using BookShopContracts.BindingModels; using BookShopContracts.ViewModels; using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Models { diff --git a/BookShop/BookShopDataBaseImplement/Models/Book.cs b/BookShop/BookShopDataBaseImplement/Models/Book.cs index 5e2df94..9360932 100644 --- a/BookShop/BookShopDataBaseImplement/Models/Book.cs +++ b/BookShop/BookShopDataBaseImplement/Models/Book.cs @@ -1,8 +1,13 @@ using BookShopContracts.BindingModels; using BookShopContracts.ViewModels; using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using System.Diagnostics; namespace BookShopDataBaseImplement.Models diff --git a/BookShop/BookShopDataBaseImplement/Models/BookAuthor.cs b/BookShop/BookShopDataBaseImplement/Models/BookAuthor.cs index 20ee469..2777120 100644 --- a/BookShop/BookShopDataBaseImplement/Models/BookAuthor.cs +++ b/BookShop/BookShopDataBaseImplement/Models/BookAuthor.cs @@ -1,5 +1,10 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Models { diff --git a/BookShop/BookShopDataBaseImplement/Models/Client.cs b/BookShop/BookShopDataBaseImplement/Models/Client.cs index e4bbd83..a77dafc 100644 --- a/BookShop/BookShopDataBaseImplement/Models/Client.cs +++ b/BookShop/BookShopDataBaseImplement/Models/Client.cs @@ -1,8 +1,13 @@ using BookShopContracts.BindingModels; using BookShopContracts.ViewModels; using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Models { diff --git a/BookShop/BookShopDataBaseImplement/Models/Genre.cs b/BookShop/BookShopDataBaseImplement/Models/Genre.cs index fb318cd..6ba8002 100644 --- a/BookShop/BookShopDataBaseImplement/Models/Genre.cs +++ b/BookShop/BookShopDataBaseImplement/Models/Genre.cs @@ -1,8 +1,13 @@ using BookShopContracts.BindingModels; using BookShopContracts.ViewModels; using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Models { diff --git a/BookShop/BookShopDataBaseImplement/Models/Order.cs b/BookShop/BookShopDataBaseImplement/Models/Order.cs index 363e5b2..7c406bc 100644 --- a/BookShop/BookShopDataBaseImplement/Models/Order.cs +++ b/BookShop/BookShopDataBaseImplement/Models/Order.cs @@ -1,7 +1,12 @@ using BookShopContracts.BindingModels; using BookShopContracts.ViewModels; using BookShopDataModels.Models; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace BookShopDataBaseImplement.Models { @@ -67,8 +72,8 @@ namespace BookShopDataBaseImplement.Models Id = Id, ClientId = ClientId, ClientSurname = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientSurname ?? string.Empty, - BookName = context.Books.FirstOrDefault(x => x.Id == BookId)?.BookName ?? string.Empty, - BookId = BookId, + BookId = BookId, + BookName = context.Books.FirstOrDefault(x => x.Id == BookId)?.BookName ?? string.Empty, Count = Count, Sum = Sum, DateCreate = DateCreate diff --git a/BookShop/BookShopDataModels/Models/IAuthorModel.cs b/BookShop/BookShopDataModels/Models/IAuthorModel.cs index 19a6209..681994f 100644 --- a/BookShop/BookShopDataModels/Models/IAuthorModel.cs +++ b/BookShop/BookShopDataModels/Models/IAuthorModel.cs @@ -1,11 +1,15 @@ -namespace BookShopDataModels.Models +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopDataModels.Models { public interface IAuthorModel: IId { string AuthorSurname { get; } - string AuthorName { get; } - string AuthorPatronymic { get; } } } diff --git a/BookShop/BookShopDataModels/Models/IBookModel.cs b/BookShop/BookShopDataModels/Models/IBookModel.cs index 8936b28..e1502b9 100644 --- a/BookShop/BookShopDataModels/Models/IBookModel.cs +++ b/BookShop/BookShopDataModels/Models/IBookModel.cs @@ -1,15 +1,17 @@ -namespace BookShopDataModels.Models +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopDataModels.Models { public interface IBookModel: IId { string BookName { get; } - double Cost { get; } - int Count { get; } - int GenreId { get; } - Dictionary BookAuthors { get; } } } diff --git a/BookShop/BookShopDataModels/Models/IClientModel.cs b/BookShop/BookShopDataModels/Models/IClientModel.cs index 95cd1fa..07d3383 100644 --- a/BookShop/BookShopDataModels/Models/IClientModel.cs +++ b/BookShop/BookShopDataModels/Models/IClientModel.cs @@ -1,13 +1,16 @@ -namespace BookShopDataModels.Models +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopDataModels.Models { public interface IClientModel: IId { string ClientSurname { get; } - string ClientName { get; } - string ClientPatronymic { get; } - string Email { get; } } } diff --git a/BookShop/BookShopDataModels/Models/IGenreModel.cs b/BookShop/BookShopDataModels/Models/IGenreModel.cs index fba6efe..0ae344f 100644 --- a/BookShop/BookShopDataModels/Models/IGenreModel.cs +++ b/BookShop/BookShopDataModels/Models/IGenreModel.cs @@ -1,4 +1,10 @@ -namespace BookShopDataModels.Models +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopDataModels.Models { public interface IGenreModel : IId { diff --git a/BookShop/BookShopDataModels/Models/IOrderModel.cs b/BookShop/BookShopDataModels/Models/IOrderModel.cs index 551950c..2383b84 100644 --- a/BookShop/BookShopDataModels/Models/IOrderModel.cs +++ b/BookShop/BookShopDataModels/Models/IOrderModel.cs @@ -1,15 +1,17 @@ -namespace BookShopDataModels.Models +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookShopDataModels.Models { public interface IOrderModel: IId { int Count { get; } - int BookId { get; } - int ClientId { get; } - double Sum { get; } - DateTime DateCreate { get; } } } diff --git a/BookShop/BookShopView/BookShopView.csproj b/BookShop/BookShopView/BookShopView.csproj index 0162b34..edc586d 100644 --- a/BookShop/BookShopView/BookShopView.csproj +++ b/BookShop/BookShopView/BookShopView.csproj @@ -13,6 +13,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/BookShop/BookShopView/Form1.Designer.cs b/BookShop/BookShopView/Form1.Designer.cs deleted file mode 100644 index 8fdf3cd..0000000 --- a/BookShop/BookShopView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace BookShopView -{ - partial class Form1 - { - /// - /// 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 = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/BookShop/BookShopView/Form1.cs b/BookShop/BookShopView/Form1.cs deleted file mode 100644 index 8004282..0000000 --- a/BookShop/BookShopView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace BookShopView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/BookShop/BookShopView/Form1.resx b/BookShop/BookShopView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/BookShop/BookShopView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/BookShop/BookShopView/FormAuthor.Designer.cs b/BookShop/BookShopView/FormAuthor.Designer.cs new file mode 100644 index 0000000..98d63b1 --- /dev/null +++ b/BookShop/BookShopView/FormAuthor.Designer.cs @@ -0,0 +1,147 @@ +namespace BookShopView +{ + 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.FTextBox = new System.Windows.Forms.TextBox(); + this.ITextBox = new System.Windows.Forms.TextBox(); + this.LabelF = new System.Windows.Forms.Label(); + this.LabelI = new System.Windows.Forms.Label(); + this.LabelP = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.OTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // FTextBox + // + this.FTextBox.Location = new System.Drawing.Point(128, 16); + this.FTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.FTextBox.Name = "FTextBox"; + this.FTextBox.Size = new System.Drawing.Size(194, 27); + this.FTextBox.TabIndex = 0; + // + // ITextBox + // + this.ITextBox.Location = new System.Drawing.Point(128, 65); + this.ITextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ITextBox.Name = "ITextBox"; + this.ITextBox.Size = new System.Drawing.Size(194, 27); + this.ITextBox.TabIndex = 1; + // + // LabelF + // + this.LabelF.AutoSize = true; + this.LabelF.Location = new System.Drawing.Point(14, 20); + this.LabelF.Name = "LabelF"; + this.LabelF.Size = new System.Drawing.Size(80, 20); + this.LabelF.TabIndex = 2; + this.LabelF.Text = "Фамилия: "; + // + // LabelI + // + this.LabelI.AutoSize = true; + this.LabelI.Location = new System.Drawing.Point(14, 69); + this.LabelI.Name = "LabelI"; + this.LabelI.Size = new System.Drawing.Size(42, 20); + this.LabelI.TabIndex = 3; + this.LabelI.Text = "Имя:"; + // + // LabelP + // + this.LabelP.AutoSize = true; + this.LabelP.Location = new System.Drawing.Point(14, 123); + this.LabelP.Name = "LabelP"; + this.LabelP.Size = new System.Drawing.Size(75, 20); + this.LabelP.TabIndex = 6; + this.LabelP.Text = "Отчество:"; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(214, 172); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(111, 39); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(97, 172); + this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(111, 39); + this.ButtonSave.TabIndex = 9; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // OTextBox + // + this.OTextBox.Location = new System.Drawing.Point(128, 116); + this.OTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.OTextBox.Name = "OTextBox"; + this.OTextBox.Size = new System.Drawing.Size(194, 27); + this.OTextBox.TabIndex = 10; + // + // FormAuthor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(350, 222); + this.Controls.Add(this.OTextBox); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.LabelP); + this.Controls.Add(this.LabelI); + this.Controls.Add(this.LabelF); + this.Controls.Add(this.ITextBox); + this.Controls.Add(this.FTextBox); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormAuthor"; + this.Text = "Автор"; + this.Load += new System.EventHandler(this.FormAuthor_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox FTextBox; + private TextBox ITextBox; + private Label LabelF; + private Label LabelI; + private Label LabelP; + private Button ButtonCancel; + private Button ButtonSave; + private TextBox OTextBox; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormAuthor.cs b/BookShop/BookShopView/FormAuthor.cs new file mode 100644 index 0000000..93981a4 --- /dev/null +++ b/BookShop/BookShopView/FormAuthor.cs @@ -0,0 +1,104 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using BookShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormAuthor : Form + { + private readonly ILogger _logger; + private readonly IAuthorLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormAuthor(ILogger logger, IAuthorLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FTextBox.Text)) + { + MessageBox.Show("Заполните фамилию", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(ITextBox.Text)) + { + MessageBox.Show("Заполните имя", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение автора"); + try + { + var model = new AuthorBindingModel + { + Id = _id ?? 0, + AuthorName = ITextBox.Text, + AuthorSurname = FTextBox.Text, + AuthorPatronymic = OTextBox.Text + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения автора"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormAuthor_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение автора"); + var view = _logic.ReadElement(new AuthorSearchModel + { + Id = _id.Value + }); + if (view != null) + { + FTextBox.Text = view.AuthorSurname; + ITextBox.Text = view.AuthorName; + OTextBox.Text = view.AuthorPatronymic; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения автора"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/BookShop/BookShopView/FormAuthor.resx b/BookShop/BookShopView/FormAuthor.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormAuthor.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormAuthors.Designer.cs b/BookShop/BookShopView/FormAuthors.Designer.cs new file mode 100644 index 0000000..14c8db7 --- /dev/null +++ b/BookShop/BookShopView/FormAuthors.Designer.cs @@ -0,0 +1,116 @@ +namespace BookShopView +{ + partial class FormAuthors + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonDelete = new System.Windows.Forms.Button(); + this.ButtonUpdate = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(461, 345); + this.dataGridView.TabIndex = 0; + // + // ButtonDelete + // + this.ButtonDelete.Location = new System.Drawing.Point(493, 181); + this.ButtonDelete.Name = "ButtonDelete"; + this.ButtonDelete.Size = new System.Drawing.Size(115, 54); + this.ButtonDelete.TabIndex = 1; + this.ButtonDelete.Text = "Удалить"; + this.ButtonDelete.UseVisualStyleBackColor = true; + this.ButtonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // ButtonUpdate + // + this.ButtonUpdate.Location = new System.Drawing.Point(493, 266); + this.ButtonUpdate.Name = "ButtonUpdate"; + this.ButtonUpdate.Size = new System.Drawing.Size(115, 58); + this.ButtonUpdate.TabIndex = 2; + this.ButtonUpdate.Text = "Обновить"; + this.ButtonUpdate.UseVisualStyleBackColor = true; + this.ButtonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(493, 30); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(115, 52); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(493, 103); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(115, 54); + this.buttonUpd.TabIndex = 4; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // FormAuthors + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(620, 372); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.ButtonUpdate); + this.Controls.Add(this.ButtonDelete); + this.Controls.Add(this.dataGridView); + this.Name = "FormAuthors"; + this.Text = "Авторы"; + this.Load += new System.EventHandler(this.FormAuthors_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonDelete; + private Button ButtonUpdate; + private Button buttonAdd; + private Button buttonUpd; + } +} diff --git a/BookShop/BookShopView/FormAuthors.cs b/BookShop/BookShopView/FormAuthors.cs new file mode 100644 index 0000000..09fd43e --- /dev/null +++ b/BookShop/BookShopView/FormAuthors.cs @@ -0,0 +1,113 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormAuthors : Form + { + private readonly ILogger _logger; + + private readonly IAuthorLogic _logic; + public FormAuthors(ILogger logger, IAuthorLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new AuthorBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + _logger.LogInformation("Удаление автора"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления автора"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormAuthor)); + if (service is FormAuthor form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void FormAuthors_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["AuthorSurname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["AuthorName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["AuthorPatronymic"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка авторов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки авторов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormAuthor)); + if (service is FormAuthor form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } +} diff --git a/BookShop/BookShopView/FormAuthors.resx b/BookShop/BookShopView/FormAuthors.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormAuthors.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormBook.Designer.cs b/BookShop/BookShopView/FormBook.Designer.cs new file mode 100644 index 0000000..ec02738 --- /dev/null +++ b/BookShop/BookShopView/FormBook.Designer.cs @@ -0,0 +1,268 @@ +namespace BookShopView +{ + partial class FormBook + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelGenre = new System.Windows.Forms.Label(); + this.TextBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.groupBox = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxGenre = new System.Windows.Forms.ComboBox(); + this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnAuthorSurname = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(26, 22); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(26, 61); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(86, 20); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Стоимость:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(26, 107); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // labelGenre + // + this.labelGenre.AutoSize = true; + this.labelGenre.Location = new System.Drawing.Point(26, 153); + this.labelGenre.Name = "labelGenre"; + this.labelGenre.Size = new System.Drawing.Size(51, 20); + this.labelGenre.TabIndex = 3; + this.labelGenre.Text = "Жанр:"; + // + // TextBoxName + // + this.TextBoxName.Location = new System.Drawing.Point(162, 22); + this.TextBoxName.Name = "TextBoxName"; + this.TextBoxName.Size = new System.Drawing.Size(259, 27); + this.TextBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(162, 61); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(259, 27); + this.textBoxCost.TabIndex = 5; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(162, 104); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(259, 27); + this.textBoxCount.TabIndex = 6; + // + // groupBox + // + this.groupBox.Controls.Add(this.buttonRef); + this.groupBox.Controls.Add(this.buttonDel); + this.groupBox.Controls.Add(this.buttonUpd); + this.groupBox.Controls.Add(this.buttonAdd); + this.groupBox.Controls.Add(this.dataGridView); + this.groupBox.Location = new System.Drawing.Point(26, 192); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(530, 247); + this.groupBox.TabIndex = 7; + this.groupBox.TabStop = false; + this.groupBox.Text = "Авторы"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(418, 199); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(418, 143); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(418, 84); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(418, 35); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnID, + this.ColumnAuthorSurname}); + this.dataGridView.Location = new System.Drawing.Point(6, 26); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(389, 215); + this.dataGridView.TabIndex = 0; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(310, 454); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(444, 454); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxGenre + // + this.comboBoxGenre.FormattingEnabled = true; + this.comboBoxGenre.Location = new System.Drawing.Point(160, 153); + this.comboBoxGenre.Name = "comboBoxGenre"; + this.comboBoxGenre.Size = new System.Drawing.Size(261, 28); + this.comboBoxGenre.TabIndex = 10; + // + // ColumnID + // + this.ColumnID.HeaderText = "ID"; + this.ColumnID.MinimumWidth = 6; + this.ColumnID.Name = "ColumnID"; + this.ColumnID.Visible = false; + this.ColumnID.Width = 125; + // + // ColumnAuthorSurname + // + this.ColumnAuthorSurname.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnAuthorSurname.HeaderText = "Автор"; + this.ColumnAuthorSurname.MinimumWidth = 6; + this.ColumnAuthorSurname.Name = "ColumnAuthorSurname"; + // + // FormBook + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(571, 495); + this.Controls.Add(this.comboBoxGenre); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBox); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.TextBoxName); + this.Controls.Add(this.labelGenre); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormBook"; + this.Text = "Книга"; + this.Load += new System.EventHandler(this.FormBook_Load); + this.groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private Label labelCount; + private Label labelGenre; + private TextBox TextBoxName; + private TextBox textBoxCost; + private TextBox textBoxCount; + private GroupBox groupBox; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxGenre; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnAuthorSurname; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormBook.cs b/BookShop/BookShopView/FormBook.cs new file mode 100644 index 0000000..0b62847 --- /dev/null +++ b/BookShop/BookShopView/FormBook.cs @@ -0,0 +1,242 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using BookShopContracts.SearchModels; +using BookShopContracts.ViewModels; +using BookShopDataModels.Models; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormBook : Form + { + private readonly ILogger _logger; + private readonly IBookLogic _logic; + private readonly IGenreLogic _logicG; + private int? _id; + private Dictionary _bookAuthors; + public int Id { set { _id = value; } } + public FormBook(ILogger logger, IBookLogic logic, IGenreLogic logicG) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _bookAuthors = new Dictionary(); + _logicG = logicG; + } + + private void FormBook_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка жанров"); + try + { + var list = _logicG.ReadList(null); + if (list != null) + { + comboBoxGenre.DisplayMember = "Genre"; + comboBoxGenre.ValueMember = "ID"; + comboBoxGenre.DataSource = list.Select(c => c.GenreName).ToList(); + comboBoxGenre.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка жанров"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + if (_id.HasValue) + { + _logger.LogInformation("Загрузка книги"); + try + { + var view = _logic.ReadElement(new BookSearchModel + { + Id = _id.Value + }); + if (view != null) + { + TextBoxName.Text = view.BookName; + textBoxCost.Text = view.Cost.ToString(); + textBoxCount.Text = view.Count.ToString(); + comboBoxGenre.SelectedIndex = view.GenreId; + _bookAuthors = view.BookAuthors ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки книги"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка автора книги"); + try + { + if (_bookAuthors != null) + { + + dataGridView.Rows.Clear(); + foreach (var pc in _bookAuthors) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.AuthorSurname }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки автора книги"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBookAuthor)); + if (service is FormBookAuthor form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.AuthorModel == null) + { + return; + } + if (_bookAuthors.ContainsKey(form.Id)) + { + _bookAuthors[form.Id] = (form.AuthorModel); + } + else + { + _bookAuthors.Add(form.Id, (form.AuthorModel)); + } + _logger.LogInformation("Добавление автора:{ AuthorSurname}", form.AuthorModel.AuthorSurname); + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormBookAuthor)); + if (service is FormBookAuthor form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.AuthorModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.AuthorModel.AuthorSurname); + _bookAuthors[form.Id] = (form.AuthorModel); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { AuthorSurname}", dataGridView.SelectedRows[0].Cells[1].Value); + _bookAuthors?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TextBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCost.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (comboBoxGenre.SelectedItem == null) + { + MessageBox.Show("Выберите жанр", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_bookAuthors == null || _bookAuthors.Count == 0) + { + MessageBox.Show("Заполните авторов", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new BookBindingModel + { + Id = _id ?? 0, + BookName = TextBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text), + Count = Convert.ToInt32(textBoxCount.Text), + GenreId = comboBoxGenre.SelectedIndex + 1, + BookAuthors = _bookAuthors + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения книги"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BookShop/BookShopView/FormBook.resx b/BookShop/BookShopView/FormBook.resx new file mode 100644 index 0000000..adad73e --- /dev/null +++ b/BookShop/BookShopView/FormBook.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + \ No newline at end of file diff --git a/BookShop/BookShopView/FormBookAuthor.Designer.cs b/BookShop/BookShopView/FormBookAuthor.Designer.cs new file mode 100644 index 0000000..92f2d88 --- /dev/null +++ b/BookShop/BookShopView/FormBookAuthor.Designer.cs @@ -0,0 +1,98 @@ +namespace BookShopView +{ + partial class FormBookAuthor + { + /// + /// 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.labelComponent = new System.Windows.Forms.Label(); + this.comboBoxAuthor = new System.Windows.Forms.ComboBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(34, 43); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(51, 20); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Автор"; + // + // comboBoxAuthor + // + this.comboBoxAuthor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxAuthor.FormattingEnabled = true; + this.comboBoxAuthor.Location = new System.Drawing.Point(128, 40); + this.comboBoxAuthor.Name = "comboBoxAuthor"; + this.comboBoxAuthor.Size = new System.Drawing.Size(265, 28); + this.comboBoxAuthor.TabIndex = 2; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(34, 117); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(114, 48); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(301, 117); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(114, 48); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormBookAuthor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(461, 190); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.comboBoxAuthor); + this.Controls.Add(this.labelComponent); + this.Name = "FormBookAuthor"; + this.Text = "Автор книги"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private ComboBox comboBoxAuthor; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormBookAuthor.cs b/BookShop/BookShopView/FormBookAuthor.cs new file mode 100644 index 0000000..abb4241 --- /dev/null +++ b/BookShop/BookShopView/FormBookAuthor.cs @@ -0,0 +1,77 @@ +using BookShopContracts.BusinessLogicsContracts; +using BookShopContracts.ViewModels; +using BookShopDataModels.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 BookShopView +{ + public partial class FormBookAuthor : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxAuthor.SelectedValue); + } + set + { + comboBoxAuthor.SelectedValue = value; + } + } + public IAuthorModel? AuthorModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public FormBookAuthor(IAuthorLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxAuthor.DisplayMember = "AuthorSurname"; + comboBoxAuthor.ValueMember = "Id"; + comboBoxAuthor.DataSource = _list; + comboBoxAuthor.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxAuthor.SelectedValue == null) + { + MessageBox.Show("Выберите автора", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BookShop/BookShopView/FormBookAuthor.resx b/BookShop/BookShopView/FormBookAuthor.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormBookAuthor.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormBooks.Designer.cs b/BookShop/BookShopView/FormBooks.Designer.cs new file mode 100644 index 0000000..8b72342 --- /dev/null +++ b/BookShop/BookShopView/FormBooks.Designer.cs @@ -0,0 +1,116 @@ +namespace BookShopView +{ + partial class FormBooks + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonDelete = new System.Windows.Forms.Button(); + this.ButtonUpdate = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(461, 345); + this.dataGridView.TabIndex = 0; + // + // ButtonDelete + // + this.ButtonDelete.Location = new System.Drawing.Point(493, 183); + this.ButtonDelete.Name = "ButtonDelete"; + this.ButtonDelete.Size = new System.Drawing.Size(115, 54); + this.ButtonDelete.TabIndex = 1; + this.ButtonDelete.Text = "Удалить"; + this.ButtonDelete.UseVisualStyleBackColor = true; + this.ButtonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonUpdate + // + this.ButtonUpdate.Location = new System.Drawing.Point(493, 266); + this.ButtonUpdate.Name = "ButtonUpdate"; + this.ButtonUpdate.Size = new System.Drawing.Size(115, 58); + this.ButtonUpdate.TabIndex = 2; + this.ButtonUpdate.Text = "Обновить"; + this.ButtonUpdate.UseVisualStyleBackColor = true; + this.ButtonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(493, 33); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(115, 52); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(493, 105); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(115, 52); + this.buttonUpd.TabIndex = 4; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // FormBooks + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(620, 372); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.ButtonUpdate); + this.Controls.Add(this.ButtonDelete); + this.Controls.Add(this.dataGridView); + this.Name = "FormBooks"; + this.Text = "Книги"; + this.Load += new System.EventHandler(this.FormBooks_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonDelete; + private Button ButtonUpdate; + private Button buttonAdd; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormBooks.cs b/BookShop/BookShopView/FormBooks.cs new file mode 100644 index 0000000..a3cc479 --- /dev/null +++ b/BookShop/BookShopView/FormBooks.cs @@ -0,0 +1,120 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormBooks : Form + { + private readonly ILogger _logger; + private readonly IBookLogic _logic; + public FormBooks(ILogger logger, IBookLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormBooks_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["BookName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Cost"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Count"].Visible = false; + dataGridView.Columns["GenreId"].Visible = false; + dataGridView.Columns["GenreName"].Visible = false; + dataGridView.Columns["BookAuthors"].Visible = false; + } + _logger.LogInformation("Загрузка книг"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки книг"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBook)); + if (service is FormBook form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + try + { + if (!_logic.Delete(new BookBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormBook)); + if (service is FormBook form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } +} diff --git a/BookShop/BookShopView/FormBooks.resx b/BookShop/BookShopView/FormBooks.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormBooks.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormClient.Designer.cs b/BookShop/BookShopView/FormClient.Designer.cs new file mode 100644 index 0000000..51d17f5 --- /dev/null +++ b/BookShop/BookShopView/FormClient.Designer.cs @@ -0,0 +1,170 @@ +namespace BookShopView +{ + partial class FormClient + { + /// + /// 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.FTextBox = new System.Windows.Forms.TextBox(); + this.ITextBox = new System.Windows.Forms.TextBox(); + this.LabelF = new System.Windows.Forms.Label(); + this.LabelI = new System.Windows.Forms.Label(); + this.LabelP = new System.Windows.Forms.Label(); + this.LabelQualification = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.OTextBox = new System.Windows.Forms.TextBox(); + this.EmailTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // FTextBox + // + this.FTextBox.Location = new System.Drawing.Point(128, 16); + this.FTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.FTextBox.Name = "FTextBox"; + this.FTextBox.Size = new System.Drawing.Size(194, 27); + this.FTextBox.TabIndex = 0; + // + // ITextBox + // + this.ITextBox.Location = new System.Drawing.Point(128, 65); + this.ITextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ITextBox.Name = "ITextBox"; + this.ITextBox.Size = new System.Drawing.Size(194, 27); + this.ITextBox.TabIndex = 1; + // + // LabelF + // + this.LabelF.AutoSize = true; + this.LabelF.Location = new System.Drawing.Point(14, 20); + this.LabelF.Name = "LabelF"; + this.LabelF.Size = new System.Drawing.Size(80, 20); + this.LabelF.TabIndex = 2; + this.LabelF.Text = "Фамилия: "; + // + // LabelI + // + this.LabelI.AutoSize = true; + this.LabelI.Location = new System.Drawing.Point(14, 69); + this.LabelI.Name = "LabelI"; + this.LabelI.Size = new System.Drawing.Size(42, 20); + this.LabelI.TabIndex = 3; + this.LabelI.Text = "Имя:"; + // + // LabelP + // + this.LabelP.AutoSize = true; + this.LabelP.Location = new System.Drawing.Point(14, 123); + this.LabelP.Name = "LabelP"; + this.LabelP.Size = new System.Drawing.Size(75, 20); + this.LabelP.TabIndex = 6; + this.LabelP.Text = "Отчество:"; + // + // LabelQualification + // + this.LabelQualification.AutoSize = true; + this.LabelQualification.Location = new System.Drawing.Point(14, 177); + this.LabelQualification.Name = "LabelQualification"; + this.LabelQualification.Size = new System.Drawing.Size(49, 20); + this.LabelQualification.TabIndex = 7; + this.LabelQualification.Text = "Email:"; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(211, 225); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(111, 39); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(94, 225); + this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(111, 39); + this.ButtonSave.TabIndex = 9; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // OTextBox + // + this.OTextBox.Location = new System.Drawing.Point(128, 116); + this.OTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.OTextBox.Name = "OTextBox"; + this.OTextBox.Size = new System.Drawing.Size(194, 27); + this.OTextBox.TabIndex = 10; + // + // EmailTextBox + // + this.EmailTextBox.Location = new System.Drawing.Point(128, 170); + this.EmailTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.EmailTextBox.Name = "EmailTextBox"; + this.EmailTextBox.Size = new System.Drawing.Size(194, 27); + this.EmailTextBox.TabIndex = 11; + // + // FormClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(350, 285); + this.Controls.Add(this.EmailTextBox); + this.Controls.Add(this.OTextBox); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.LabelQualification); + this.Controls.Add(this.LabelP); + this.Controls.Add(this.LabelI); + this.Controls.Add(this.LabelF); + this.Controls.Add(this.ITextBox); + this.Controls.Add(this.FTextBox); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormClient"; + this.Text = "Клиент"; + this.Click += new System.EventHandler(this.FormClient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox FTextBox; + private TextBox ITextBox; + private Label LabelF; + private Label LabelI; + private Label LabelP; + private Label LabelQualification; + private Button ButtonCancel; + private Button ButtonSave; + private TextBox OTextBox; + private TextBox EmailTextBox; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormClient.cs b/BookShop/BookShopView/FormClient.cs new file mode 100644 index 0000000..830fecc --- /dev/null +++ b/BookShop/BookShopView/FormClient.cs @@ -0,0 +1,113 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using BookShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormClient : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormClient(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FTextBox.Text)) + { + MessageBox.Show("Заполните фамилию", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(ITextBox.Text)) + { + MessageBox.Show("Заполните имя", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(EmailTextBox.Text)) + { + MessageBox.Show("Заполните почту", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение клиента"); + try + { + var model = new ClientBindingModel + { + Id = _id ?? 0, + ClientName = ITextBox.Text, + ClientSurname = FTextBox.Text, + ClientPatronymic = OTextBox.Text, + Email = EmailTextBox.Text + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormClient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение клиента"); + var view = _logic.ReadElement(new ClientSearchModel + { + Id = _id.Value + }); + if (view != null) + { + FTextBox.Text = view.ClientSurname; + ITextBox.Text = view.ClientName; + OTextBox.Text = view.ClientPatronymic; + EmailTextBox.Text = view.Email; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } +} diff --git a/BookShop/BookShopView/FormClient.resx b/BookShop/BookShopView/FormClient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormClient.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormClients.Designer.cs b/BookShop/BookShopView/FormClients.Designer.cs new file mode 100644 index 0000000..c6e0604 --- /dev/null +++ b/BookShop/BookShopView/FormClients.Designer.cs @@ -0,0 +1,116 @@ +namespace BookShopView +{ + partial class FormClients + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonDelete = new System.Windows.Forms.Button(); + this.ButtonUpdate = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(461, 345); + this.dataGridView.TabIndex = 0; + // + // ButtonDelete + // + this.ButtonDelete.Location = new System.Drawing.Point(493, 183); + this.ButtonDelete.Name = "ButtonDelete"; + this.ButtonDelete.Size = new System.Drawing.Size(115, 54); + this.ButtonDelete.TabIndex = 1; + this.ButtonDelete.Text = "Удалить"; + this.ButtonDelete.UseVisualStyleBackColor = true; + this.ButtonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // ButtonUpdate + // + this.ButtonUpdate.Location = new System.Drawing.Point(493, 266); + this.ButtonUpdate.Name = "ButtonUpdate"; + this.ButtonUpdate.Size = new System.Drawing.Size(115, 58); + this.ButtonUpdate.TabIndex = 2; + this.ButtonUpdate.Text = "Обновить"; + this.ButtonUpdate.UseVisualStyleBackColor = true; + this.ButtonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(493, 30); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(115, 52); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(493, 103); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(115, 54); + this.buttonUpd.TabIndex = 4; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(620, 372); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.ButtonUpdate); + this.Controls.Add(this.ButtonDelete); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.Text = "Клиенты"; + this.Load += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonDelete; + private Button ButtonUpdate; + private Button buttonAdd; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormClients.cs b/BookShop/BookShopView/FormClients.cs new file mode 100644 index 0000000..cf49ac6 --- /dev/null +++ b/BookShop/BookShopView/FormClients.cs @@ -0,0 +1,113 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new ClientBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + _logger.LogInformation("Удаление клиента"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientSurname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Email"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BookShop/BookShopView/FormClients.resx b/BookShop/BookShopView/FormClients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormClients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormGenre.Designer.cs b/BookShop/BookShopView/FormGenre.Designer.cs new file mode 100644 index 0000000..db7ae36 --- /dev/null +++ b/BookShop/BookShopView/FormGenre.Designer.cs @@ -0,0 +1,101 @@ +namespace BookShopView +{ + partial class FormGenre + { + /// + /// 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.NameTextBox = new System.Windows.Forms.TextBox(); + this.LabelName = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // NameTextBox + // + this.NameTextBox.Location = new System.Drawing.Point(128, 16); + this.NameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.NameTextBox.Name = "NameTextBox"; + this.NameTextBox.Size = new System.Drawing.Size(194, 27); + this.NameTextBox.TabIndex = 0; + // + // LabelName + // + this.LabelName.AutoSize = true; + this.LabelName.Location = new System.Drawing.Point(14, 20); + this.LabelName.Name = "LabelName"; + this.LabelName.Size = new System.Drawing.Size(80, 20); + this.LabelName.TabIndex = 2; + this.LabelName.Text = "Название:"; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(211, 63); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(111, 39); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(79, 63); + this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(111, 39); + this.ButtonSave.TabIndex = 9; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormGenre + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(350, 119); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.LabelName); + this.Controls.Add(this.NameTextBox); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormGenre"; + this.Text = "Жанр"; + this.Load += new System.EventHandler(this.FormGenre_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox NameTextBox; + private Label LabelName; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormGenre.cs b/BookShop/BookShopView/FormGenre.cs new file mode 100644 index 0000000..3a138c2 --- /dev/null +++ b/BookShop/BookShopView/FormGenre.cs @@ -0,0 +1,94 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using BookShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormGenre : Form + { + private readonly ILogger _logger; + private readonly IGenreLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormGenre(ILogger logger, IGenreLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение жанра"); + try + { + var model = new GenreBindingModel + { + Id = _id ?? 0, + GenreName = NameTextBox.Text + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения жанра"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormGenre_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение жанра"); + var view = _logic.ReadElement(new GenreSearchModel + { + Id = _id.Value + }); + if (view != null) + { + NameTextBox.Text = view.GenreName; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения жанра"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/BookShop/BookShopView/FormGenre.resx b/BookShop/BookShopView/FormGenre.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormGenre.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormGenres.Designer.cs b/BookShop/BookShopView/FormGenres.Designer.cs new file mode 100644 index 0000000..402e784 --- /dev/null +++ b/BookShop/BookShopView/FormGenres.Designer.cs @@ -0,0 +1,116 @@ +namespace BookShopView +{ + partial class FormGenres + { + /// + /// 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.DataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonDelete = new System.Windows.Forms.Button(); + this.ButtonUpdate = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(12, 12); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 29; + this.DataGridView.Size = new System.Drawing.Size(461, 345); + this.DataGridView.TabIndex = 0; + // + // ButtonDelete + // + this.ButtonDelete.Location = new System.Drawing.Point(493, 183); + this.ButtonDelete.Name = "ButtonDelete"; + this.ButtonDelete.Size = new System.Drawing.Size(115, 54); + this.ButtonDelete.TabIndex = 1; + this.ButtonDelete.Text = "Удалить"; + this.ButtonDelete.UseVisualStyleBackColor = true; + this.ButtonDelete.Click += new System.EventHandler(this.DeleteButton_Click); + // + // ButtonUpdate + // + this.ButtonUpdate.Location = new System.Drawing.Point(493, 266); + this.ButtonUpdate.Name = "ButtonUpdate"; + this.ButtonUpdate.Size = new System.Drawing.Size(115, 58); + this.ButtonUpdate.TabIndex = 2; + this.ButtonUpdate.Text = "Обновить"; + this.ButtonUpdate.UseVisualStyleBackColor = true; + this.ButtonUpdate.Click += new System.EventHandler(this.UpdateButton_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(493, 29); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(115, 52); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(493, 105); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(115, 52); + this.buttonUpd.TabIndex = 4; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ChangeButton_Click); + // + // FormGenres + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(620, 372); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.ButtonUpdate); + this.Controls.Add(this.ButtonDelete); + this.Controls.Add(this.DataGridView); + this.Name = "FormGenres"; + this.Text = "Жанры"; + this.Load += new System.EventHandler(this.FormGenres_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button ButtonDelete; + private Button ButtonUpdate; + private Button buttonAdd; + private Button buttonUpd; + } +} diff --git a/BookShop/BookShopView/FormGenres.cs b/BookShop/BookShopView/FormGenres.cs new file mode 100644 index 0000000..ed3f78f --- /dev/null +++ b/BookShop/BookShopView/FormGenres.cs @@ -0,0 +1,119 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormGenres : Form + { + private readonly ILogger _logger; + private readonly IGenreLogic _logic; + public FormGenres(ILogger logger, IGenreLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGenre)); + if (service is FormGenre form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + _logger.LogInformation("Удаление жанра"); + + try + { + if (!_logic.Delete(new GenreBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления жанра"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormGenres_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["GenreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка жанров"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки жанров"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGenre)); + if (service is FormGenre form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } +} diff --git a/BookShop/BookShopView/FormGenres.resx b/BookShop/BookShopView/FormGenres.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormGenres.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormMain.Designer.cs b/BookShop/BookShopView/FormMain.Designer.cs new file mode 100644 index 0000000..bd57b43 --- /dev/null +++ b/BookShop/BookShopView/FormMain.Designer.cs @@ -0,0 +1,191 @@ +namespace BookShopView +{ + 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() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.AuthorsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.BooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ClientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.GenresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ComponentGiftsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.OrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.testsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1367, 28); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.AuthorsToolStripMenuItem, + this.BooksToolStripMenuItem, + this.ClientsToolStripMenuItem, + this.GenresToolStripMenuItem, + this.testsToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // AuthorsToolStripMenuItem + // + this.AuthorsToolStripMenuItem.Name = "AuthorsToolStripMenuItem"; + this.AuthorsToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.AuthorsToolStripMenuItem.Text = "Авторы"; + this.AuthorsToolStripMenuItem.Click += new System.EventHandler(this.AuthorsToolStripMenuItem_Click); + // + // BooksToolStripMenuItem + // + this.BooksToolStripMenuItem.Name = "BooksToolStripMenuItem"; + this.BooksToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.BooksToolStripMenuItem.Text = "Книги"; + this.BooksToolStripMenuItem.Click += new System.EventHandler(this.BooksToolStripMenuItem_Click); + // + // ClientsToolStripMenuItem + // + this.ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + this.ClientsToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.ClientsToolStripMenuItem.Text = "Клиенты"; + this.ClientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); + // + // GenresToolStripMenuItem + // + this.GenresToolStripMenuItem.Name = "GenresToolStripMenuItem"; + this.GenresToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.GenresToolStripMenuItem.Text = "Жанры"; + this.GenresToolStripMenuItem.Click += new System.EventHandler(this.GenresToolStripMenuItem_Click); + // + // ComponentsToolStripMenuItem + // + this.ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.ComponentsToolStripMenuItem.Text = "Список компонентов"; + // + // ComponentGiftsToolStripMenuItem + // + this.ComponentGiftsToolStripMenuItem.Name = "ComponentGiftsToolStripMenuItem"; + this.ComponentGiftsToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.ComponentGiftsToolStripMenuItem.Text = "Компоненты по изделиям"; + // + // OrdersToolStripMenuItem + // + this.OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; + this.OrdersToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.OrdersToolStripMenuItem.Text = "Список заказов"; + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 41); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(1123, 423); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(1155, 167); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(189, 78); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(1155, 304); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(189, 78); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + // + // testsToolStripMenuItem + // + this.testsToolStripMenuItem.Name = "testsToolStripMenuItem"; + this.testsToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.testsToolStripMenuItem.Text = "Тесты"; + this.testsToolStripMenuItem.Click += new System.EventHandler(this.testsToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1367, 471); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Книжный магазин"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem AuthorsToolStripMenuItem; + private ToolStripMenuItem BooksToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonRef; + private ToolStripMenuItem ComponentsToolStripMenuItem; + private ToolStripMenuItem ComponentGiftsToolStripMenuItem; + private ToolStripMenuItem OrdersToolStripMenuItem; + private ToolStripMenuItem ClientsToolStripMenuItem; + private ToolStripMenuItem GenresToolStripMenuItem; + private ToolStripMenuItem testsToolStripMenuItem; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormMain.cs b/BookShop/BookShopView/FormMain.cs new file mode 100644 index 0000000..02e26c1 --- /dev/null +++ b/BookShop/BookShopView/FormMain.cs @@ -0,0 +1,111 @@ +using BookShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["BookId"].Visible = false; + dataGridView.Columns["BookName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ClientSurname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Count"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Sum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DateCreate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AuthorsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAuthors)); + if (service is FormAuthors form) + { + form.ShowDialog(); + } + } + private void GenresToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGenres)); + + if (service is FormGenres form) + { + form.ShowDialog(); + } + } + private void BooksToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBooks)); + + if (service is FormBooks form) + { + form.ShowDialog(); + } + } + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + + if (service is FormClients form) + { + form.ShowDialog(); + } + } + + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormСreateOrder)); + if (service is FormСreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void testsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTests)); + + if (service is FormTests form) + { + form.ShowDialog(); + } + } + } +} diff --git a/BookShop/BookShopView/FormMain.resx b/BookShop/BookShopView/FormMain.resx new file mode 100644 index 0000000..bcd95f7 --- /dev/null +++ b/BookShop/BookShopView/FormMain.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + + 36 + + \ No newline at end of file diff --git a/BookShop/BookShopView/FormTests.Designer.cs b/BookShop/BookShopView/FormTests.Designer.cs new file mode 100644 index 0000000..7b6125d --- /dev/null +++ b/BookShop/BookShopView/FormTests.Designer.cs @@ -0,0 +1,238 @@ +namespace BookShopView +{ + partial class FormTests + { + /// + /// 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.buttonInsertTest = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxInsertTime = new System.Windows.Forms.TextBox(); + this.buttonReadTest = new System.Windows.Forms.Button(); + this.textBoxReadTime = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownRead = new System.Windows.Forms.NumericUpDown(); + this.buttonJoinQuery = new System.Windows.Forms.Button(); + this.numericUpDownJoin = new System.Windows.Forms.NumericUpDown(); + this.textBoxJoin = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).BeginInit(); + this.SuspendLayout(); + // + // buttonInsertTest + // + this.buttonInsertTest.Location = new System.Drawing.Point(14, 16); + this.buttonInsertTest.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonInsertTest.Name = "buttonInsertTest"; + this.buttonInsertTest.Size = new System.Drawing.Size(98, 81); + this.buttonInsertTest.TabIndex = 0; + this.buttonInsertTest.Text = "Тест вставки сообщений"; + this.buttonInsertTest.UseVisualStyleBackColor = true; + this.buttonInsertTest.Click += new System.EventHandler(this.buttonInsertTest_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(119, 16); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(197, 20); + this.label1.TabIndex = 1; + this.label1.Text = "Введите кол-во элементов:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(119, 71); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(187, 20); + this.label2.TabIndex = 3; + this.label2.Text = "Итоговое время запроса:"; + // + // textBoxInsertTime + // + this.textBoxInsertTime.Location = new System.Drawing.Point(334, 68); + this.textBoxInsertTime.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxInsertTime.Name = "textBoxInsertTime"; + this.textBoxInsertTime.ReadOnly = true; + this.textBoxInsertTime.Size = new System.Drawing.Size(114, 27); + this.textBoxInsertTime.TabIndex = 4; + // + // buttonReadTest + // + this.buttonReadTest.Location = new System.Drawing.Point(14, 141); + this.buttonReadTest.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonReadTest.Name = "buttonReadTest"; + this.buttonReadTest.Size = new System.Drawing.Size(98, 75); + this.buttonReadTest.TabIndex = 5; + this.buttonReadTest.Text = "Тест чтения сообщений"; + this.buttonReadTest.UseVisualStyleBackColor = true; + this.buttonReadTest.Click += new System.EventHandler(this.buttonReadTest_Click); + // + // textBoxReadTime + // + this.textBoxReadTime.Location = new System.Drawing.Point(334, 193); + this.textBoxReadTime.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxReadTime.Name = "textBoxReadTime"; + this.textBoxReadTime.ReadOnly = true; + this.textBoxReadTime.Size = new System.Drawing.Size(114, 27); + this.textBoxReadTime.TabIndex = 9; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(119, 196); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(187, 20); + this.label3.TabIndex = 8; + this.label3.Text = "Итоговое время запроса:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(119, 141); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(197, 20); + this.label4.TabIndex = 6; + this.label4.Text = "Введите кол-во элементов:"; + // + // numericUpDownInsert + // + this.numericUpDownInsert.Location = new System.Drawing.Point(334, 16); + this.numericUpDownInsert.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.numericUpDownInsert.Name = "numericUpDownInsert"; + this.numericUpDownInsert.Size = new System.Drawing.Size(114, 27); + this.numericUpDownInsert.TabIndex = 10; + // + // numericUpDownRead + // + this.numericUpDownRead.Location = new System.Drawing.Point(334, 139); + this.numericUpDownRead.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.numericUpDownRead.Name = "numericUpDownRead"; + this.numericUpDownRead.Size = new System.Drawing.Size(114, 27); + this.numericUpDownRead.TabIndex = 11; + // + // buttonJoinQuery + // + this.buttonJoinQuery.Location = new System.Drawing.Point(14, 263); + this.buttonJoinQuery.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonJoinQuery.Name = "buttonJoinQuery"; + this.buttonJoinQuery.Size = new System.Drawing.Size(98, 99); + this.buttonJoinQuery.TabIndex = 12; + this.buttonJoinQuery.Text = "Тест сложного чтения (Join)"; + this.buttonJoinQuery.UseVisualStyleBackColor = true; + this.buttonJoinQuery.Click += new System.EventHandler(this.buttonJoinQuery_Click); + // + // numericUpDownJoin + // + this.numericUpDownJoin.Location = new System.Drawing.Point(334, 256); + this.numericUpDownJoin.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.numericUpDownJoin.Name = "numericUpDownJoin"; + this.numericUpDownJoin.Size = new System.Drawing.Size(114, 27); + this.numericUpDownJoin.TabIndex = 16; + // + // textBoxJoin + // + this.textBoxJoin.Location = new System.Drawing.Point(334, 314); + this.textBoxJoin.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxJoin.Name = "textBoxJoin"; + this.textBoxJoin.ReadOnly = true; + this.textBoxJoin.Size = new System.Drawing.Size(114, 27); + this.textBoxJoin.TabIndex = 15; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(119, 317); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(187, 20); + this.label5.TabIndex = 14; + this.label5.Text = "Итоговое время запроса:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(119, 263); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(197, 20); + this.label6.TabIndex = 13; + this.label6.Text = "Введите кол-во элементов:"; + // + // FormTests + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(553, 381); + this.Controls.Add(this.numericUpDownJoin); + this.Controls.Add(this.textBoxJoin); + this.Controls.Add(this.label5); + this.Controls.Add(this.label6); + this.Controls.Add(this.buttonJoinQuery); + this.Controls.Add(this.numericUpDownRead); + this.Controls.Add(this.numericUpDownInsert); + this.Controls.Add(this.textBoxReadTime); + this.Controls.Add(this.label3); + this.Controls.Add(this.label4); + this.Controls.Add(this.buttonReadTest); + this.Controls.Add(this.textBoxInsertTime); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonInsertTest); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormTests"; + this.Text = "Тесты запросов к бд"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonInsertTest; + private Label label1; + private Label label2; + private TextBox textBoxInsertTime; + private Button buttonReadTest; + private TextBox textBoxReadTime; + private Label label3; + private Label label4; + private NumericUpDown numericUpDownInsert; + private NumericUpDown numericUpDownRead; + private Button buttonJoinQuery; + private NumericUpDown numericUpDownJoin; + private TextBox textBoxJoin; + private Label label5; + private Label label6; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormTests.cs b/BookShop/BookShopView/FormTests.cs new file mode 100644 index 0000000..efc4e95 --- /dev/null +++ b/BookShop/BookShopView/FormTests.cs @@ -0,0 +1,75 @@ +using BookShopContracts.BusinessLogicsContracts; +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 BookShopView +{ + public partial class FormTests : Form + { + private readonly IBookLogic _bookLogic; + //private readonly IUserLogic _userLogic; + //private readonly ITopicLogic _topicLogic; + public FormTests(IBookLogic routeLogic)//IUserLogic userLogic, ITopicLogic topicLogic, IMessageLogic messageLogic) + { + InitializeComponent(); + //_userLogic = userLogic; + //_topicLogic = topicLogic; + _bookLogic = routeLogic; + numericUpDownInsert.Minimum = 0; + numericUpDownInsert.Maximum = 1000000; + numericUpDownRead.Minimum = 0; + numericUpDownRead.Maximum = 1000000; + numericUpDownJoin.Minimum = 0; + numericUpDownJoin.Maximum = 1000000; + } + + private void buttonInsertTest_Click(object sender, EventArgs e) + { + //try + //{ + // var result = _messageLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value), + // _userLogic.ReadList(null) ?? new(), + // _topicLogic.ReadList(null) ?? new()); + + // textBoxInsertTime.Text = result; + //} + //catch (Exception ex) + //{ + // MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + //} + } + + private void buttonReadTest_Click(object sender, EventArgs e) + { + try + { + var result = _bookLogic.TestReadList(Convert.ToInt32(numericUpDownRead.Value)); + textBoxReadTime.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonJoinQuery_Click(object sender, EventArgs e) + { + //try + //{ + // var result = _messageLogic.TestJoinReadList(Convert.ToInt32(numericUpDownJoin.Value)); + // textBoxJoin.Text = result; + //} + //catch (Exception ex) + //{ + // MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + //} + } + } +} diff --git a/BookShop/BookShopView/FormTests.resx b/BookShop/BookShopView/FormTests.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormTests.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/FormСreateOrder.Designer.cs b/BookShop/BookShopView/FormСreateOrder.Designer.cs new file mode 100644 index 0000000..fd7172b --- /dev/null +++ b/BookShop/BookShopView/FormСreateOrder.Designer.cs @@ -0,0 +1,170 @@ +namespace BookShopView +{ + partial class FormСreateOrder + { + /// + /// 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.labelBook = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxBook = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxClient = new System.Windows.Forms.ComboBox(); + this.labelClient = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // labelBook + // + this.labelBook.AutoSize = true; + this.labelBook.Location = new System.Drawing.Point(31, 44); + this.labelBook.Name = "labelBook"; + this.labelBook.Size = new System.Drawing.Size(50, 20); + this.labelBook.TabIndex = 0; + this.labelBook.Text = "Книга"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(31, 128); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(34, 178); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(55, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма"; + // + // comboBoxBook + // + this.comboBoxBook.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxBook.FormattingEnabled = true; + this.comboBoxBook.Location = new System.Drawing.Point(141, 41); + this.comboBoxBook.Name = "comboBoxBook"; + this.comboBoxBook.Size = new System.Drawing.Size(369, 28); + this.comboBoxBook.TabIndex = 3; + this.comboBoxBook.SelectedIndexChanged += new System.EventHandler(this.ComboBoxBook_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(141, 125); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(369, 27); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(141, 171); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(369, 27); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(82, 232); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(110, 58); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(366, 232); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(110, 58); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxClient + // + this.comboBoxClient.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxClient.FormattingEnabled = true; + this.comboBoxClient.Location = new System.Drawing.Point(141, 85); + this.comboBoxClient.Name = "comboBoxClient"; + this.comboBoxClient.Size = new System.Drawing.Size(369, 28); + this.comboBoxClient.TabIndex = 9; + // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(31, 88); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(58, 20); + this.labelClient.TabIndex = 8; + this.labelClient.Text = "Клиент"; + // + // FormСreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(539, 308); + this.Controls.Add(this.comboBoxClient); + this.Controls.Add(this.labelClient); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxBook); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelBook); + this.Name = "FormСreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelBook; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxBook; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxClient; + private Label labelClient; + } +} \ No newline at end of file diff --git a/BookShop/BookShopView/FormСreateOrder.cs b/BookShop/BookShopView/FormСreateOrder.cs new file mode 100644 index 0000000..e627c84 --- /dev/null +++ b/BookShop/BookShopView/FormСreateOrder.cs @@ -0,0 +1,153 @@ +using BookShopContracts.BindingModels; +using BookShopContracts.BusinessLogicsContracts; +using BookShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +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 BookShopView +{ + public partial class FormСreateOrder : Form + { + private readonly ILogger _logger; + private readonly IBookLogic _logicB; + private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; + public FormСreateOrder(ILogger logger, IBookLogic logicB, IOrderLogic logicO, IClientLogic logicC) + { + InitializeComponent(); + _logger = logger; + _logicB = logicB; + _logicO = logicO; + _logicC = logicC; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка книг для заказа"); + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка книг для заказа"); + try + { + var list = _logicB.ReadList(null); + if (list != null) + { + comboBoxBook.DisplayMember = "BookName"; + comboBoxBook.ValueMember = "ID"; + comboBoxBook.DataSource = list; + comboBoxBook.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка книг"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "Клиент"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list.Select(c => c.ClientSurname).ToList(); + comboBoxClient.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxBook.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxBook.SelectedValue); + var product = _logicB.ReadElement(new BookSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Cost ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxBook_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxBook.SelectedValue == null) + { + MessageBox.Show("Выберите книгу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.Create(new OrderBindingModel + { + BookId = Convert.ToInt32(comboBoxBook.SelectedValue), + BookName = comboBoxBook.Text, + ClientId = comboBoxClient.SelectedIndex + 1, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BookShop/BookShopView/FormСreateOrder.resx b/BookShop/BookShopView/FormСreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BookShop/BookShopView/FormСreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BookShop/BookShopView/Program.cs b/BookShop/BookShopView/Program.cs index f60ba3b..3bbada3 100644 --- a/BookShop/BookShopView/Program.cs +++ b/BookShop/BookShopView/Program.cs @@ -1,17 +1,64 @@ +using BookShopBusinessLogic.BusinessLogics; +using BookShopContracts.BusinessLogicsContracts; +using BookShopContracts.StoragesContracts; +using BookShopDataBaseImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + namespace BookShopView { - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +}