Лабораторная 3 готовая
This commit is contained in:
parent
b60e109f9d
commit
59aad56527
@ -34,4 +34,16 @@ public class FuelSale
|
||||
FuelFuelSale = fuelFuelSale
|
||||
};
|
||||
}
|
||||
|
||||
public static FuelSale CreateElement(TempFuelFuelSale tempFuelFuelSale, IEnumerable<FuelFuelSale> fuelFuelSale)
|
||||
{
|
||||
return new FuelSale
|
||||
{
|
||||
Id = tempFuelFuelSale.Id,
|
||||
CashierId = tempFuelFuelSale.CashierId,
|
||||
SaleDate = tempFuelFuelSale.SaleDate,
|
||||
TotalPrice = tempFuelFuelSale.TotalPrice,
|
||||
FuelFuelSale = fuelFuelSale
|
||||
};
|
||||
}
|
||||
}
|
||||
|
17
GasStation/GasStation/Entities/TempFuelFuelSale.cs
Normal file
17
GasStation/GasStation/Entities/TempFuelFuelSale.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GasStation.Entities;
|
||||
|
||||
public class TempFuelFuelSale
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int CashierId { get; private set; }
|
||||
public DateTime SaleDate { get; private set; }
|
||||
public int TotalPrice { get; private set; }
|
||||
public int FuelId { get; private set; }
|
||||
public int Quantity { get; private set; }
|
||||
}
|
12
GasStation/GasStation/FormGasStation.Designer.cs
generated
12
GasStation/GasStation/FormGasStation.Designer.cs
generated
@ -39,6 +39,7 @@
|
||||
отчётыToolStripMenuItem = new ToolStripMenuItem();
|
||||
DirectoryReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
FuelReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
ToolStripFuelDistribution = new ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -102,7 +103,7 @@
|
||||
//
|
||||
// отчётыToolStripMenuItem
|
||||
//
|
||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, FuelReportToolStripMenuItem });
|
||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, FuelReportToolStripMenuItem, ToolStripFuelDistribution });
|
||||
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
||||
отчётыToolStripMenuItem.Size = new Size(62, 20);
|
||||
отчётыToolStripMenuItem.Text = "Отчёты";
|
||||
@ -123,6 +124,14 @@
|
||||
FuelReportToolStripMenuItem.Text = "Движение топлива";
|
||||
FuelReportToolStripMenuItem.Click += FuelReportToolStripMenuItem_Click;
|
||||
//
|
||||
// ToolStripFuelDistribution
|
||||
//
|
||||
ToolStripFuelDistribution.Name = "ToolStripFuelDistribution";
|
||||
ToolStripFuelDistribution.ShortcutKeys = Keys.Control | Keys.P;
|
||||
ToolStripFuelDistribution.Size = new Size(311, 22);
|
||||
ToolStripFuelDistribution.Text = "Распределение поставок топлива";
|
||||
ToolStripFuelDistribution.Click += ToolStripFuelDistribution_Click;
|
||||
//
|
||||
// FormGasStation
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -154,5 +163,6 @@
|
||||
private ToolStripMenuItem ToolStripMenuItemSuppliersFuel;
|
||||
private ToolStripMenuItem DirectoryReportToolStripMenuItem;
|
||||
private ToolStripMenuItem FuelReportToolStripMenuItem;
|
||||
private ToolStripMenuItem ToolStripFuelDistribution;
|
||||
}
|
||||
}
|
@ -103,4 +103,17 @@ public partial class FormGasStation : Form
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ToolStripFuelDistribution_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormSuppliersFuelDistributionReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
@ -68,6 +68,7 @@ public partial class FormFuelSale : Form
|
||||
Convert.ToInt32(row.Cells["ColumnFuel"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnQuantity"].Value), 0));
|
||||
}
|
||||
return list;
|
||||
return list.GroupBy(x => x.FuelId, x => x.Quantity, (id, counts) =>
|
||||
FuelFuelSale.CreateFuelFuelSale(0, id, counts.Sum(), 0)).ToList();
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@
|
||||
// ButtonSave
|
||||
//
|
||||
ButtonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonSave.Location = new Point(13, 370);
|
||||
ButtonSave.Location = new Point(12, 365);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(117, 22);
|
||||
ButtonSave.TabIndex = 5;
|
||||
@ -89,7 +89,7 @@
|
||||
// ButtonCancel
|
||||
//
|
||||
ButtonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonCancel.Location = new Point(210, 370);
|
||||
ButtonCancel.Location = new Point(211, 365);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(117, 22);
|
||||
ButtonCancel.TabIndex = 6;
|
||||
@ -99,11 +99,10 @@
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBox.Controls.Add(dataGridView);
|
||||
groupBox.Location = new Point(12, 89);
|
||||
groupBox.Location = new Point(13, 89);
|
||||
groupBox.Name = "groupBox";
|
||||
groupBox.Size = new Size(318, 272);
|
||||
groupBox.Size = new Size(318, 271);
|
||||
groupBox.TabIndex = 7;
|
||||
groupBox.TabStop = false;
|
||||
groupBox.Text = "Топливо";
|
||||
@ -120,9 +119,8 @@
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(312, 250);
|
||||
dataGridView.Size = new Size(312, 249);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// ColumnFuel
|
||||
|
@ -123,4 +123,10 @@
|
||||
<metadata name="ColumnQuantity.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnFuel.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnQuantity.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
108
GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.Designer.cs
generated
Normal file
108
GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.Designer.cs
generated
Normal file
@ -0,0 +1,108 @@
|
||||
namespace GasStation.Forms
|
||||
{
|
||||
partial class FormSuppliersFuelDistributionReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
ButtonFile = new Button();
|
||||
labelFileName = new Label();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
label1 = new Label();
|
||||
ButtonBuild = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ButtonFile
|
||||
//
|
||||
ButtonFile.Location = new Point(12, 22);
|
||||
ButtonFile.Name = "ButtonFile";
|
||||
ButtonFile.Size = new Size(75, 23);
|
||||
ButtonFile.TabIndex = 0;
|
||||
ButtonFile.Text = "Выбрать";
|
||||
ButtonFile.UseVisualStyleBackColor = true;
|
||||
ButtonFile.Click += ButtonFile_Click;
|
||||
//
|
||||
// labelFileName
|
||||
//
|
||||
labelFileName.AutoSize = true;
|
||||
labelFileName.Location = new Point(93, 26);
|
||||
labelFileName.Name = "labelFileName";
|
||||
labelFileName.Size = new Size(38, 15);
|
||||
labelFileName.TabIndex = 1;
|
||||
labelFileName.Text = "Файл";
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(71, 65);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(151, 23);
|
||||
dateTimePicker.TabIndex = 2;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(12, 71);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(36, 15);
|
||||
label1.TabIndex = 3;
|
||||
label1.Text = "Дата:";
|
||||
//
|
||||
// ButtonBuild
|
||||
//
|
||||
ButtonBuild.Location = new Point(12, 101);
|
||||
ButtonBuild.Name = "ButtonBuild";
|
||||
ButtonBuild.Size = new Size(210, 27);
|
||||
ButtonBuild.TabIndex = 4;
|
||||
ButtonBuild.Text = "Сформировать";
|
||||
ButtonBuild.UseVisualStyleBackColor = true;
|
||||
ButtonBuild.Click += ButtonBuild_Click;
|
||||
//
|
||||
// FormSuppliersFuelDistributionReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(236, 154);
|
||||
Controls.Add(ButtonBuild);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dateTimePicker);
|
||||
Controls.Add(labelFileName);
|
||||
Controls.Add(ButtonFile);
|
||||
Name = "FormSuppliersFuelDistributionReport";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "FormSuppliersFuelDistributionReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button ButtonFile;
|
||||
private Label labelFileName;
|
||||
private DateTimePicker dateTimePicker;
|
||||
private Label label1;
|
||||
private Button ButtonBuild;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using GasStation.Reports;
|
||||
using Unity;
|
||||
|
||||
namespace GasStation.Forms;
|
||||
|
||||
public partial class FormSuppliersFuelDistributionReport : Form
|
||||
{
|
||||
private string _fileName = string.Empty;
|
||||
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormSuppliersFuelDistributionReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
private void ButtonBuild_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_fileName))
|
||||
{
|
||||
throw new Exception("Отсутствует имя файла для отчета");
|
||||
}
|
||||
if
|
||||
(_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePicker.Value))
|
||||
{
|
||||
MessageBox.Show("Документ сформирован",
|
||||
"Формирование документа",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах",
|
||||
"Формирование документа",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при создании отчета",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Pdf Files | *.pdf"
|
||||
};
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_fileName = sfd.FileName;
|
||||
labelFileName.Text = Path.GetFileName(_fileName);
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
@ -26,6 +26,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.5" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
<PackageReference Include="Serilog" Version="4.0.2" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
|
54
GasStation/GasStation/Reports/ChartReport.cs
Normal file
54
GasStation/GasStation/Reports/ChartReport.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GasStation.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace GasStation.Reports;
|
||||
|
||||
internal class ChartReport
|
||||
{
|
||||
private readonly ISuppliersFuelRepository _suppliersFuelRepository;
|
||||
private readonly IFuelRepository _fuelRepository;
|
||||
private readonly ILogger<ChartReport> _logger;
|
||||
|
||||
public ChartReport(ISuppliersFuelRepository suppliersFuelRepository, IFuelRepository fuelRepository, ILogger<ChartReport> logger)
|
||||
{
|
||||
_suppliersFuelRepository = suppliersFuelRepository ?? throw new ArgumentNullException(nameof(suppliersFuelRepository));
|
||||
_fuelRepository = fuelRepository ?? throw new ArgumentNullException(nameof(fuelRepository));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public bool CreateChart(string filePath, DateTime dateTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Поставки топлива")
|
||||
.AddPieChart("Виды топлива", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
var fuelNames = _fuelRepository.ReadFuels()
|
||||
.ToDictionary(f => f.Id, f => f.Type);
|
||||
|
||||
return _suppliersFuelRepository
|
||||
.ReadSuppliersFuels()
|
||||
.Where(x => x.Date.Date == dateTime.Date)
|
||||
.SelectMany(x => x.SuppliersFuelFuel)
|
||||
.GroupBy(x => x.FuelId)
|
||||
.Select(g => (Caption: fuelNames[g.Key].ToString(), Value: (double)g.Sum(x => x.Quantity)))
|
||||
.ToList();
|
||||
}
|
||||
}
|
77
GasStation/GasStation/Reports/PdfBuilder.cs
Normal file
77
GasStation/GasStation/Reports/PdfBuilder.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System.Text;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MigraDoc.Rendering;
|
||||
|
||||
namespace GasStation.Reports;
|
||||
|
||||
internal class PdfBuilder
|
||||
{
|
||||
private readonly string _filePath;
|
||||
private readonly Document _document;
|
||||
|
||||
public PdfBuilder(string filePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
_filePath = filePath;
|
||||
_document = new Document();
|
||||
DefineStyles();
|
||||
}
|
||||
|
||||
public PdfBuilder AddHeader(string header)
|
||||
{
|
||||
_document.AddSection().AddParagraph(header, "NormalBold");
|
||||
return this;
|
||||
}
|
||||
|
||||
public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
var chart = new Chart(ChartType.Pie2D);
|
||||
var series = chart.SeriesCollection.AddSeries();
|
||||
series.Add(data.Select(x => x.Value).ToArray());
|
||||
var xseries = chart.XValues.AddXSeries();
|
||||
xseries.Add(data.Select(x => x.Caption).ToArray());
|
||||
chart.DataLabel.Type = DataLabelType.Percent;
|
||||
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
||||
chart.Width = Unit.FromCentimeter(16);
|
||||
chart.Height = Unit.FromCentimeter(12);
|
||||
chart.TopArea.AddParagraph(title);
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.HasMajorGridlines = true;
|
||||
chart.PlotArea.LineFormat.Width = 1;
|
||||
chart.PlotArea.LineFormat.Visible = true;
|
||||
chart.TopArea.AddLegend();
|
||||
_document.LastSection.Add(chart);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(_filePath);
|
||||
}
|
||||
|
||||
private void DefineStyles()
|
||||
{
|
||||
var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal");
|
||||
headerStyle.Font.Bold = true;
|
||||
headerStyle.Font.Size = 14;
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ internal class TableReport
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по движению топлива", 0, 3)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddTable([ 10, 15, 15], GetData(fuelId, startDate, endDate))
|
||||
.AddTable([10, 15, 15], GetData(fuelId, startDate, endDate))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -42,38 +42,31 @@ internal class TableReport
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<string[]> GetData(int fuelId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var data = _suppliersFuelRepository
|
||||
var suppliersData = _suppliersFuelRepository
|
||||
.ReadSuppliersFuels()
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.SuppliersFuelFuel.Any(y => y.FuelId == fuelId))
|
||||
.Select(x => new { x.Date, CountIn = x.SuppliersFuelFuel.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity, CountOut = (int?)null })
|
||||
.Union(
|
||||
_fuelSalesRepository
|
||||
.Select(x => new { Date = x.Date, CountIn = x.SuppliersFuelFuel.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity, CountOut = (int?)null });
|
||||
|
||||
var salesData = _fuelSalesRepository
|
||||
.ReadFuelSale()
|
||||
.Where(x => x.SaleDate >= startDate && x.SaleDate <= endDate && x.FuelFuelSale.Any(y => y.FuelId == fuelId))
|
||||
.Select(x => new { Date = x.SaleDate, CountIn = (int?)null, CountOut = x.FuelFuelSale.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity })
|
||||
)
|
||||
.OrderBy(x => x.Date);
|
||||
.Select(x => new { Date = x.SaleDate, CountIn = (int?)null, CountOut = x.FuelFuelSale.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity });
|
||||
|
||||
var groupedData = data
|
||||
var combinedData = suppliersData.Union(salesData)
|
||||
.GroupBy(x => x.Date)
|
||||
.Select(g => new
|
||||
{
|
||||
Date = g.Key,
|
||||
TotalIn = g.Sum(x => x.CountIn),
|
||||
TotalOut = g.Sum(x => x.CountOut)
|
||||
})
|
||||
.Select(g => new { Date = g.Key, CountIn = g.Sum(x => x.CountIn ?? 0), CountOut = g.Sum(x => x.CountOut ?? 0) })
|
||||
.OrderBy(x => x.Date);
|
||||
|
||||
return
|
||||
new List<string[]>() { item }
|
||||
.Union(groupedData
|
||||
.Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.TotalIn.ToString()!, x.TotalOut.ToString()! }))
|
||||
return new List<string[]>() { item }
|
||||
.Union(
|
||||
new[] { new string[] { "Всего", groupedData.Sum(x => x.TotalIn).ToString()!, groupedData.Sum(x => x.TotalOut).ToString()! } }
|
||||
)
|
||||
combinedData
|
||||
.Select(x => new string[] { x.Date.ToString(), x.CountIn.ToString(), x.CountOut.ToString() }))
|
||||
.Union(
|
||||
new List<string[]>() { new string[] { "Всего", combinedData.Sum(x => x.CountIn).ToString(), combinedData.Sum(x => x.CountOut).ToString() } })
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ using GasStation.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectGasStation.Entities;
|
||||
|
||||
namespace GasStation.Repositories.Implementations;
|
||||
|
||||
@ -97,11 +98,13 @@ public class FuelSalesRepository : IFuelSalesRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM FuelSale";
|
||||
var fuelSales = connection.Query<FuelSale>(querySelect);
|
||||
var querySelect = @"SELECT fs.*, ffs.FuelId, ffs.Quantity FROM FuelSale fs
|
||||
INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id";
|
||||
var fuelSales = connection.Query<TempFuelFuelSale>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(fuelSales));
|
||||
return fuelSales;
|
||||
return fuelSales.GroupBy(x => x.Id, y => y, (key, value) => FuelSale.CreateElement(value.First(),
|
||||
value.Select(z => FuelFuelSale.CreateFuelFuelSale(0, z.FuelId, z.Quantity,0)))).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user