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