Реализовал сохранение отчета в PDF

This commit is contained in:
Никита Потапов 2024-12-06 15:34:00 +04:00
parent 4144f645ad
commit 9a85314694

View File

@ -3,16 +3,19 @@ using InternetShopContracts.DataViewModels;
using InternetShopContracts.LogicsContracts;
using InternetShopForms.Orders;
using InternetShopForms.Products;
using WinFormsLibrary1.HelperClasses;
namespace InternetShopForms
{
public partial class FormOrdersList : Form
{
private IOrderLogic _orderLogic;
public FormOrdersList(IOrderLogic orderLogic)
private IProductLogic _productLogic;
public FormOrdersList(IOrderLogic orderLogic, IProductLogic productLogic)
{
InitializeComponent();
_orderLogic = orderLogic;
_productLogic = productLogic;
List<(string, string, float)> configureColumns = [
("ID", "Id", 1.0f),
@ -289,7 +292,51 @@ namespace InternetShopForms
{
return;
}
// todo
var orders = _orderLogic.ReadList();
var products = _productLogic.ReadList();
Dictionary<string, double> productsStat = new Dictionary<string, double>();
foreach (var order in orders)
{
foreach (var product in order.ProductNames)
{
if (productsStat.ContainsKey(product))
{
productsStat[product]++;
}
else
{
productsStat.Add(product, 1);
}
}
}
List<ChartData> charts = new List<ChartData>();
foreach (var product in productsStat.Keys)
{
ChartData chartData = new ChartData();
Dictionary<string, double> data = new Dictionary<string, double>();
data.Add(product, productsStat[product]);
chartData.SeriesName = product;
chartData.Data = data;
charts.Add(chartData);
}
try
{
pdfHistogram.CreateHistogramPdf(
exportFileName,
"Îò÷åò ïî òîâàðàì",
"Êîëè÷åñòâî çàêàçîâ",
OxyPlot.Legends.LegendPosition.RightTop,
charts
);
MessageBox.Show("Îò÷åò óñïåøíî ñôîðìèðîâàí", "Ñîçäàíèå îò÷åòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà ïðè ñîçäàíèè îò÷åòà:\n" + ex.Message, "Ñîçäàíèå îò÷åòà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void reportOrderImagesExcelToolStripMenuItem_Click(object sender, EventArgs e)