From fd952b242a265ccad7a52fc0dbaa3e5640a75dc3 Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Fri, 20 Dec 2024 15:49:09 +0400 Subject: [PATCH] =?UTF-8?q?=D1=8D=D1=82=D0=BE=20=D1=82=D1=80=D1=8B=D0=BD?= =?UTF-8?q?=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