6(4/1). Improvement with displaying info, query rearrangement left
This commit is contained in:
parent
fd945d094e
commit
ed1b146837
@ -63,8 +63,11 @@ public partial class CustomerListF : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadList() =>
|
||||
private void ReloadList()
|
||||
{
|
||||
DataGV.DataSource = _custR.GetCards();
|
||||
DataGV.Columns["FIO"].Visible = false;
|
||||
}
|
||||
|
||||
private bool GetIDFromRow(out int id)
|
||||
{
|
||||
|
@ -83,7 +83,11 @@ public partial class EmployeesF : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadList() => DataGV.DataSource = _libR.GetCards();
|
||||
private void ReloadList()
|
||||
{
|
||||
DataGV.DataSource = _libR.GetCards();
|
||||
// DataGV.Columns["CardID"].Visible = false;
|
||||
}
|
||||
|
||||
private bool GetiDFromRow(out int id)
|
||||
{
|
||||
|
@ -63,8 +63,12 @@ public partial class OrdersF : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadList() =>
|
||||
private void ReloadList()
|
||||
{
|
||||
DataGV.DataSource = _regR.GetOrdersInfo();
|
||||
DataGV.Columns["OrderID"].Visible = false;
|
||||
DataGV.Columns["BorrowDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
}
|
||||
|
||||
private bool GetIDFromRow(out int id)
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
using LDBproject.Entities;
|
||||
using LDBproject.Repositories;
|
||||
using LDBproject.Repositories.Implementations;
|
||||
|
||||
namespace LDBproject.AdditionalForms;
|
||||
|
||||
@ -23,7 +22,7 @@ public partial class RegOrderF : Form
|
||||
CardCBox.ValueMember = "CardID";
|
||||
|
||||
BookColumnCBox.DataSource = bookRep.GetBookList();
|
||||
BookColumnCBox.DisplayMember = "Title";
|
||||
BookColumnCBox.DisplayMember = "MainBookInfo"; // MainBookInfo \ BookInfo
|
||||
BookColumnCBox.ValueMember = "BookID";
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,7 @@ public partial class UpdateF : Form
|
||||
LibrarianCBox.DisplayMember = "FIO";
|
||||
LibrarianCBox.ValueMember = "CardID";
|
||||
CardCBox.DataSource = customersRep.GetCards();
|
||||
CardCBox.DisplayMember = "FIO";
|
||||
CardCBox.DisplayMember = "CardID";
|
||||
CardCBox.DisplayMember = "FullReaderInfo"; // FullReaderInfo \ ReaderName
|
||||
CardCBox.ValueMember = "CardID";
|
||||
}
|
||||
|
||||
|
@ -63,8 +63,13 @@ public partial class UpdatesListF : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadList() =>
|
||||
private void ReloadList()
|
||||
{
|
||||
DataGV.DataSource = _updR.GetUpdateList();
|
||||
DataGV.Columns["ID"].Visible = false;
|
||||
DataGV.Columns["LastUpdate"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||
DataGV.Columns["UpdBoundary"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||
}
|
||||
|
||||
private bool GetIDFromRow(out int id)
|
||||
{
|
||||
|
@ -1,14 +1,24 @@
|
||||
using LDBproject.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
using LDBproject.Entities.Enums;
|
||||
|
||||
namespace LDBproject.Entities;
|
||||
|
||||
public class Book
|
||||
{
|
||||
public int BookID { get; private set; }
|
||||
|
||||
[DisplayName("< title >")]
|
||||
public string Title { get; private set; }
|
||||
[DisplayName("< author >")]
|
||||
public string Author { get; private set; }
|
||||
[DisplayName("< year of print >")]
|
||||
|
||||
public string MainBookInfo => $"<<{Title}>>; {Author}";
|
||||
|
||||
public int PublishYear { get; private set; }
|
||||
[DisplayName("< current position >")]
|
||||
public BookStat Status { get; private set; }
|
||||
[DisplayName("< genres >")]
|
||||
public Genres GenreMask { get; private set; } = Genres.None;
|
||||
|
||||
public static Book AddBook(
|
||||
|
@ -1,11 +1,18 @@
|
||||
namespace LDBproject.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace LDBproject.Entities;
|
||||
|
||||
public class CustomerCard
|
||||
{
|
||||
[DisplayName("Reader's index")]
|
||||
public int CardID { get; private set; }
|
||||
|
||||
[DisplayName("Reader's full name")]
|
||||
public string FIO { get; private set; }
|
||||
|
||||
public string FullReaderInfo => $"{CardID} : {FIO}";
|
||||
|
||||
[DisplayName("Birthday date")]
|
||||
public DateTime AgeBirthday { get; private set; }
|
||||
|
||||
public static CustomerCard AddCustomer(
|
||||
|
@ -1,4 +1,5 @@
|
||||
using LDBproject.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
using LDBproject.Entities.Enums;
|
||||
|
||||
namespace LDBproject.Entities;
|
||||
|
||||
@ -6,8 +7,10 @@ public class LibrarianCard
|
||||
{
|
||||
public int CardID { get; private set; }
|
||||
|
||||
[DisplayName("Employee full name")]
|
||||
public string FIO { get; private set; }
|
||||
|
||||
[DisplayName("Connected genres")]
|
||||
public Genres GenreMask { get; private set; }
|
||||
|
||||
public static LibrarianCard AddWorker(
|
||||
|
@ -1,15 +1,27 @@
|
||||
namespace LDBproject.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace LDBproject.Entities;
|
||||
|
||||
public class Order
|
||||
{
|
||||
public int OrderID { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int CardID { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int LibrarianID { get; private set; }
|
||||
[DisplayName("Reader")]
|
||||
public string ReaderName { get; private set; } = string.Empty;
|
||||
[DisplayName("Librarian")]
|
||||
public string EmployeeName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Book")]
|
||||
public string BookInfo { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Date of borrow")]
|
||||
public DateTime BorrowDate { get; private set; }
|
||||
|
||||
[DisplayName("List of borrowed books")]
|
||||
public string BookList => Registrations != null ? string.Join(", ", Registrations.Select(x => $"{x.BookID} {x.Note}")) : string.Empty;
|
||||
[Browsable(false)]
|
||||
public IEnumerable<Registration> Registrations { get; set; } = [];
|
||||
|
||||
public static Order NewOrder(
|
||||
@ -33,7 +45,15 @@ public class Order
|
||||
CardID = order.CardID,
|
||||
LibrarianID = order.LibrarianID,
|
||||
Registrations = regs,
|
||||
BorrowDate= order.BorrowDate
|
||||
BorrowDate = order.BorrowDate
|
||||
};
|
||||
}
|
||||
|
||||
public void SetRegs(IEnumerable<Registration> regs)
|
||||
{
|
||||
if (regs != null && regs.Any())
|
||||
{
|
||||
Registrations = regs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,9 @@
|
||||
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; }
|
||||
|
||||
public static Registration OrderReg(
|
||||
|
@ -1,20 +0,0 @@
|
||||
namespace LDBproject.Entities;
|
||||
|
||||
public class TemprOrderReg
|
||||
{
|
||||
// from Order class
|
||||
public int OrderID { get; private set; }
|
||||
|
||||
public int CardID { get; private set; }
|
||||
|
||||
public int LibrarianID { get; private set; }
|
||||
|
||||
public DateTime BorrowDate { get; private set; }
|
||||
|
||||
// from Registration class
|
||||
public int ID { get; private set; }
|
||||
|
||||
public int BookID { get; private set; }
|
||||
|
||||
public string Note { get; private set; }
|
||||
}
|
@ -1,17 +1,24 @@
|
||||
namespace LDBproject.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace LDBproject.Entities;
|
||||
|
||||
public class UpdateC
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int CardID { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int LibrarianID { get; private set; }
|
||||
|
||||
[DisplayName("Reader")]
|
||||
public string ReaderName { get; private set; } = string.Empty;
|
||||
[DisplayName("Librarian")]
|
||||
public string EmployeeName { get; private set; } = string.Empty;
|
||||
[DisplayName("Date of last upd")]
|
||||
public DateTime LastUpdate { get; private set; }
|
||||
|
||||
[DisplayName("upd active till")]
|
||||
public DateTime UpdBoundary { get; private set; }
|
||||
|
||||
[DisplayName("Notes")]
|
||||
public string Note { get; private set; }
|
||||
|
||||
public static UpdateC CustomerUpd(
|
||||
|
@ -132,18 +132,44 @@ public class OrderR : IOrderRep
|
||||
|
||||
public IEnumerable<Order> GetOrdersInfo()
|
||||
{
|
||||
_logger.LogInformation("< Getting ORDERS based on a date >");
|
||||
_logger.LogInformation("< Getting ORDERS >");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var querySelectAll = @"SELECT orders.*, regs.BookID, regs.Note FROM Orders orders
|
||||
INNER JOIN Registrations regs ON regs.OrderID = orders.OrderID";
|
||||
|
||||
var orders = connection.Query<TemprOrderReg>(querySelectAll);
|
||||
var querySelectAll = @"SELECT
|
||||
orders.*,
|
||||
lc.FIO as 'EmployeeName',
|
||||
CONCAT(books.Title, ' ', books.Author) as BookInfo,
|
||||
CONCAT(cc.FIO, ' ', cc.AnimalNickName) 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 = orders.BookID";
|
||||
|
||||
var regsDict = new Dictionary<int, List<Registration>>();
|
||||
var orders = connection.Query<Order, Registration, Order>(querySelectAll, (order, orders) =>
|
||||
{
|
||||
if (!regsDict.TryGetValue(order.OrderID, out var reg))
|
||||
{
|
||||
reg = [];
|
||||
regsDict.Add(order.OrderID, reg);
|
||||
}
|
||||
reg.Add(orders);
|
||||
return order;
|
||||
}, splitOn: "BookID"); // params: ... - variables parameters from GetOrdersInfo(...) [ ! ]
|
||||
// unnessessary - [ + ]
|
||||
_logger.LogDebug("Aimed objects: {json}", JsonConvert.SerializeObject(orders));
|
||||
return orders.GroupBy(x => x.OrderID, y => y, (key, value) => Order.NewOrder(value.First(),
|
||||
value.Select(z => Registration.OrderReg(z.OrderID, z.BookID, z.Note)))).ToList();
|
||||
|
||||
return regsDict.Select(x =>
|
||||
{
|
||||
var odr = orders.First(y => y.OrderID == x.Key);
|
||||
odr.SetRegs(x.Value);
|
||||
return odr;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -0,0 +1,34 @@
|
||||
using System.Text;
|
||||
|
||||
namespace LDBproject.Repositories.Implementations;
|
||||
internal class QueryBuilder
|
||||
{
|
||||
private readonly StringBuilder _builder;
|
||||
|
||||
public QueryBuilder()
|
||||
{
|
||||
_builder = new();
|
||||
}
|
||||
|
||||
public QueryBuilder AddCondition(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}";
|
||||
}
|
||||
}
|
@ -76,7 +76,15 @@ public class UpdateR : IUpdateRep
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelectAll = @"SELECT * FROM Updates";
|
||||
|
||||
var querySelectAll = @"SELECT
|
||||
upd.*,
|
||||
lc.FIO as 'EmployeeName',
|
||||
CONCAT(cc.CardID, ' ', cc.FIO) as ReaderName
|
||||
FROM Updates upd
|
||||
LEFT JOIN LibrarianCards lc ON lc.CardID = orders.LibrarianID
|
||||
LEFT JOIN CustomerCards cc ON cc.CardID = orders.CardID";
|
||||
|
||||
var upds = connection.Query<UpdateC>(querySelectAll);
|
||||
_logger.LogDebug("Aimed objects: {json}", JsonConvert.SerializeObject(upds));
|
||||
return upds;
|
||||
|
Loading…
Reference in New Issue
Block a user