Labwork_4 ИСЭбд-21 Мосевнин А. #5

Closed
Aleks_andr435 wants to merge 7 commits from Labwork_4 into Labwork_3
30 changed files with 265 additions and 117 deletions

View File

@ -1,14 +1,24 @@
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;
[Browsable(false)]
public string Name { get; private set; } = string.Empty;
[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

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -9,9 +10,15 @@ namespace ProjectLibrary.Entites
public class Book_Orders
{
public int BookID { get; private set; }
public int OrderID { get; private set; }
[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

View File

@ -1,9 +1,13 @@
namespace ProjectLibrary.Entites
using System.ComponentModel;
namespace ProjectLibrary.Entites
{
public class Book_Library
{
public int BookID { get; private set; }
public int LibraryID { get; private set; }
[DisplayName("Количество")]
public int Count { get; private set; }
public static Book_Library CreateEntity(int libraryID, int bookID, int count)

View File

@ -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,14 +11,24 @@ 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;
[Browsable(false)]
public IEnumerable<Book_Library> 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<Book_Library> bookLibrary)
{
return new Library
@ -28,5 +39,13 @@ namespace ProjectLibrary.Entites
BookLibrary = bookLibrary
};
}
public void SetLibraryForBook(IEnumerable<Book_Library> book_Library)
{
if (book_Library != null && book_Library.Any())
{
BookLibrary = book_Library;
}
}
}
}

View File

@ -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,15 +13,32 @@ 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; }
[DisplayName("ФИО читателя")]
public string ReaderName { get; private set; }
public string BookName { get; set; }
[Browsable(false)]
public IEnumerable<Book_Orders> 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<Book_Orders> bookOrders)
{
@ -33,17 +51,12 @@ namespace ProjectLibrary.Entites
BookOrders = bookOrders
};
}
public static Orders CreateEntity(TempBookOrders tempBookOrders, IEnumerable<Book_Orders> bookOrders)
public void SetOrdersOfBooks(IEnumerable<Book_Orders> 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;
}
}
}
}

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

@ -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)

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Entites;
public class TempBookOrders
{
public int Id { get; set; }
public DateTime OrderDate { get; set; }
public DateTime ReturnDate { get; set; }
public int ReaderID { get; set; }
public int BookID { get; set; }
public int Count { get; set; }
}

View File

@ -1,12 +1,25 @@
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 string ReaderName { 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)
{
return new TicketExtensions

View File

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

View File

@ -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)

View File

