8(4/3). Fin*[ ? ]
This commit is contained in:
parent
d1cb641edd
commit
6dc22058f4
@ -60,7 +60,12 @@ public partial class BookListF : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadList() => DataGV.DataSource = _bookR.GetBookList();
|
||||
private void ReloadList()
|
||||
{
|
||||
DataGV.DataSource = _bookR.GetBookList();
|
||||
// [Browsable(false)] * [ - ]
|
||||
DataGV.Columns["MainBookInfo"].Visible = false; // [ + ]
|
||||
}
|
||||
|
||||
private void DelBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
@ -65,8 +65,11 @@ public partial class OrdersF : Form
|
||||
|
||||
private void ReloadList()
|
||||
{
|
||||
var res = _regR.GetOrdersInfo();
|
||||
DataGV.DataSource = _regR.GetOrdersInfo();
|
||||
// DataGV.Columns["BorrowDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
// DataGV.Columns["ID"].Visible = false;
|
||||
// DataGV.Columns["OrderID"].Visible = false;
|
||||
DataGV.Columns["BorrowDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||
}
|
||||
|
||||
private bool GetIDFromRow(out int id)
|
||||
|
@ -5,6 +5,7 @@ public class Registration
|
||||
public int ID { get; private set; }
|
||||
public int OrderID { get; private set; }
|
||||
public int BookID { get; private set; }
|
||||
|
||||
public string BookInfo { get; private set; } = string.Empty;
|
||||
public string Note { get; private set; }
|
||||
|
||||
|
@ -18,13 +18,11 @@ internal class ChartReport
|
||||
{
|
||||
try
|
||||
{
|
||||
var updates = _updR.GetUpdateList().ToList(); // Materialize the query
|
||||
var updates = _updR.GetUpdateList(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1)).ToList(); // Materialize the query
|
||||
var data = GetData(updates, dateTime);
|
||||
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
|
||||
new PdfBuilder(filePath).AddHeader("Card Updates") // More descriptive header
|
||||
.AddPieChart("Number of Times Card Updated", data) // Corrected caption
|
||||
new PdfBuilder(filePath).AddHeader("Card Updates")
|
||||
.AddPieChart("Number of Times Card Updated", data)
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -34,23 +32,12 @@ internal class ChartReport
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<(string Caption, double Value)> GetData(List<UpdateC> updates, DateTime date)
|
||||
{
|
||||
var result = new List<(string Caption, double Value)>();
|
||||
|
||||
var distinctCards = updates.Where(u => u.LastUpdate.Date == date.Date) // Filter by date
|
||||
.GroupBy(u => u.CardID)
|
||||
.Select(g => new { CardID = g.Key, Count = g.Count() })
|
||||
.ToList();
|
||||
|
||||
|
||||
foreach (var cardData in distinctCards)
|
||||
{
|
||||
result.Add(($"Card {cardData.CardID}", cardData.Count));
|
||||
}
|
||||
|
||||
return result;
|
||||
return updates.GroupBy(x => x.CardID)
|
||||
.Select(group => (
|
||||
Caption: $"Card n_{group.Key}",
|
||||
Value: (double)group.Count()
|
||||
)).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ internal class PdfBuilder
|
||||
// _document.AddSection().AddParagraph(header, "NormalBold");
|
||||
// return this;
|
||||
}
|
||||
public PdfBuilder AddPieChart(string title, List<(string Caption, double
|
||||
Value)> data)
|
||||
public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace LDBproject.Reports
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Report about borrowed books", 0, 5) // Updated header
|
||||
.AddParagraph($"Period: {startDate:yyyy-MM-dd} - {endDate:yyyy-MM-dd}", 0)
|
||||
.AddTable(new[] { 4, 4, 7, 4, 7 }, GetData(startDate, endDate)) // Updated column widths
|
||||
.AddTable([4, 4, 7, 4, 7], GetData(startDate, endDate)) // Updated column widths
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -32,27 +32,33 @@ namespace LDBproject.Reports
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<string[]> GetData(DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var data = _orderRep.GetOrdersInfo(brDate: startDate, tillDate: endDate)
|
||||
.SelectMany(order => order.Registrations
|
||||
.Select(reg => new
|
||||
{
|
||||
order.EmployeeName,
|
||||
order.ReaderName,
|
||||
order.BorrowDate,
|
||||
order.BookInfo,
|
||||
reg.Note
|
||||
}))
|
||||
.OrderBy(x => x.BorrowDate);
|
||||
|
||||
|
||||
var result = new List<string[]> { item };
|
||||
var orders = _orderRep.GetOrdersInfo();
|
||||
result.AddRange(data.Select(x => new string[]
|
||||
{
|
||||
x.EmployeeName,
|
||||
x.ReaderName,
|
||||
x.BorrowDate.ToString("dd.MM.yyyy"),
|
||||
x.BookInfo,
|
||||
x.Note
|
||||
}));
|
||||
int totalBookCount = data.Count();
|
||||
|
||||
var flattenedData = orders
|
||||
.SelectMany(order => order.Registrations
|
||||
.Select(reg => new { order.LibrarianID, order.CardID,
|
||||
order.BorrowDate, reg.BookID, reg.Note }))
|
||||
.Where(x => startDate <= x.BorrowDate && x.BorrowDate <= endDate)
|
||||
.ToList();
|
||||
|
||||
result.AddRange(flattenedData.Select(x => new string[]
|
||||
{
|
||||
x.LibrarianID.ToString(),
|
||||
x.CardID.ToString(),
|
||||
x.BorrowDate.ToString("yyyy-MM-dd"),
|
||||
x.BookID.ToString(),
|
||||
x.Note
|
||||
}).ToList());
|
||||
int totalBookCount = flattenedData.Count;
|
||||
result.Add(new[] { "Total Books:", "", "", totalBookCount.ToString(), "" });
|
||||
|
||||
return result;
|
||||
|
@ -4,7 +4,8 @@ namespace LDBproject.Repositories;
|
||||
|
||||
public interface IOrderRep
|
||||
{
|
||||
IEnumerable<Order> GetOrdersInfo();
|
||||
IEnumerable<Order> GetOrdersInfo(DateTime? brDate = null, DateTime? tillDate = null,
|
||||
int? cardID = null, int? librnID = null);
|
||||
|
||||
void CreateOrder(Order order);
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace LDBproject.Repositories;
|
||||
|
||||
public interface IUpdateRep
|
||||
{
|
||||
IEnumerable<UpdateC> GetUpdateList();
|
||||
IEnumerable<UpdateC> GetUpdateList(DateTime? dateFrom = null, DateTime? dateTo = null);
|
||||
|
||||
UpdateC GetUpdateByID(int id);
|
||||
|
||||
|
@ -130,25 +130,45 @@ public class OrderR : IOrderRep
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Order> GetOrdersInfo()
|
||||
public IEnumerable<Order> GetOrdersInfo(DateTime? brDate = null, DateTime? tilldate = null,
|
||||
int? cardID = null, int? librnID = null)
|
||||
{
|
||||
_logger.LogInformation("< Getting ORDERS >");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (brDate.HasValue)
|
||||
{
|
||||
builder.AddCondition("orders.BorrowDate >= @brDate");
|
||||
}
|
||||
if (brDate.HasValue)
|
||||
{
|
||||
builder.AddCondition("orders.BorrowDate <= @tilldate");
|
||||
}
|
||||
if (cardID.HasValue)
|
||||
{
|
||||
builder.AddCondition("orders.CardID = @cardID");
|
||||
}
|
||||
if (librnID.HasValue)
|
||||
{
|
||||
builder.AddCondition("orders.LibrarianID = @librnID");
|
||||
}
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelectAll = @"SELECT
|
||||
orders.*,
|
||||
lc.FIO as EmployeeName,
|
||||
CONCAT(books.Title, ' ', books.Author) as BookInfo,
|
||||
CONCAT(cc.CardID, ' ', cc.FIO) as ReaderName,
|
||||
regs.BookID, regs.Note
|
||||
FROM Orders orders
|
||||
LEFT JOIN LibrarianCards lc ON lc.CardID = orders.LibrarianID
|
||||
LEFT JOIN CustomerCards cc ON cc.CardID = orders.CardID
|
||||
INNER JOIN Registrations regs ON regs.OrderID = orders.OrderID
|
||||
LEFT JOIN Books books ON books.BookID = regs.BookID";
|
||||
var querySelectAll = @$"SELECT
|
||||
orders.*,
|
||||
lc.FIO as EmployeeName,
|
||||
CONCAT(books.Title, ' ', books.Author) as BookInfo,
|
||||
CONCAT(cc.CardID, ' ', cc.FIO) as ReaderName,
|
||||
regs.BookID, regs.Note
|
||||
FROM Orders orders
|
||||
INNER JOIN LibrarianCards lc ON lc.CardID = orders.LibrarianID
|
||||
INNER JOIN CustomerCards cc ON cc.CardID = orders.CardID
|
||||
INNER JOIN Registrations regs ON regs.OrderID = orders.OrderID
|
||||
LEFT JOIN Books books ON books.BookID = regs.BookID
|
||||
{builder.Build()}";
|
||||
|
||||
var regsDict = new Dictionary<int, List<Registration>>();
|
||||
var orders = connection.Query<Order, Registration, Order>(querySelectAll, (order, orders) =>
|
||||
@ -169,7 +189,7 @@ public class OrderR : IOrderRep
|
||||
var odr = orders.First(y => y.OrderID == x.Key);
|
||||
odr.SetRegs(x.Value);
|
||||
return odr;
|
||||
});
|
||||
}).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ public class UpdateR : IUpdateRep
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<UpdateC> GetUpdateList()
|
||||
public IEnumerable<UpdateC> GetUpdateList(DateTime? dateFrom = null, DateTime? dateTo = null)
|
||||
{
|
||||
_logger.LogInformation("< Getting all UPDATES >");
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user