From d878a6a73f2aedd86df399101f1c0f55f88de817 Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Fri, 20 Dec 2024 11:46:58 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectLibrary/Entites/Book.cs | 7 ++++++ ProjectLibrary/Entites/Book_Orders.cs | 6 +++++ ProjectLibrary/Entites/Book_library.cs | 8 ++++++- ProjectLibrary/Entites/Library.cs | 5 ++++ ProjectLibrary/Entites/Orders.cs | 7 ++++++ ProjectLibrary/Entites/Reader.cs | 10 +++++++- ProjectLibrary/Entites/TempBookOrders.cs | 11 +++++++++ ProjectLibrary/Entites/Ticket_Extension.cs | 10 +++++++- ProjectLibrary/Reports/ChartReport.cs | 6 ++--- ProjectLibrary/Reports/TableReport.cs | 28 +++++++++++----------- 10 files changed, 78 insertions(+), 20 deletions(-) diff --git a/ProjectLibrary/Entites/Book.cs b/ProjectLibrary/Entites/Book.cs index 7204483..bc146db 100644 --- a/ProjectLibrary/Entites/Book.cs +++ b/ProjectLibrary/Entites/Book.cs @@ -1,12 +1,19 @@ namespace ProjectLibrary.Entities { using ProjectLibrary.Entities.Enums; + using System.ComponentModel; public class Book { public int Id { get; private set; } + + [DisplayName("Автор")] public string Author { get; private set; } = string.Empty; + + [DisplayName("Назвние книги")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Тип книги")] public BookType TypeBookID { get; set; } = BookType.None; public static Book CreateEntity(int id, string author, string name, BookType typeBookID = BookType.None) diff --git a/ProjectLibrary/Entites/Book_Orders.cs b/ProjectLibrary/Entites/Book_Orders.cs index 9b6f030..49274da 100644 --- a/ProjectLibrary/Entites/Book_Orders.cs +++ b/ProjectLibrary/Entites/Book_Orders.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,8 +9,13 @@ namespace ProjectLibrary.Entites { public class Book_Orders { + [Browsable(false)] public int BookID { get; private set; } + + [Browsable(false)] public int OrderID { get; private set; } + + [DisplayName("Количество")] public int Count { get; private set; } public static Book_Orders CreateEntity(int orderID,int bookID, int count ) diff --git a/ProjectLibrary/Entites/Book_library.cs b/ProjectLibrary/Entites/Book_library.cs index 5c08041..f79ca6c 100644 --- a/ProjectLibrary/Entites/Book_library.cs +++ b/ProjectLibrary/Entites/Book_library.cs @@ -1,9 +1,15 @@ -namespace ProjectLibrary.Entites +using System.ComponentModel; + +namespace ProjectLibrary.Entites { public class Book_Library { + [Browsable(false)] public int BookID { get; private set; } + + [Browsable(false)] public int LibraryID { get; private set; } + [DisplayName("Количество")] public int Count { get; private set; } public static Book_Library CreateEntity(int libraryID, int bookID, int count) diff --git a/ProjectLibrary/Entites/Library.cs b/ProjectLibrary/Entites/Library.cs index 07c629c..843757a 100644 --- a/ProjectLibrary/Entites/Library.cs +++ b/ProjectLibrary/Entites/Library.cs @@ -1,6 +1,7 @@ using ProjectLibrary.Forms; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,7 +11,11 @@ namespace ProjectLibrary.Entites public class Library { public int Id { get; private set; } + + [DisplayName("Название")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Адрес")] public string Address { get; private set; } = string.Empty; public IEnumerable BookLibrary { diff --git a/ProjectLibrary/Entites/Orders.cs b/ProjectLibrary/Entites/Orders.cs index 03f05db..53f338f 100644 --- a/ProjectLibrary/Entites/Orders.cs +++ b/ProjectLibrary/Entites/Orders.cs @@ -3,6 +3,7 @@ using Microsoft.VisualBasic; using ProjectLibrary.Entities; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,8 +13,14 @@ namespace ProjectLibrary.Entites public class Orders { public int Id { get; private set; } + + [DisplayName("Дата с")] public DateTime OrderDate { get; private set; } + + [DisplayName("Дата по")] public DateTime ReturnDate { get; private set; } + + [Browsable(false)] public int ReaderID { get; private set; } public IEnumerable BookOrders { diff --git a/ProjectLibrary/Entites/Reader.cs b/ProjectLibrary/Entites/Reader.cs index c46b5af..6ffa6d7 100644 --- a/ProjectLibrary/Entites/Reader.cs +++ b/ProjectLibrary/Entites/Reader.cs @@ -1,10 +1,18 @@ -namespace ProjectLibrary.Entities +using System.ComponentModel; + +namespace ProjectLibrary.Entities { public class Reader { public int Id { get; private set; } + + [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Читательский билет")] public int ReaderTicket { get; private set; } + + [DisplayName("Дата регистрации")] public DateTime RegistrationDateRT { get; private set; } // Изменение на DateTime public static Reader CreateEntity(int id, string name, int readerTicket) diff --git a/ProjectLibrary/Entites/TempBookOrders.cs b/ProjectLibrary/Entites/TempBookOrders.cs index 3597cd2..a41c941 100644 --- a/ProjectLibrary/Entites/TempBookOrders.cs +++ b/ProjectLibrary/Entites/TempBookOrders.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,10 +10,20 @@ namespace ProjectLibrary.Entites; public class TempBookOrders { public int Id { get; set; } + + [DisplayName("Дата заказа???")] public DateTime OrderDate { get; set; } + + [DisplayName("Дата исполнения???")] public DateTime ReturnDate { get; set; } + + [Browsable(false)] public int ReaderID { get; set; } + + [Browsable(false)] public int BookID { get; set; } + + [DisplayName("Количество")] public int Count { get; set; } diff --git a/ProjectLibrary/Entites/Ticket_Extension.cs b/ProjectLibrary/Entites/Ticket_Extension.cs index 331ace5..ae4c789 100644 --- a/ProjectLibrary/Entites/Ticket_Extension.cs +++ b/ProjectLibrary/Entites/Ticket_Extension.cs @@ -1,10 +1,18 @@ -namespace ProjectLibrary.Entites +using System.ComponentModel; + +namespace ProjectLibrary.Entites { public class TicketExtensions { public int Id { get; private set; } + + [Browsable(false)] public int ReaderID { get; private set; } + + [DisplayName("Последняя дата обновления")] public DateTime LastUpdateDate { get; private set; } + + [DisplayName("Следущая дата обновления")] public DateTime NextUpdateDate { get; private set; } public static TicketExtensions CreateEntity(int id, int readerID, DateTime lastUpdateDate, DateTime nextUpdateDate) diff --git a/ProjectLibrary/Reports/ChartReport.cs b/ProjectLibrary/Reports/ChartReport.cs index 1e0e893..54f58e7 100644 --- a/ProjectLibrary/Reports/ChartReport.cs +++ b/ProjectLibrary/Reports/ChartReport.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using DocumentFormat.OpenXml.Wordprocessing; +using Microsoft.Extensions.Logging; using ProjectLibrary.Repositories; using System; using System.Collections.Generic; @@ -37,8 +38,7 @@ public class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { return _orderRepository - .ReadOrders() - .Where(x => x.OrderDate.Date == dateTime.Date) + .ReadOrders(StartDate: startDate, EndDate: endDate) .GroupBy(x => x.BookOrders.First(y => y.OrderID == x.Id).BookID , (key, group) => new { ID = key, Count = group.Sum(y => y.BookOrders.First(z => z.OrderID == y.Id).Count) }) .Select(x => (x.ID.ToString(), (double)x.Count)) .ToList(); diff --git a/ProjectLibrary/Reports/TableReport.cs b/ProjectLibrary/Reports/TableReport.cs index 78e94eb..6e9d19b 100644 --- a/ProjectLibrary/Reports/TableReport.cs +++ b/ProjectLibrary/Reports/TableReport.cs @@ -13,7 +13,7 @@ public class TableReport { private readonly IOrderRepository _orderRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Id заказа","Дата заказа", "Дата возврата", "Книга", "Количество"]; + internal static readonly string[] item = ["Id заказа", "Книга", "Дата заказа", "Дата возврата", "Количество"]; public TableReport(IOrderRepository orderRepository, ILogger logger) @@ -28,7 +28,7 @@ public class TableReport { new ExcelBuilder(filePath) .AddHeader("Сводка по движению книг", 0, 5) - .AddParagraph("за период", 0) + .AddParagraph($"За период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}",0) .AddTable([10, 10, 10, 15, 15], GetData(startDate, endDate)) .Build(); return true; @@ -43,24 +43,24 @@ public class TableReport private List GetData(DateTime startDate, DateTime endDate) { var data = _orderRepository - .ReadOrders() - .Where(x => x.OrderDate >= startDate && x.OrderDate <= endDate && x.BookOrders.Any(y => y.OrderID == x.Id)) + .ReadOrders(StartDate: startDate, EndDate: endDate) .Select(x => new - { - x.Id, - DateOrder = x.OrderDate, - DateReturn = x.ReturnDate, - Book = (int?)x.BookOrders.First(y => y.OrderID == x.Id).BookID, - Count = (int?)x.BookOrders.First(y => y.OrderID == x.Id).Count - }) + { + x.Id, + DateOrder = x.OrderDate, + DateReturn = x.ReturnDate, + Book = (int?)x.BookOrders.First(y => y.OrderID == x.Id).BookID, + Count = (int?)x.BookOrders.First(y => y.OrderID == x.Id).Count + }) .OrderBy(x => x.DateOrder); return new List() { item } .Union( data - .Select(x => new string[] { x.Id.ToString(), x.DateOrder.ToString(), x.DateReturn.ToString(), - x.Book?.ToString() ?? string.Empty, x.Count?.ToString() ?? string.Empty})) - .Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString()]]) + .Select(x => new string[] { x.Id.ToString(), x.DateOrder.ToString("dd.MM.yyyy"), x.DateReturn.ToString("dd.MM.yyyy"), + x.Book?.ToString("N0") ?? string.Empty, x.Count?.ToString("N0") ?? string.Empty})) + .Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString("N0")]]) .ToList(); + //return null; } } -- 2.25.1 From 01a7cffa4ed55365cb5ed519abb9843f0a32a06a Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Fri, 20 Dec 2024 11:50:02 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=B7=D0=B0=D0=BB=D0=B8=D0=B2=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectLibrary/Forms/FBooks.cs | 1 + ProjectLibrary/Forms/FLibraries.cs | 1 + ProjectLibrary/Forms/FLibrary.cs | 2 +- ProjectLibrary/Forms/FOrder.cs | 2 +- ProjectLibrary/Forms/FOrders.cs | 3 +++ ProjectLibrary/Forms/FReaders.cs | 1 + ProjectLibrary/Forms/FTiclet_Extensions.cs | 3 +++ 7 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ProjectLibrary/Forms/FBooks.cs b/ProjectLibrary/Forms/FBooks.cs index 91e6c78..a4b82b6 100644 --- a/ProjectLibrary/Forms/FBooks.cs +++ b/ProjectLibrary/Forms/FBooks.cs @@ -20,6 +20,7 @@ namespace ProjectLibrary.Forms // Привязывает к DataGridView коллекцию книг, полученную из репозитория. // Устанавливает источник данных DataGridView (dataGridViewBooks) как список объектов из ReadBooks(). dataGridViewBooks.DataSource = _bookRepository.ReadBooks(); + dataGridViewBooks.Columns["Id"].Visible = false; } private bool TryGetIdentifierFromSelectedRow(out int id) diff --git a/ProjectLibrary/Forms/FLibraries.cs b/ProjectLibrary/Forms/FLibraries.cs index 499a120..3318dce 100644 --- a/ProjectLibrary/Forms/FLibraries.cs +++ b/ProjectLibrary/Forms/FLibraries.cs @@ -85,6 +85,7 @@ namespace ProjectLibrary.Forms private void LoadList() { dataGridViewOrders.DataSource = _libraryRepository.ReadLibraries(); + dataGridViewOrders.Columns["Id"].Visible = false; } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectLibrary/Forms/FLibrary.cs b/ProjectLibrary/Forms/FLibrary.cs index 8a3676a..20356bb 100644 --- a/ProjectLibrary/Forms/FLibrary.cs +++ b/ProjectLibrary/Forms/FLibrary.cs @@ -41,7 +41,7 @@ namespace ProjectLibrary.Forms _libraryRepository = libraryRepository ?? throw new ArgumentNullException(nameof(libraryRepository)); Book.DataSource = bookRepository.ReadBooks(); - Book.DisplayMember = "Name"; + Book.DisplayMember = "NameTypeBookID"; Book.ValueMember = "Id"; } diff --git a/ProjectLibrary/Forms/FOrder.cs b/ProjectLibrary/Forms/FOrder.cs index 7da78a2..35f567c 100644 --- a/ProjectLibrary/Forms/FOrder.cs +++ b/ProjectLibrary/Forms/FOrder.cs @@ -21,7 +21,7 @@ namespace ProjectLibrary.Forms comboBox.ValueMember = "Id"; Book.DataSource = bookRepository.ReadBooks(); - Book.DisplayMember = "Name"; + comboBox.DisplayMember = "NameTypeBookID"; Book.ValueMember = "Id"; } diff --git a/ProjectLibrary/Forms/FOrders.cs b/ProjectLibrary/Forms/FOrders.cs index e720877..49603e7 100644 --- a/ProjectLibrary/Forms/FOrders.cs +++ b/ProjectLibrary/Forms/FOrders.cs @@ -18,6 +18,9 @@ namespace ProjectLibrary.Forms private void LoadList() { dataGridViewOrders.DataSource = _orderRepository.ReadOrders(); + dataGridViewOrders.Columns["Id"].Visible = false; + dataGridViewOrders.Columns["OrderDate"].DefaultCellStyle.Format = "dd.MM.yyyy"; + dataGridViewOrders.Columns["ReturnDate"].DefaultCellStyle.Format = "dd.MM.yyyy"; } private void buttonAdd_Click(object sender, EventArgs e) diff --git a/ProjectLibrary/Forms/FReaders.cs b/ProjectLibrary/Forms/FReaders.cs index 4d8b770..42bff89 100644 --- a/ProjectLibrary/Forms/FReaders.cs +++ b/ProjectLibrary/Forms/FReaders.cs @@ -19,6 +19,7 @@ namespace ProjectLibrary.Forms private void LoadList() { dataGridViewReaders.DataSource = _readerRepository.ReadReaders(); + dataGridViewReaders.Columns["Id"].Visible = false; } private void FReaders_Load(object sender, EventArgs e) { diff --git a/ProjectLibrary/Forms/FTiclet_Extensions.cs b/ProjectLibrary/Forms/FTiclet_Extensions.cs index 858fec3..76f6be6 100644 --- a/ProjectLibrary/Forms/FTiclet_Extensions.cs +++ b/ProjectLibrary/Forms/FTiclet_Extensions.cs @@ -62,6 +62,9 @@ namespace ProjectLibrary.Forms private void LoadList() { dataGridView.DataSource = _ticketRepository.ReadTicketExtensions(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["LastUpdateDate"].DefaultCellStyle.Format = "dd MMMM yyyy"; + dataGridView.Columns["NextUpdateDate"].DefaultCellStyle.Format = "dd MMMM yyyy"; } private bool TryGetIdentifierFromSelectedRow(out int id) { -- 2.25.1 From d42bfcd0a3913281bb460d852c0ab5547dd9e9ea Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Fri, 20 Dec 2024 11:52:29 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=B7=D0=B0=D0=BB=D0=B8=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BF=D0=BA=D0=B8=20Repositores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositores/IOrderRepository.cs | 2 +- .../Implementations/LibraryRepository.cs | 29 +++++++++++-- .../Implementations/OrderRepository.cs | 42 +++++++++++++++---- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/ProjectLibrary/Repositores/IOrderRepository.cs b/ProjectLibrary/Repositores/IOrderRepository.cs index 0249e15..660cdc3 100644 --- a/ProjectLibrary/Repositores/IOrderRepository.cs +++ b/ProjectLibrary/Repositores/IOrderRepository.cs @@ -4,7 +4,7 @@ public interface IOrderRepository { - IEnumerable ReadOrders(); + IEnumerable ReadOrders(DateTime? StartDate = null, DateTime? EndDate = null); Orders ReadOrderById(int id); void CreateOrder(Orders order); void DeleteOrder(int id); diff --git a/ProjectLibrary/Repositores/Implementations/LibraryRepository.cs b/ProjectLibrary/Repositores/Implementations/LibraryRepository.cs index fccda71..d99e1fa 100644 --- a/ProjectLibrary/Repositores/Implementations/LibraryRepository.cs +++ b/ProjectLibrary/Repositores/Implementations/LibraryRepository.cs @@ -164,14 +164,35 @@ namespace ProjectLibrary.Repositories.Implementations public IEnumerable ReadLibraries() { _logger.LogInformation("Получение всех библиотек"); - + var builder = new QueryBuilder(); try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM Library"; - var libraries = connection.Query(querySelect); + var querySelect = @$"SELECT lbr.*, + bl.Bookid as Bookid, + bl.count + from library lbr + left join book_library bl on lbr.id = bl.libraryid {builder.Build()}"; + var BooksFromLibraryDict = new Dictionary>(); + + var libraries = connection.Query(querySelect, (libr, bookfromlib) => + { + if (!BooksFromLibraryDict.TryGetValue(libr.Id, out var booklibrer)) + { + booklibrer = []; + BooksFromLibraryDict.Add(libr.Id, booklibrer); + } + booklibrer.Add(bookfromlib); + return libr; + }, + splitOn: "Bookid", param: new { }); _logger.LogDebug("Полученные библиотеки: {json}", JsonConvert.SerializeObject(libraries)); - return libraries; + return BooksFromLibraryDict.Select(x => + { + var lbfb = libraries.First(y => y.Id == x.Key); + lbfb.SetLibraryForBook(x.Value); + return lbfb; + }).ToList(); } catch (Exception ex) { diff --git a/ProjectLibrary/Repositores/Implementations/OrderRepository.cs b/ProjectLibrary/Repositores/Implementations/OrderRepository.cs index b839c99..6d8e7e2 100644 --- a/ProjectLibrary/Repositores/Implementations/OrderRepository.cs +++ b/ProjectLibrary/Repositores/Implementations/OrderRepository.cs @@ -108,20 +108,48 @@ namespace ProjectLibrary.Repositories.Implementations } // Получение всех заказов - public IEnumerable ReadOrders() + public IEnumerable ReadOrders(DateTime? StartDate = null, DateTime? EndDate = null) { _logger.LogInformation("Получение всех объектов"); try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT ord.*, bo.BookId, bo.Count + var builder = new QueryBuilder(); + if(StartDate.HasValue) + { + builder.AddCollerction("ord.OrderDate >= @StartDate"); + } + + var querySelect = $@"SELECT ord.*, + Obo.BookId as bookid, + Obo.Count, + bk.Name FROM Orders ord - INNER JOIN Book_Orders bo ON bo.orderId = ord.Id"; - var order = connection.Query(querySelect); + INNER JOIN Book_Orders Obo ON Obo.orderId = ord.Id + Inner join book bk on bk.ID = obo.Bookid + {builder.Build()}"; + var OrderBookDict = new Dictionary>(); + + var order = connection + .Query(querySelect, (orders, books_orders) => + { + if (!OrderBookDict.TryGetValue(orders.Id, out var Book_Orders)) + { + Book_Orders = []; + OrderBookDict.Add(orders.Id, Book_Orders); + } + Book_Orders.Add(books_orders); + return orders; + }, + splitOn: "bookid", param: new { StartDate, EndDate }); + _logger.LogDebug("Получ енные объекты: {json}", JsonConvert.SerializeObject(order)); - return order.GroupBy(x => x.Id, y => y, - (key, value) => Orders.CreateEntity(value.First(), - value.Select(z => Book_Orders.CreateEntity(z.Id, z.BookID, z.Count)))).ToList(); + return OrderBookDict.Select(x => + { + var or = order.First(y => y.Id == x.Key); + or.SetOrdersOfBooks(x.Value); + return or; + }).ToArray(); } catch (Exception ex) { -- 2.25.1 From fd952b242a265ccad7a52fc0dbaa3e5640a75dc3 Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Fri, 20 Dec 2024 15:49:09 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D1=8D=D1=82=D0=BE=20=D1=82=D1=80=D1=8B?= =?UTF-8?q?=D0=BD=D0=B4=D0=B5=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectLibrary/Entites/Book.cs | 7 ++-- ProjectLibrary/Entites/Book_Orders.cs | 2 ++ ProjectLibrary/Entites/Library.cs | 16 ++++++++- ProjectLibrary/Entites/Orders.cs | 27 +++++++------- ProjectLibrary/Entites/QueryBuilder.cs | 35 +++++++++++++++++++ ProjectLibrary/Entites/Reader.cs | 2 +- ProjectLibrary/Entites/TempBookOrders.cs | 30 ---------------- ProjectLibrary/Entites/Ticket_Extension.cs | 2 +- ProjectLibrary/Reports/ChartReport.cs | 4 +-- ProjectLibrary/Reports/TableReport.cs | 26 +++++++------- .../Implementations/OrderRepository.cs | 8 ++--- 11 files changed, 94 insertions(+), 65 deletions(-) create mode 100644 ProjectLibrary/Entites/QueryBuilder.cs delete mode 100644 ProjectLibrary/Entites/TempBookOrders.cs diff --git a/ProjectLibrary/Entites/Book.cs b/ProjectLibrary/Entites/Book.cs index bc146db..607faa0 100644 --- a/ProjectLibrary/Entites/Book.cs +++ b/ProjectLibrary/Entites/Book.cs @@ -10,12 +10,15 @@ [DisplayName("Автор")] public string Author { get; private set; } = string.Empty; - [DisplayName("Назвние книги")] + [Browsable(false)] public string Name { get; private set; } = string.Empty; - [DisplayName("Тип книги")] + [Browsable(false)] public BookType TypeBookID { get; set; } = BookType.None; + [DisplayName("Название книги (жанр)")] + public string NameTypeBookID => $"{Name}({TypeBookID})"; + public static Book CreateEntity(int id, string author, string name, BookType typeBookID = BookType.None) { return new Book diff --git a/ProjectLibrary/Entites/Book_Orders.cs b/ProjectLibrary/Entites/Book_Orders.cs index 49274da..83876a2 100644 --- a/ProjectLibrary/Entites/Book_Orders.cs +++ b/ProjectLibrary/Entites/Book_Orders.cs @@ -18,6 +18,8 @@ namespace ProjectLibrary.Entites [DisplayName("Количество")] public int Count { get; private set; } + public string BookName { get; set; } + public static Book_Orders CreateEntity(int orderID,int bookID, int count ) { return new Book_Orders diff --git a/ProjectLibrary/Entites/Library.cs b/ProjectLibrary/Entites/Library.cs index 843757a..5bedc2a 100644 --- a/ProjectLibrary/Entites/Library.cs +++ b/ProjectLibrary/Entites/Library.cs @@ -14,15 +14,21 @@ namespace ProjectLibrary.Entites [DisplayName("Название")] public string Name { get; private set; } = string.Empty; - + [DisplayName("Адрес")] public string Address { get; private set; } = string.Empty; + + [Browsable(false)] public IEnumerable BookLibrary { get; private set; } + [DisplayName("Перечень книг в библиотеке")] + public string ListBookInLibrary => BookLibrary != null ? + string.Join("; ", BookLibrary.Select(x => $"{x.BookID},{x.Count}")): string.Empty; + public static Library CreateEntity(int id, string name, string address, IEnumerable bookLibrary) { return new Library @@ -33,5 +39,13 @@ namespace ProjectLibrary.Entites BookLibrary = bookLibrary }; } + + public void SetLibraryForBook(IEnumerable book_Library) + { + if (book_Library != null && book_Library.Any()) + { + BookLibrary = book_Library; + } + } } } diff --git a/ProjectLibrary/Entites/Orders.cs b/ProjectLibrary/Entites/Orders.cs index 53f338f..9aae524 100644 --- a/ProjectLibrary/Entites/Orders.cs +++ b/ProjectLibrary/Entites/Orders.cs @@ -14,20 +14,28 @@ namespace ProjectLibrary.Entites { public int Id { get; private set; } - [DisplayName("Дата с")] + [DisplayName("Дата взятия книги")] public DateTime OrderDate { get; private set; } - [DisplayName("Дата по")] + [DisplayName("Дата зврата книги")] public DateTime ReturnDate { get; private set; } - [Browsable(false)] + [DisplayName("Идентификационный номер читателя")] public int ReaderID { get; private set; } + + public string BookName { get; set; } + + [Browsable(false)] public IEnumerable BookOrders { get; private set; } = []; + [DisplayName("Отданные книги")] + public string BookOrdersing => BookOrders != null ? + string.Join(", ", BookOrders.Select(x => $"{x.BookID}{x.Count}")) : + string.Empty; public static Orders CreateEntity(int id, DateTime returnDate, int readerID, IEnumerable bookOrders) { @@ -40,17 +48,12 @@ namespace ProjectLibrary.Entites BookOrders = bookOrders }; } - - public static Orders CreateEntity(TempBookOrders tempBookOrders, IEnumerable bookOrders) + public void SetOrdersOfBooks(IEnumerable book_Orders) { - return new Orders + if (book_Orders != null && book_Orders.Any()) { - Id = tempBookOrders.Id, - OrderDate = tempBookOrders.OrderDate, - ReturnDate = tempBookOrders.ReturnDate, - ReaderID = tempBookOrders.ReaderID, - BookOrders = bookOrders - }; + BookOrders = book_Orders; + } } } } diff --git a/ProjectLibrary/Entites/QueryBuilder.cs b/ProjectLibrary/Entites/QueryBuilder.cs new file mode 100644 index 0000000..e6c898b --- /dev/null +++ b/ProjectLibrary/Entites/QueryBuilder.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectLibrary.Entites; + +internal class QueryBuilder +{ + private readonly StringBuilder _builder; + public QueryBuilder() + { + _builder = new(); + } + + public QueryBuilder AddCollerction(string condition) + { + if (_builder.Length > 0) + { + _builder.Append("AND"); + } + _builder.Append(condition); + return this; + } + + public string Build() + { + if (_builder.Length == 0) + { + return string.Empty; + } + return $"WHERE {_builder}"; + } +} diff --git a/ProjectLibrary/Entites/Reader.cs b/ProjectLibrary/Entites/Reader.cs index 6ffa6d7..23015da 100644 --- a/ProjectLibrary/Entites/Reader.cs +++ b/ProjectLibrary/Entites/Reader.cs @@ -6,7 +6,7 @@ namespace ProjectLibrary.Entities { public int Id { get; private set; } - [DisplayName("Имя")] + [DisplayName("ФИО")] public string Name { get; private set; } = string.Empty; [DisplayName("Читательский билет")] diff --git a/ProjectLibrary/Entites/TempBookOrders.cs b/ProjectLibrary/Entites/TempBookOrders.cs deleted file mode 100644 index a41c941..0000000 --- a/ProjectLibrary/Entites/TempBookOrders.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectLibrary.Entites; - -public class TempBookOrders -{ - public int Id { get; set; } - - [DisplayName("Дата заказа???")] - public DateTime OrderDate { get; set; } - - [DisplayName("Дата исполнения???")] - public DateTime ReturnDate { get; set; } - - [Browsable(false)] - public int ReaderID { get; set; } - - [Browsable(false)] - public int BookID { get; set; } - - [DisplayName("Количество")] - public int Count { get; set; } - - -} diff --git a/ProjectLibrary/Entites/Ticket_Extension.cs b/ProjectLibrary/Entites/Ticket_Extension.cs index ae4c789..21149f5 100644 --- a/ProjectLibrary/Entites/Ticket_Extension.cs +++ b/ProjectLibrary/Entites/Ticket_Extension.cs @@ -6,7 +6,7 @@ namespace ProjectLibrary.Entites { public int Id { get; private set; } - [Browsable(false)] + [DisplayName("Идентификационный номер читателя")] public int ReaderID { get; private set; } [DisplayName("Последняя дата обновления")] diff --git a/ProjectLibrary/Reports/ChartReport.cs b/ProjectLibrary/Reports/ChartReport.cs index 54f58e7..f9d2a6b 100644 --- a/ProjectLibrary/Reports/ChartReport.cs +++ b/ProjectLibrary/Reports/ChartReport.cs @@ -35,10 +35,10 @@ public class ChartReport } } - private List<(string Caption, double Value)> GetData(DateTime dateTime) + private List<(string Caption, double Value)> GetData(DateTime? dateTime = null) { return _orderRepository - .ReadOrders(StartDate: startDate, EndDate: endDate) + .ReadOrders() .GroupBy(x => x.BookOrders.First(y => y.OrderID == x.Id).BookID , (key, group) => new { ID = key, Count = group.Sum(y => y.BookOrders.First(z => z.OrderID == y.Id).Count) }) .Select(x => (x.ID.ToString(), (double)x.Count)) .ToList(); diff --git a/ProjectLibrary/Reports/TableReport.cs b/ProjectLibrary/Reports/TableReport.cs index 6e9d19b..545a174 100644 --- a/ProjectLibrary/Reports/TableReport.cs +++ b/ProjectLibrary/Reports/TableReport.cs @@ -13,7 +13,7 @@ public class TableReport { private readonly IOrderRepository _orderRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Id заказа", "Книга", "Дата заказа", "Дата возврата", "Количество"]; + internal static readonly string[] item = ["Id заказа", "Дата заказа", "Дата возврата","Книга", "Количество"]; public TableReport(IOrderRepository orderRepository, ILogger logger) @@ -22,7 +22,7 @@ public class TableReport _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } - public bool CreateTable(string filePath, DateTime startDate, DateTime endDate) + public bool CreateTable(string filePath, DateTime? startDate = null, DateTime? endDate = null) { try { @@ -40,25 +40,27 @@ public class TableReport } } - private List GetData(DateTime startDate, DateTime endDate) + private List GetData(DateTime? startDate = null, DateTime? endDate = null) { + //var s = _orderRepository + // .ReadOrders(StartDate: startDate, EndDate: endDate); var data = _orderRepository .ReadOrders(StartDate: startDate, EndDate: endDate) .Select(x => new - { - x.Id, - DateOrder = x.OrderDate, - DateReturn = x.ReturnDate, - Book = (int?)x.BookOrders.First(y => y.OrderID == x.Id).BookID, - Count = (int?)x.BookOrders.First(y => y.OrderID == x.Id).Count - }) - .OrderBy(x => x.DateOrder); + { + x.Id, + DateOrder = x.OrderDate, + DateReturn = x.ReturnDate, + Book = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.BookName, + Count = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.Count + }) + .OrderBy(x => x.Id); return new List() { item } .Union( data .Select(x => new string[] { x.Id.ToString(), x.DateOrder.ToString("dd.MM.yyyy"), x.DateReturn.ToString("dd.MM.yyyy"), - x.Book?.ToString("N0") ?? string.Empty, x.Count?.ToString("N0") ?? string.Empty})) + x.Book ?? string.Empty, x.Count?.ToString("N0") ?? string.Empty})) .Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString("N0")]]) .ToList(); //return null; diff --git a/ProjectLibrary/Repositores/Implementations/OrderRepository.cs b/ProjectLibrary/Repositores/Implementations/OrderRepository.cs index 6d8e7e2..090731f 100644 --- a/ProjectLibrary/Repositores/Implementations/OrderRepository.cs +++ b/ProjectLibrary/Repositores/Implementations/OrderRepository.cs @@ -118,12 +118,12 @@ namespace ProjectLibrary.Repositories.Implementations if(StartDate.HasValue) { builder.AddCollerction("ord.OrderDate >= @StartDate"); - } + } var querySelect = $@"SELECT ord.*, - Obo.BookId as bookid, - Obo.Count, - bk.Name + bk.Name as BookName, + Obo.bookid as bookid + FROM Orders ord INNER JOIN Book_Orders Obo ON Obo.orderId = ord.Id Inner join book bk on bk.ID = obo.Bookid -- 2.25.1 From f0df960fceeca9e4dffee94fab06cd33f5047d13 Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Sat, 21 Dec 2024 19:56:37 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=B0=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectLibrary/Entites/Orders.cs | 2 +- ProjectLibrary/Reports/TableReport.cs | 9 +++++---- .../Repositores/Implementations/OrderRepository.cs | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ProjectLibrary/Entites/Orders.cs b/ProjectLibrary/Entites/Orders.cs index 9aae524..c085586 100644 --- a/ProjectLibrary/Entites/Orders.cs +++ b/ProjectLibrary/Entites/Orders.cs @@ -34,7 +34,7 @@ namespace ProjectLibrary.Entites [DisplayName("Отданные книги")] public string BookOrdersing => BookOrders != null ? - string.Join(", ", BookOrders.Select(x => $"{x.BookID}{x.Count}")) : + string.Join(", ", BookOrders.Select(x => $"{x.BookID}({x.Count})")) : string.Empty; public static Orders CreateEntity(int id, DateTime returnDate, int readerID, IEnumerable bookOrders) diff --git a/ProjectLibrary/Reports/TableReport.cs b/ProjectLibrary/Reports/TableReport.cs index 545a174..d1a7624 100644 --- a/ProjectLibrary/Reports/TableReport.cs +++ b/ProjectLibrary/Reports/TableReport.cs @@ -42,8 +42,9 @@ public class TableReport private List GetData(DateTime? startDate = null, DateTime? endDate = null) { - //var s = _orderRepository - // .ReadOrders(StartDate: startDate, EndDate: endDate); + var s = _orderRepository + .ReadOrders(StartDate: startDate, EndDate: endDate); + var data = _orderRepository .ReadOrders(StartDate: startDate, EndDate: endDate) .Select(x => new @@ -51,7 +52,7 @@ public class TableReport x.Id, DateOrder = x.OrderDate, DateReturn = x.ReturnDate, - Book = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.BookName, + Book = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.BookID,//вот эти данные не вставляются в эксель Count = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.Count }) .OrderBy(x => x.Id); @@ -60,7 +61,7 @@ public class TableReport .Union( data .Select(x => new string[] { x.Id.ToString(), x.DateOrder.ToString("dd.MM.yyyy"), x.DateReturn.ToString("dd.MM.yyyy"), - x.Book ?? string.Empty, x.Count?.ToString("N0") ?? string.Empty})) + x.Book?.ToString("N0") ?? string.Empty, x.Count?.ToString("N0") ?? string.Empty})) .Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString("N0")]]) .ToList(); //return null; diff --git a/ProjectLibrary/Repositores/Implementations/OrderRepository.cs b/ProjectLibrary/Repositores/Implementations/OrderRepository.cs index 090731f..d8481f2 100644 --- a/ProjectLibrary/Repositores/Implementations/OrderRepository.cs +++ b/ProjectLibrary/Repositores/Implementations/OrderRepository.cs @@ -119,11 +119,13 @@ namespace ProjectLibrary.Repositories.Implementations { builder.AddCollerction("ord.OrderDate >= @StartDate"); } - + /*if (EndDate.HasValue) + { + builder.AddCollerction("ord.ReturnDate < @EndDate"); + }*/ var querySelect = $@"SELECT ord.*, bk.Name as BookName, Obo.bookid as bookid - FROM Orders ord INNER JOIN Book_Orders Obo ON Obo.orderId = ord.Id Inner join book bk on bk.ID = obo.Bookid -- 2.25.1 From c8c1ec5714525a0cbdde494c413057358789b7f2 Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Sat, 21 Dec 2024 20:33:17 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=AD=D0=A2=D0=9E=20=D0=9F=D0=9E=D0=91?= =?UTF-8?q?=D0=95=D0=94=D0=90=D0=90=D0=90=D0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectLibrary/Entites/Book_Orders.cs | 3 +-- ProjectLibrary/Entites/Book_library.cs | 2 -- ProjectLibrary/Forms/FBooks.Designer.cs | 27 ++++++++----------- ProjectLibrary/Forms/FBooks.resx | 4 +-- ProjectLibrary/Forms/FLibraries.Designer.cs | 27 +++++++++---------- ProjectLibrary/Forms/FLibraries.resx | 4 +-- .../FOrderDistributionReport.Designer.cs | 6 ++--- ProjectLibrary/Forms/FOrders.Designer.cs | 2 +- .../Forms/FTiclet_Extensions.Designer.cs | 22 +++++++-------- ProjectLibrary/Forms/FTiclet_Extensions.resx | 4 +-- ProjectLibrary/Reports/ChartReport.cs | 4 +-- ProjectLibrary/Reports/TableReport.cs | 7 ++--- .../Implementations/OrderRepository.cs | 7 ++--- 13 files changed, 52 insertions(+), 67 deletions(-) diff --git a/ProjectLibrary/Entites/Book_Orders.cs b/ProjectLibrary/Entites/Book_Orders.cs index 83876a2..5e14df2 100644 --- a/ProjectLibrary/Entites/Book_Orders.cs +++ b/ProjectLibrary/Entites/Book_Orders.cs @@ -9,10 +9,9 @@ namespace ProjectLibrary.Entites { public class Book_Orders { - [Browsable(false)] public int BookID { get; private set; } - [Browsable(false)] + public int OrderID { get; private set; } [DisplayName("Количество")] diff --git a/ProjectLibrary/Entites/Book_library.cs b/ProjectLibrary/Entites/Book_library.cs index f79ca6c..7806809 100644 --- a/ProjectLibrary/Entites/Book_library.cs +++ b/ProjectLibrary/Entites/Book_library.cs @@ -4,10 +4,8 @@ namespace ProjectLibrary.Entites { public class Book_Library { - [Browsable(false)] public int BookID { get; private set; } - [Browsable(false)] public int LibraryID { get; private set; } [DisplayName("Количество")] public int Count { get; private set; } diff --git a/ProjectLibrary/Forms/FBooks.Designer.cs b/ProjectLibrary/Forms/FBooks.Designer.cs index b11ed39..4359dd1 100644 --- a/ProjectLibrary/Forms/FBooks.Designer.cs +++ b/ProjectLibrary/Forms/FBooks.Designer.cs @@ -40,57 +40,52 @@ dataGridViewBooks.AllowUserToAddRows = false; dataGridViewBooks.AllowUserToDeleteRows = false; dataGridViewBooks.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewBooks.Location = new Point(10, 9); - dataGridViewBooks.Margin = new Padding(3, 2, 3, 2); + dataGridViewBooks.Location = new Point(11, 12); dataGridViewBooks.Name = "dataGridViewBooks"; dataGridViewBooks.ReadOnly = true; dataGridViewBooks.RowHeadersWidth = 51; dataGridViewBooks.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewBooks.Size = new Size(602, 254); + dataGridViewBooks.Size = new Size(688, 339); dataGridViewBooks.TabIndex = 8; // // buttonAdd // - buttonAdd.Location = new Point(27, 267); - buttonAdd.Margin = new Padding(3, 2, 3, 2); + buttonAdd.Location = new Point(31, 356); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(161, 37); + buttonAdd.Size = new Size(184, 49); buttonAdd.TabIndex = 9; buttonAdd.Text = "Добавить"; buttonAdd.Click += buttonAdd_Click; // // buttonUpdate // - buttonUpdate.Location = new Point(247, 267); - buttonUpdate.Margin = new Padding(3, 2, 3, 2); + buttonUpdate.Location = new Point(282, 356); buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(161, 37); + buttonUpdate.Size = new Size(184, 49); buttonUpdate.TabIndex = 10; buttonUpdate.Text = "Изменить"; buttonUpdate.Click += buttonUpdate_Click; // // buttonRemove // - buttonRemove.Location = new Point(452, 267); - buttonRemove.Margin = new Padding(3, 2, 3, 2); + buttonRemove.Location = new Point(517, 356); buttonRemove.Name = "buttonRemove"; - buttonRemove.Size = new Size(161, 37); + buttonRemove.Size = new Size(184, 49); buttonRemove.TabIndex = 11; buttonRemove.Text = "Удалить"; buttonRemove.Click += buttonRemove_Click; // // FBooks // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(700, 338); + ClientSize = new Size(800, 451); Controls.Add(dataGridViewBooks); Controls.Add(buttonAdd); Controls.Add(buttonUpdate); Controls.Add(buttonRemove); - Margin = new Padding(3, 2, 3, 2); Name = "FBooks"; - Text = "FBooks"; + Text = "Книги"; Load += FBooks_Load; ((System.ComponentModel.ISupportInitialize)dataGridViewBooks).EndInit(); ResumeLayout(false); diff --git a/ProjectLibrary/Forms/FBooks.resx b/ProjectLibrary/Forms/FBooks.resx index af32865..8b2ff64 100644 --- a/ProjectLibrary/Forms/FBooks.resx +++ b/ProjectLibrary/Forms/FBooks.resx @@ -1,7 +1,7 @@