@ -40,56 +40,53 @@
dataGridViewOrders.AllowUserToAddRows = false;
dataGridViewOrders.AllowUserToDeleteRows = false;
dataGridViewOrders.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewOrders.Location = new Point(12, 11);
dataGridViewOrders.Margin = new Padding(3, 2, 3, 2);
dataGridViewOrders.Location = new Point(14, 15);
dataGridViewOrders.Name = "dataGridViewOrders";
dataGridViewOrders.ReadOnly = true;
dataGridViewOrders.RowHeadersWidth = 51;
dataGridViewOrders.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewOrders.Size = new Size(525, 225);
dataGridViewOrders.Size = new Size(600, 300);
dataGridViewOrders.TabIndex = 8;
//
// buttonAdd
//
buttonAdd.Location = new Point(12, 251);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Location = new Point(14, 335);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(88, 22);
buttonAdd.Size = new Size(101, 29);
buttonAdd.TabIndex = 9;
buttonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(227, 251);
buttonUpdate.Margin = new Padding(3, 2, 3, 2);
buttonUpdate.Location = new Point(259, 335);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(88, 22);
buttonUpdate.Size = new Size(101, 29);
buttonUpdate.TabIndex = 10;
buttonUpdate.Text = "Изменить";
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonRemove
//
buttonRemove.Location = new Point(450, 251);
buttonRemove.Margin = new Padding(3, 2, 3, 2);
buttonRemove.Location = new Point(514, 335);
buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(88, 22);
buttonRemove.Size = new Size(101, 29);
buttonRemove.TabIndex = 11;
buttonRemove.Text = "Удалить";
buttonRemove.Click += buttonRemove_Click;
//
// FLibraries
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(562, 283);
ClientSize = new Size(642, 377);
Controls.Add(dataGridViewOrders);
Controls.Add(buttonAdd);
Controls.Add(buttonUpdate);
Controls.Add(buttonRemove);
Margin = new Padding(3, 4, 3, 4);
Name = "FLibraries";
Text = "FLibraries";
Text = "Библиотеки";
Load += FLibraries_Load;
((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit();
ResumeLayout(false);

View File

@ -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)
{

View File

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

View File

@ -21,7 +21,7 @@ namespace ProjectLibrary.Forms
comboBox.ValueMember = "Id";
Book.DataSource = bookRepository.ReadBooks();
Book.DisplayMember = "Name";
comboBox.DisplayMember = "NameTypeBookID";
Book.ValueMember = "Id";
}

View File

@ -82,7 +82,7 @@
buttonCreate.UseVisualStyleBackColor = false;
buttonCreate.Click += ButtonCreate_Click;
//
// FormOrderDistributionReport
// FOrderDistributionReport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
@ -92,8 +92,8 @@
Controls.Add(label1);
Controls.Add(labelFileName);
Controls.Add(buttonSelectFileName);
Name = "FormOrderDistributionReport";
Text = "FormInvoiceDistributionReport";
Name = "FOrderDistributionReport";
Text = "Количество книг в библиотеках";
ResumeLayout(false);
PerformLayout();
}

View File

@ -74,7 +74,7 @@
Controls.Add(buttonAdd);
Controls.Add(buttonRemove);
Name = "FOrders";
Text = "FOrders";
Text = "Заказы";
Load += FOrders_Load;
((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit();
ResumeLayout(false);

View File

@ -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)

View File

@ -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)
{

View File

@ -39,45 +39,43 @@
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 11);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Location = new Point(14, 15);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersWidth = 51;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(525, 225);
dataGridView.Size = new Size(600, 300);
dataGridView.TabIndex = 8;
//
// buttonAdd
//
buttonAdd.Location = new Point(12, 251);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Location = new Point(14, 335);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(88, 22);
buttonAdd.Size = new Size(101, 29);
buttonAdd.TabIndex = 9;
buttonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(227, 251);
buttonUpdate.Margin = new Padding(3, 2, 3, 2);
buttonUpdate.Location = new Point(259, 335);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(88, 22);
buttonUpdate.Size = new Size(101, 29);
buttonUpdate.TabIndex = 10;
buttonUpdate.Text = "Изменить";
buttonUpdate.Click += buttonUpdate_Click;
//
// FTiclet_Extensions
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(569, 293);
ClientSize = new Size(650, 391);
Controls.Add(dataGridView);
Controls.Add(buttonAdd);
Controls.Add(buttonUpdate);
Margin = new Padding(3, 4, 3, 4);
Name = "FTiclet_Extensions";
Text = "FTiclet_Extensions";
Text = "Продления билетов";
Load += FTiclet_Extensions_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);

View File

@ -62,6 +62,11 @@ 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)
{

View File

@ -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;
@ -23,7 +24,7 @@ public class ChartReport
{
new PdfBuilder(filePath)
.AddHeader("Количество книг в библиотеках")
.AddPieChart("Библиотеки", GetData(dateTime))
.AddPieChart($"Библиотеки на {dateTime: dd MMMM yyyy}", GetData(dateTime))
.Build();
return true;
}
@ -34,13 +35,12 @@ 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()
.Where(x => x.OrderDate.Date == dateTime.Date)
.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))
.GroupBy(x => x.BookOrders.First(y => y.OrderID == x.Id).BookName , (key, group) => new { Name = key, Count = group.Sum(y => y.BookOrders.First(z => z.OrderID == y.Id).Count) })
.Select(x => (x.Name, (double)x.Count))
.ToList();
}
}

