5(3/2). Excel added, all reports work syccessfully
This commit is contained in:
parent
df70bb6e56
commit
fd945d094e
@ -34,7 +34,7 @@ public partial class FullReportsF : Form
|
||||
|
||||
if (_container.Resolve<DocReport>().CreateDoc(sfd.FileName, BookChBox.Checked, EmployeeChBox.Checked, ReadersChBox.Checked))
|
||||
{
|
||||
MessageBox.Show("The document was formed : Report done", "Process result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
MessageBox.Show("< The DOCument was made : Report done >", "Process result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
114
LibraryDBproject/LDBproj/AdditionalForms/OrdersReportF.Designer.cs
generated
Normal file
114
LibraryDBproject/LDBproj/AdditionalForms/OrdersReportF.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
||||
namespace LDBproject.AdditionalForms
|
||||
{
|
||||
partial class OrdersReportF
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
OkBtn = new Button();
|
||||
FilePathTb = new TextBox();
|
||||
ComboBoxB = new ComboBox();
|
||||
BeginDTP = new DateTimePicker();
|
||||
FinDTP = new DateTimePicker();
|
||||
PathConfirmBtn = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// OkBtn
|
||||
//
|
||||
OkBtn.Location = new Point(49, 362);
|
||||
OkBtn.Name = "OkBtn";
|
||||
OkBtn.Size = new Size(513, 46);
|
||||
OkBtn.TabIndex = 0;
|
||||
OkBtn.Text = "Confirm";
|
||||
OkBtn.UseVisualStyleBackColor = true;
|
||||
OkBtn.Click += MakeReportBtn_Click;
|
||||
//
|
||||
// FilePathTb
|
||||
//
|
||||
FilePathTb.Location = new Point(49, 56);
|
||||
FilePathTb.Name = "FilePathTb";
|
||||
FilePathTb.Size = new Size(413, 39);
|
||||
FilePathTb.TabIndex = 1;
|
||||
//
|
||||
// ComboBoxB
|
||||
//
|
||||
ComboBoxB.FormattingEnabled = true;
|
||||
ComboBoxB.Location = new Point(49, 142);
|
||||
ComboBoxB.Name = "ComboBoxB";
|
||||
ComboBoxB.Size = new Size(513, 40);
|
||||
ComboBoxB.TabIndex = 2;
|
||||
//
|
||||
// BeginDTP
|
||||
//
|
||||
BeginDTP.Location = new Point(49, 215);
|
||||
BeginDTP.Name = "BeginDTP";
|
||||
BeginDTP.Size = new Size(513, 39);
|
||||
BeginDTP.TabIndex = 3;
|
||||
//
|
||||
// FinDTP
|
||||
//
|
||||
FinDTP.Location = new Point(49, 279);
|
||||
FinDTP.Name = "FinDTP";
|
||||
FinDTP.Size = new Size(513, 39);
|
||||
FinDTP.TabIndex = 4;
|
||||
//
|
||||
// PathConfirmBtn
|
||||
//
|
||||
PathConfirmBtn.Location = new Point(477, 53);
|
||||
PathConfirmBtn.Name = "PathConfirmBtn";
|
||||
PathConfirmBtn.Size = new Size(85, 47);
|
||||
PathConfirmBtn.TabIndex = 5;
|
||||
PathConfirmBtn.Text = "../";
|
||||
PathConfirmBtn.UseVisualStyleBackColor = true;
|
||||
PathConfirmBtn.Click += SelectFilePathBtn_Click;
|
||||
//
|
||||
// CardsReportF
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(614, 452);
|
||||
Controls.Add(PathConfirmBtn);
|
||||
Controls.Add(FinDTP);
|
||||
Controls.Add(BeginDTP);
|
||||
Controls.Add(ComboBoxB);
|
||||
Controls.Add(FilePathTb);
|
||||
Controls.Add(OkBtn);
|
||||
Name = "CardsReportF";
|
||||
Text = "CardsReportF";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button OkBtn;
|
||||
private TextBox FilePathTb;
|
||||
private ComboBox ComboBoxB;
|
||||
private DateTimePicker BeginDTP;
|
||||
private DateTimePicker FinDTP;
|
||||
private Button PathConfirmBtn;
|
||||
}
|
||||
}
|
87
LibraryDBproject/LDBproj/AdditionalForms/OrdersReportF.cs
Normal file
87
LibraryDBproject/LDBproj/AdditionalForms/OrdersReportF.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using Unity;
|
||||
using LDBproject.Repositories;
|
||||
using LDBproject.Reports;
|
||||
using LDBproject.Entities;
|
||||
|
||||
namespace LDBproject.AdditionalForms
|
||||
{
|
||||
public partial class OrdersReportF : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly IOrderRep _orderRep;
|
||||
|
||||
public OrdersReportF(IUnityContainer container, IOrderRep orderRep)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
_orderRep = orderRep ?? throw new ArgumentNullException(nameof(orderRep));
|
||||
|
||||
var ordersInfo = _orderRep.GetOrdersInfo().ToList();
|
||||
|
||||
if (ordersInfo.Any())
|
||||
{
|
||||
ComboBoxB.DataSource = ordersInfo;
|
||||
ComboBoxB.DisplayMember = "DisplayInfo";
|
||||
ComboBoxB.ValueMember = "OrderID"; // Assuming the data model has this property
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("No Orders Found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
private void SelectFilePathBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
var sfd = new SaveFileDialog() { Filter = "Excel Files | *.xlsx" };
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
FilePathTb.Text = sfd.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
private void MakeReportBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string filePath = FilePathTb.Text;
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
MessageBox.Show("Please select a file path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ComboBoxB.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Please select an order.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
DateTime startDate = BeginDTP.Value;
|
||||
DateTime endDate = FinDTP.Value;
|
||||
|
||||
if (startDate >= endDate)
|
||||
{
|
||||
MessageBox.Show("Start date must be before end date.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
// Correctly get the selected OrderInfo object
|
||||
if (ComboBoxB.SelectedItem is not Order selectedOrderInfo)
|
||||
{
|
||||
MessageBox.Show("Invalid order selection.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
// Resolve TableReport and pass the dates
|
||||
var tableReport = _container.Resolve<TableReport>();
|
||||
|
||||
if (tableReport.CreateTable(filePath, startDate, endDate))
|
||||
{
|
||||
MessageBox.Show("< Chart PDF report generated successfully >", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"An error occurred while generating the report: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
LibraryDBproject/LDBproj/AdditionalForms/OrdersReportF.resx
Normal file
120
LibraryDBproject/LDBproj/AdditionalForms/OrdersReportF.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -24,4 +24,16 @@ public class Order
|
||||
BorrowDate = borrow
|
||||
};
|
||||
}
|
||||
|
||||
public static Order NewOrder(TemprOrderReg order, IEnumerable<Registration> regs)
|
||||
{
|
||||
return new Order
|
||||
{
|
||||
OrderID = order.OrderID,
|
||||
CardID = order.CardID,
|
||||
LibrarianID = order.LibrarianID,
|
||||
Registrations = regs,
|
||||
BorrowDate= order.BorrowDate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace LDBproject.Entities;
|
||||
|
||||
internal class TemprOrderReg
|
||||
public class TemprOrderReg
|
||||
{
|
||||
// from Order class
|
||||
public int OrderID { get; private set; }
|
||||
|
@ -96,7 +96,7 @@ public partial class MainForm : Form
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
_container.Resolve<OrdersReportF>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -118,4 +118,3 @@ public partial class MainForm : Form
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
61
LibraryDBproject/LDBproj/Reports/TableReport.cs
Normal file
61
LibraryDBproject/LDBproj/Reports/TableReport.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using LDBproject.Repositories;
|
||||
|
||||
namespace LDBproject.Reports
|
||||
{
|
||||
internal class TableReport
|
||||
{
|
||||
private readonly IOrderRep _orderRep;
|
||||
private readonly ILogger<TableReport> _logger;
|
||||
internal static readonly string[] item = { "Librarian ID", "Card ID", "Borrow Date", "Book ID", "Note" };
|
||||
|
||||
public TableReport(IOrderRep orderRep, ILogger<TableReport> logger)
|
||||
{
|
||||
_orderRep = orderRep ?? throw new ArgumentNullException(nameof(orderRep));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public bool CreateTable(string filePath, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
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
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while forming document");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private List<string[]> GetData(DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var result = new List<string[]> { item };
|
||||
var orders = _orderRep.GetOrdersInfo();
|
||||
|
||||
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,8 +4,7 @@ namespace LDBproject.Repositories;
|
||||
|
||||
public interface IOrderRep
|
||||
{
|
||||
IEnumerable<Order> GetOrdersInfo(
|
||||
int? librarianID = null, int? orderID = null, int? customerID = null);
|
||||
IEnumerable<Order> GetOrdersInfo();
|
||||
|
||||
void CreateOrder(Order order);
|
||||
|
||||
|
@ -130,21 +130,20 @@ public class OrderR : IOrderRep
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------- [ REVIEWED (waits for further editing) ] -------------------------------
|
||||
|
||||
public IEnumerable<Order> GetOrdersInfo(int? orderID = null, int ? librarianID = null, int? customerID = null)
|
||||
public IEnumerable<Order> GetOrdersInfo()
|
||||
{
|
||||
_logger.LogInformation("< Getting all ORDERS >");
|
||||
_logger.LogInformation("< Getting ORDERS based on a date >");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var querySelectAll = @"SELECT * FROM Orders";
|
||||
var orders = connection.Query<Order>(querySelectAll);
|
||||
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);
|
||||
_logger.LogDebug("Aimed objects: {json}", JsonConvert.SerializeObject(orders));
|
||||
|
||||
return 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();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user