lab 3 done
This commit is contained in:
parent
8d1763bee7
commit
4662c2e508
@ -40,6 +40,7 @@
|
|||||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
directoryReportToolStripMenuItem = new ToolStripMenuItem();
|
directoryReportToolStripMenuItem = new ToolStripMenuItem();
|
||||||
CarSummaryToolStripMenuItem = new ToolStripMenuItem();
|
CarSummaryToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
kilometersDrovenToolStripMenuItem = new ToolStripMenuItem();
|
||||||
menuStrip.SuspendLayout();
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -97,20 +98,20 @@
|
|||||||
// выездToolStripMenuItem
|
// выездToolStripMenuItem
|
||||||
//
|
//
|
||||||
выездToolStripMenuItem.Name = "выездToolStripMenuItem";
|
выездToolStripMenuItem.Name = "выездToolStripMenuItem";
|
||||||
выездToolStripMenuItem.Size = new Size(125, 22);
|
выездToolStripMenuItem.Size = new Size(180, 22);
|
||||||
выездToolStripMenuItem.Text = "Выезд";
|
выездToolStripMenuItem.Text = "Выезд";
|
||||||
выездToolStripMenuItem.Click += EquipageToolStripMenuItem_Click;
|
выездToolStripMenuItem.Click += EquipageToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// заправкаToolStripMenuItem
|
// заправкаToolStripMenuItem
|
||||||
//
|
//
|
||||||
заправкаToolStripMenuItem.Name = "заправкаToolStripMenuItem";
|
заправкаToolStripMenuItem.Name = "заправкаToolStripMenuItem";
|
||||||
заправкаToolStripMenuItem.Size = new Size(125, 22);
|
заправкаToolStripMenuItem.Size = new Size(180, 22);
|
||||||
заправкаToolStripMenuItem.Text = "Заправка";
|
заправкаToolStripMenuItem.Text = "Заправка";
|
||||||
заправкаToolStripMenuItem.Click += RefuelingToolStripMenuItem_Click;
|
заправкаToolStripMenuItem.Click += RefuelingToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// отчетыToolStripMenuItem
|
// отчетыToolStripMenuItem
|
||||||
//
|
//
|
||||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { directoryReportToolStripMenuItem, CarSummaryToolStripMenuItem });
|
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { directoryReportToolStripMenuItem, CarSummaryToolStripMenuItem, kilometersDrovenToolStripMenuItem });
|
||||||
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
||||||
отчетыToolStripMenuItem.Size = new Size(60, 20);
|
отчетыToolStripMenuItem.Size = new Size(60, 20);
|
||||||
отчетыToolStripMenuItem.Text = "Отчеты";
|
отчетыToolStripMenuItem.Text = "Отчеты";
|
||||||
@ -131,6 +132,14 @@
|
|||||||
CarSummaryToolStripMenuItem.Text = "Сводка по автомобилям";
|
CarSummaryToolStripMenuItem.Text = "Сводка по автомобилям";
|
||||||
CarSummaryToolStripMenuItem.Click += CarSummaryToolStripMenuItem_Click;
|
CarSummaryToolStripMenuItem.Click += CarSummaryToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
// kilometersDrovenToolStripMenuItem
|
||||||
|
//
|
||||||
|
kilometersDrovenToolStripMenuItem.Name = "kilometersDrovenToolStripMenuItem";
|
||||||
|
kilometersDrovenToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
|
||||||
|
kilometersDrovenToolStripMenuItem.Size = new Size(280, 22);
|
||||||
|
kilometersDrovenToolStripMenuItem.Text = "Сводка по километражу";
|
||||||
|
kilometersDrovenToolStripMenuItem.Click += KilometersDrovenToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// FormFuelAccounting
|
// FormFuelAccounting
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -163,5 +172,6 @@
|
|||||||
private ToolStripMenuItem отчетыToolStripMenuItem;
|
private ToolStripMenuItem отчетыToolStripMenuItem;
|
||||||
private ToolStripMenuItem directoryReportToolStripMenuItem;
|
private ToolStripMenuItem directoryReportToolStripMenuItem;
|
||||||
private ToolStripMenuItem CarSummaryToolStripMenuItem;
|
private ToolStripMenuItem CarSummaryToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem kilometersDrovenToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -132,5 +132,18 @@ namespace FuelAccounting
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void KilometersDrovenToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormKilometersDrivenReport>().ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
108
FuelAccounting/FuelAccounting/Forms/FormKilometersDrivenReport.Designer.cs
generated
Normal file
108
FuelAccounting/FuelAccounting/Forms/FormKilometersDrivenReport.Designer.cs
generated
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
namespace FuelAccounting.Forms
|
||||||
|
{
|
||||||
|
partial class FormKilometersDrivenReport
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
buttonSelectFilePath = new Button();
|
||||||
|
labelFileName = new Label();
|
||||||
|
label2 = new Label();
|
||||||
|
dateTimePicker = new DateTimePicker();
|
||||||
|
buttonBuild = new Button();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonSelectFilePath
|
||||||
|
//
|
||||||
|
buttonSelectFilePath.Location = new Point(25, 22);
|
||||||
|
buttonSelectFilePath.Name = "buttonSelectFilePath";
|
||||||
|
buttonSelectFilePath.Size = new Size(98, 35);
|
||||||
|
buttonSelectFilePath.TabIndex = 0;
|
||||||
|
buttonSelectFilePath.Text = "Выбрать";
|
||||||
|
buttonSelectFilePath.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
|
||||||
|
//
|
||||||
|
// labelFileName
|
||||||
|
//
|
||||||
|
labelFileName.AutoSize = true;
|
||||||
|
labelFileName.Location = new Point(150, 32);
|
||||||
|
labelFileName.Name = "labelFileName";
|
||||||
|
labelFileName.Size = new Size(36, 15);
|
||||||
|
labelFileName.TabIndex = 1;
|
||||||
|
labelFileName.Text = "Файл";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(25, 81);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(38, 15);
|
||||||
|
label2.TabIndex = 2;
|
||||||
|
label2.Text = "Дата: ";
|
||||||
|
//
|
||||||
|
// dateTimePicker
|
||||||
|
//
|
||||||
|
dateTimePicker.Location = new Point(69, 75);
|
||||||
|
dateTimePicker.Name = "dateTimePicker";
|
||||||
|
dateTimePicker.Size = new Size(200, 23);
|
||||||
|
dateTimePicker.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonBuild
|
||||||
|
//
|
||||||
|
buttonBuild.Location = new Point(25, 116);
|
||||||
|
buttonBuild.Name = "buttonBuild";
|
||||||
|
buttonBuild.Size = new Size(244, 46);
|
||||||
|
buttonBuild.TabIndex = 4;
|
||||||
|
buttonBuild.Text = "Сформировать";
|
||||||
|
buttonBuild.UseVisualStyleBackColor = true;
|
||||||
|
buttonBuild.Click += ButtonBuild_Click;
|
||||||
|
//
|
||||||
|
// FormKilometersDrivenReport
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(293, 182);
|
||||||
|
Controls.Add(buttonBuild);
|
||||||
|
Controls.Add(dateTimePicker);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(labelFileName);
|
||||||
|
Controls.Add(buttonSelectFilePath);
|
||||||
|
Name = "FormKilometersDrivenReport";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Километров пройдено";
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonSelectFilePath;
|
||||||
|
private Label labelFileName;
|
||||||
|
private Label label2;
|
||||||
|
private DateTimePicker dateTimePicker;
|
||||||
|
private Button buttonBuild;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
using FuelAccounting.Reports;
|
||||||
|
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 Unity;
|
||||||
|
|
||||||
|
namespace FuelAccounting.Forms
|
||||||
|
{
|
||||||
|
public partial class FormKilometersDrivenReport : Form
|
||||||
|
{
|
||||||
|
private string _fileName = string.Empty;
|
||||||
|
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
|
public FormKilometersDrivenReport(IUnityContainer container)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_container = container ??
|
||||||
|
throw new ArgumentNullException(nameof(container));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectFilePath_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
@ -16,6 +16,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Npgsql" Version="9.0.1" />
|
<PackageReference Include="Npgsql" Version="9.0.1" />
|
||||||
|
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||||
|
47
FuelAccounting/FuelAccounting/Reports/ChartReport.cs
Normal file
47
FuelAccounting/FuelAccounting/Reports/ChartReport.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using FuelAccounting.Repositories;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FuelAccounting.Reports;
|
||||||
|
|
||||||
|
internal class ChartReport
|
||||||
|
{
|
||||||
|
private readonly IRefuelingRepository _refuelingRepository;
|
||||||
|
|
||||||
|
private readonly ILogger<ChartReport> _logger;
|
||||||
|
|
||||||
|
public ChartReport(IRefuelingRepository refuelingRepository, ILogger<ChartReport> logger)
|
||||||
|
{
|
||||||
|
_refuelingRepository = refuelingRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(refuelingRepository));
|
||||||
|
_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)
|
||||||
|
{
|
||||||
|
return _refuelingRepository
|
||||||
|
.ReadRefuelings()
|
||||||
|
.Where(x => x.RefuelingDate == dateTime.Date)
|
||||||
|
.GroupBy(x => x.CarId, (key, group) => new { Id = key, Count = group.Sum(x => x.Kilometers) })
|
||||||
|
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
87
FuelAccounting/FuelAccounting/Reports/PdfBuilder.cs
Normal file
87
FuelAccounting/FuelAccounting/Reports/PdfBuilder.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||||
|
using MigraDoc.Rendering;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace FuelAccounting.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)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user