View File

@ -13,7 +13,7 @@ public class TableReport
{
private readonly IOrderRepository _orderRepository;
private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Id заказа","Дата заказа", "Дата возврата", "Книга", "Количество"];
internal static readonly string[] item = ["Id заказа", "Дата заказа", "Дата возврата","Книга", "Количество"];
public TableReport(IOrderRepository orderRepository, ILogger<TableReport> logger)
@ -22,13 +22,13 @@ 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
{
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;
@ -40,27 +40,27 @@ public class TableReport
}
}
private List<string[]> GetData(DateTime startDate, DateTime endDate)
private List<string[]> GetData(DateTime? startDate = null, DateTime? endDate = null)
{
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
Book = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.BookName,
Count = x.BookOrders.FirstOrDefault(y => y.OrderID == x.Id)?.Count
})
.OrderBy(x => x.DateOrder);
.OrderBy(x => x.Id);
return
new List<string[]>() { 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() ?? string.Empty, x.Count?.ToString("N0") ?? string.Empty}))
.Union([["Всего", "", "", "", data.Sum(x => x.Count ?? 0).ToString("N0")]])
.ToList();
//return null;
Review

Закомментированного кода быть не должно

Закомментированного кода быть не должно
}
}

View File

@ -4,7 +4,7 @@
public interface IOrderRepository
{
IEnumerable<Orders> ReadOrders();
IEnumerable<Orders> ReadOrders(DateTime? StartDate = null, DateTime? EndDate = null);
Orders ReadOrderById(int id);
void CreateOrder(Orders order);
void DeleteOrder(int id);

View File

@ -164,14 +164,35 @@ namespace ProjectLibrary.Repositories.Implementations
public IEnumerable<Library> ReadLibraries()
{
_logger.LogInformation("Получение всех библиотек");
var builder = new QueryBuilder();
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Library";
var libraries = connection.Query<Library>(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<int, List<Book_Library>>();
var libraries = connection.Query<Library, Book_Library, Library>(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)
{

View File

@ -108,20 +108,54 @@ namespace ProjectLibrary.Repositories.Implementations
}
// Получение всех заказов
public IEnumerable<Orders> ReadOrders()
public IEnumerable<Orders> 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");
}
/*if (EndDate.HasValue)
{
builder.AddCollerction("ord.ReturnDate < @EndDate");
}*/
var querySelect = $@"SELECT ord.*,re.name as ReaderName,
bk.Name as BookName,
Obo.bookid as bookid,
Obo.Orderid, obo.count
FROM Orders ord
INNER JOIN Book_Orders bo ON bo.orderId = ord.Id";
var order = connection.Query<TempBookOrders>(querySelect);
INNER JOIN Book_Orders Obo ON Obo.orderId = ord.Id
Inner join book bk on bk.ID = obo.Bookid
inner join reader re on re.id = ord.readerid
{builder.Build()}";
var OrderBookDict = new Dictionary<int, List<Book_Orders>>();
var order = connection
.Query<Orders, Book_Orders, Orders>(querySelect, (orders, books_orders) =>
{
if (!OrderBookDict.TryGetValue(orders.Id, out var Book_Orders))
{
Book_Orders = [];
OrderBookDict.Add(orders.Id, Book_Orders);
}
books_orders.BookName = orders.BookName;
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)
{

View File

@ -112,7 +112,9 @@ namespace ProjectLibrary.Repositories.Implementations
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Ticket_Extensions";
var querySelect = @"SELECT te.*, r.Name as ReaderName
FROM Ticket_Extensions te
INNER JOIN Reader r ON r.Id = te.ReaderId";
var ticketExtensions = connection.Query<TicketExtensions>(querySelect).ToList();
_logger.LogDebug("Полученные продления билетов: {json}", JsonConvert.SerializeObject(ticketExtensions));