это трындец

This commit is contained in:
Aleksandr4350 2024-12-20 15:49:09 +04:00
parent d42bfcd0a3
commit fd952b242a
11 changed files with 94 additions and 65 deletions

View File

@ -10,12 +10,15 @@
[DisplayName("Автор")] [DisplayName("Автор")]
public string Author { get; private set; } = string.Empty; public string Author { get; private set; } = string.Empty;
[DisplayName("Назвние книги")] [Browsable(false)]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[DisplayName("Тип книги")] [Browsable(false)]
public BookType TypeBookID { get; set; } = BookType.None; 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) public static Book CreateEntity(int id, string author, string name, BookType typeBookID = BookType.None)
{ {
return new Book return new Book

View File

@ -18,6 +18,8 @@ namespace ProjectLibrary.Entites
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; private set; } public int Count { get; private set; }
public string BookName { get; set; }
public static Book_Orders CreateEntity(int orderID,int bookID, int count ) public static Book_Orders CreateEntity(int orderID,int bookID, int count )
{ {
return new Book_Orders return new Book_Orders

View File

@ -17,12 +17,18 @@ namespace ProjectLibrary.Entites
[DisplayName("Адрес")] [DisplayName("Адрес")]
public string Address { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty;
[Browsable(false)]
public IEnumerable<Book_Library> BookLibrary public IEnumerable<Book_Library> BookLibrary
{ {
get; get;
private set; 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<Book_Library> bookLibrary) public static Library CreateEntity(int id, string name, string address, IEnumerable<Book_Library> bookLibrary)
{ {
return new Library return new Library
@ -33,5 +39,13 @@ namespace ProjectLibrary.Entites
BookLibrary = bookLibrary BookLibrary = bookLibrary
}; };
} }
public void SetLibraryForBook(IEnumerable<Book_Library> book_Library)
{
if (book_Library != null && book_Library.Any())
{
BookLibrary = book_Library;
}
}
} }
} }

View File

@ -14,20 +14,28 @@ namespace ProjectLibrary.Entites
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Дата с")] [DisplayName("Дата взятия книги")]
public DateTime OrderDate { get; private set; } public DateTime OrderDate { get; private set; }
[DisplayName("Дата по")] [DisplayName("Дата зврата книги")]
public DateTime ReturnDate { get; private set; } public DateTime ReturnDate { get; private set; }
[Browsable(false)] [DisplayName("Идентификационный номер читателя")]
public int ReaderID { get; private set; } public int ReaderID { get; private set; }
public string BookName { get; set; }
[Browsable(false)]
public IEnumerable<Book_Orders> BookOrders public IEnumerable<Book_Orders> BookOrders
{ {
get; get;
private set; 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<Book_Orders> bookOrders) public static Orders CreateEntity(int id, DateTime returnDate, int readerID, IEnumerable<Book_Orders> bookOrders)
{ {
@ -40,17 +48,12 @@ namespace ProjectLibrary.Entites
BookOrders = bookOrders BookOrders = bookOrders
}; };
} }
public void SetOrdersOfBooks(IEnumerable<Book_Orders> book_Orders)
public static Orders CreateEntity(TempBookOrders tempBookOrders, IEnumerable<Book_Orders> bookOrders)
{ {
return new Orders if (book_Orders != null && book_Orders.Any())
{ {
Id = tempBookOrders.Id, BookOrders = book_Orders;
OrderDate = tempBookOrders.OrderDate, }
ReturnDate = tempBookOrders.ReturnDate,
ReaderID = tempBookOrders.ReaderID,
BookOrders = bookOrders
};
} }
} }
} }

View File

@ -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}";
}
}

View File

@ -6,7 +6,7 @@ namespace ProjectLibrary.Entities
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Имя")] [DisplayName("ФИО")]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[DisplayName("Читательский билет")] [DisplayName("Читательский билет")]

View File

@ -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; }
}

View File

@ -6,7 +6,7 @@ namespace ProjectLibrary.Entites
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)] [DisplayName("Идентификационный номер читателя")]
public int ReaderID { get; private set; } public int ReaderID { get; private set; }
[DisplayName("Последняя дата обновления")] [DisplayName("Последняя дата обновления")]

View File

@ -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 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) }) .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)) .Select(x => (x.ID.ToString(), (double)x.Count))
.ToList(); .ToList();

View File

@ -13,7 +13,7 @@ public class TableReport
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly ILogger<TableReport> _logger; private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Id заказа", "Книга", "Дата заказа", "Дата возврата", "Количество"]; internal static readonly string[] item = ["Id заказа", "Дата заказа", "Дата возврата","Книга", "Количество"];
public TableReport(IOrderRepository orderRepository, ILogger<TableReport> logger) public TableReport(IOrderRepository orderRepository, ILogger<TableReport> logger)
@ -22,7 +22,7 @@ public class TableReport
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _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 try
{ {
@ -40,8 +40,10 @@ public class TableReport
} }
} }
private List<string[]> GetData(DateTime startDate, DateTime endDate) private List<string[]> GetData(DateTime? startDate = null, DateTime? endDate = null)
{ {
//var s = _orderRepository
// .ReadOrders(StartDate: startDate, EndDate: endDate);
var data = _orderRepository var data = _orderRepository
.ReadOrders(StartDate: startDate, EndDate: endDate) .ReadOrders(StartDate: startDate, EndDate: endDate)
.Select(x => new .Select(x => new
@ -49,16 +51,16 @@ public class TableReport
x.Id, x.Id,
DateOrder = x.OrderDate, DateOrder = x.OrderDate,
DateReturn = x.ReturnDate, DateReturn = x.ReturnDate,
Book = (int?)x.BookOrders.First(y => y.OrderID == x.Id).BookID, Book = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.BookName,
Count = (int?)x.BookOrders.First(y => y.OrderID == x.Id).Count Count = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.Count
}) })
.OrderBy(x => x.DateOrder); .OrderBy(x => x.Id);
return return
new List<string[]>() { item } new List<string[]>() { item }
.Union( .Union(
data data
.Select(x => new string[] { x.Id.ToString(), x.DateOrder.ToString("dd.MM.yyyy"), x.DateReturn.ToString("dd.MM.yyyy"), .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")]]) .Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString("N0")]])
.ToList(); .ToList();
//return null; //return null;

View File

@ -121,9 +121,9 @@ namespace ProjectLibrary.Repositories.Implementations
} }
var querySelect = $@"SELECT ord.*, var querySelect = $@"SELECT ord.*,
Obo.BookId as bookid, bk.Name as BookName,
Obo.Count, Obo.bookid as bookid
bk.Name
FROM Orders ord FROM Orders ord
INNER JOIN Book_Orders Obo ON Obo.orderId = ord.Id INNER JOIN Book_Orders Obo ON Obo.orderId = ord.Id
Inner join book bk on bk.ID = obo.Bookid Inner join book bk on bk.ID = obo.Bookid