From ce98df60608fde4e6fb2afe7ec58df4fe350967b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BA=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=A0=D0=BE=D0=B3=D0=B0=D1=88=D0=BE=D0=B2=D0=B0?= Date: Tue, 9 May 2023 10:42:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D1=81=D0=BE=D1=85=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=BA=D0=BD=D0=B8=D0=B3?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...er.cs => 20230509063637_InitialCreate.Designer.cs} | 2 +- ...itialCreate.cs => 20230509063637_InitialCreate.cs} | 0 BookShop/Models/Book.cs | 2 +- BookShopBusinessLogic/BusinessLogics/BookLogic.cs | 6 +++--- BookShopContracts/SearchModels/BookSearchModel.cs | 1 - BookShopContracts/ViewModels/BookViewModel.cs | 5 +++-- BookShopDataModels/Models/IBookModel.cs | 1 + BookShopView/FormBook.cs | 11 +++++++++-- BookShopView/FormBookAuthor.cs | 3 +-- BookShopView/FormBooks.Designer.cs | 1 + BookShopView/FormBooks.cs | 3 +++ 11 files changed, 23 insertions(+), 12 deletions(-) rename BookShop/Migrations/{20230508181531_InitialCreate.Designer.cs => 20230509063637_InitialCreate.Designer.cs} (99%) rename BookShop/Migrations/{20230508181531_InitialCreate.cs => 20230509063637_InitialCreate.cs} (100%) diff --git a/BookShop/Migrations/20230508181531_InitialCreate.Designer.cs b/BookShop/Migrations/20230509063637_InitialCreate.Designer.cs similarity index 99% rename from BookShop/Migrations/20230508181531_InitialCreate.Designer.cs rename to BookShop/Migrations/20230509063637_InitialCreate.Designer.cs index 50f76eb..9511544 100644 --- a/BookShop/Migrations/20230508181531_InitialCreate.Designer.cs +++ b/BookShop/Migrations/20230509063637_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BookShopDataBaseImplement.Migrations { [DbContext(typeof(BookShopDatabase))] - [Migration("20230508181531_InitialCreate")] + [Migration("20230509063637_InitialCreate")] partial class InitialCreate { /// diff --git a/BookShop/Migrations/20230508181531_InitialCreate.cs b/BookShop/Migrations/20230509063637_InitialCreate.cs similarity index 100% rename from BookShop/Migrations/20230508181531_InitialCreate.cs rename to BookShop/Migrations/20230509063637_InitialCreate.cs diff --git a/BookShop/Models/Book.cs b/BookShop/Models/Book.cs index 53729a6..9360932 100644 --- a/BookShop/Models/Book.cs +++ b/BookShop/Models/Book.cs @@ -23,7 +23,7 @@ namespace BookShopDataBaseImplement.Models public double Cost { get; set; } [Required] public int GenreId { get; set; } - public virtual Genre Genre { get; set; } + public virtual Genre Genre { get; set; } private Dictionary? _bookAuthors = null; [NotMapped] public Dictionary BookAuthors diff --git a/BookShopBusinessLogic/BusinessLogics/BookLogic.cs b/BookShopBusinessLogic/BusinessLogics/BookLogic.cs index fd7b0e9..63db28c 100644 --- a/BookShopBusinessLogic/BusinessLogics/BookLogic.cs +++ b/BookShopBusinessLogic/BusinessLogics/BookLogic.cs @@ -50,7 +50,7 @@ namespace BookShopBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. BookName: {BookName}. GenreId: {GenreId}. Id: {Id}.", model.BookName, model.GenreId, model.Id); + _logger.LogInformation("ReadElement. BookName: {BookName}. Id: {Id}.", model.BookName, model.Id); var element = _bookStorage.GetElement(model); if (element == null) { @@ -63,7 +63,7 @@ namespace BookShopBusinessLogic.BusinessLogics public List? ReadList(BookSearchModel? model) { - _logger.LogInformation("ReadList. BookName: {BookName}. GenreId: {GenreId}. Id: {Id}.", model?.BookName, model?.GenreId, model?.Id); + _logger.LogInformation("ReadList. BookName: {BookName}. Id: {Id}.", model?.BookName, model?.Id); var list = model == null ? _bookStorage.GetFullList() : _bookStorage.GetFilteredList(model); if (list == null) { @@ -107,7 +107,7 @@ namespace BookShopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Стоимость не может быть меньше 0", nameof(model.BookName)); } - _logger.LogInformation("Book. BookName: {BookName}. Count: {Count}. Cost: {Cost}. GenreId: {GenreId}. Id: {Id}.", model.BookName, model.Count, model.Cost, model.GenreId, model.Id); + _logger.LogInformation("Book. BookName: {BookName}. Cost: {Cost}. Id: {Id}.", model.BookName, model.Cost, model.Id); var element = _bookStorage.GetElement(new BookSearchModel { BookName = model.BookName diff --git a/BookShopContracts/SearchModels/BookSearchModel.cs b/BookShopContracts/SearchModels/BookSearchModel.cs index c5cc63a..f94bdab 100644 --- a/BookShopContracts/SearchModels/BookSearchModel.cs +++ b/BookShopContracts/SearchModels/BookSearchModel.cs @@ -10,6 +10,5 @@ namespace BookShopContracts.SearchModels { public int? Id { get; set; } public string? BookName { get; set; } - public int? GenreId { get; set; } } } diff --git a/BookShopContracts/ViewModels/BookViewModel.cs b/BookShopContracts/ViewModels/BookViewModel.cs index a599071..92c563d 100644 --- a/BookShopContracts/ViewModels/BookViewModel.cs +++ b/BookShopContracts/ViewModels/BookViewModel.cs @@ -11,12 +11,13 @@ namespace BookShopContracts.ViewModels public class BookViewModel: IBookModel { 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; } - [DisplayName("GenreName")] public string GenreName { get; set; } = string.Empty; - public Dictionary BookAuthors { get; set; } + public Dictionary BookAuthors { get; set; } = new(); } } diff --git a/BookShopDataModels/Models/IBookModel.cs b/BookShopDataModels/Models/IBookModel.cs index b95848d..e1502b9 100644 --- a/BookShopDataModels/Models/IBookModel.cs +++ b/BookShopDataModels/Models/IBookModel.cs @@ -12,5 +12,6 @@ namespace BookShopDataModels.Models double Cost { get; } int Count { get; } int GenreId { get; } + Dictionary BookAuthors { get; } } } diff --git a/BookShopView/FormBook.cs b/BookShopView/FormBook.cs index a571e6d..c713281 100644 --- a/BookShopView/FormBook.cs +++ b/BookShopView/FormBook.cs @@ -81,7 +81,6 @@ namespace BookShopView } private void LoadData() { - _logger.LogInformation("Загрузка автора книги"); try { @@ -112,6 +111,14 @@ namespace BookShopView { 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(); } @@ -185,7 +192,7 @@ namespace BookShopView MessageBoxIcon.Error); return; } - if (comboBoxGenre.SelectedValue == null) + if (comboBoxGenre.SelectedItem == null) { MessageBox.Show("Выберите жанр", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); diff --git a/BookShopView/FormBookAuthor.cs b/BookShopView/FormBookAuthor.cs index db7d6d5..abb4241 100644 --- a/BookShopView/FormBookAuthor.cs +++ b/BookShopView/FormBookAuthor.cs @@ -52,7 +52,6 @@ namespace BookShopView if (_list != null) { comboBoxAuthor.DisplayMember = "AuthorSurname"; - comboBoxAuthor.DisplayMember = "AuthorName"; comboBoxAuthor.ValueMember = "Id"; comboBoxAuthor.DataSource = _list; comboBoxAuthor.SelectedItem = null; @@ -62,7 +61,7 @@ namespace BookShopView { if (comboBoxAuthor.SelectedValue == null) { - MessageBox.Show("Выберите компонент", "Ошибка", + MessageBox.Show("Выберите автора", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } diff --git a/BookShopView/FormBooks.Designer.cs b/BookShopView/FormBooks.Designer.cs index 3b75a38..51967eb 100644 --- a/BookShopView/FormBooks.Designer.cs +++ b/BookShopView/FormBooks.Designer.cs @@ -96,6 +96,7 @@ 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); diff --git a/BookShopView/FormBooks.cs b/BookShopView/FormBooks.cs index 34ca15a..a3cc479 100644 --- a/BookShopView/FormBooks.cs +++ b/BookShopView/FormBooks.cs @@ -40,6 +40,9 @@ namespace BookShopView 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("Загрузка книг");