Реализовали создание диагарммы по операции пополнение денег
This commit is contained in:
parent
d7ab5542d1
commit
06d1a0d610
12
project/ProjectTourAgency/FormTourAgency.Designer.cs
generated
12
project/ProjectTourAgency/FormTourAgency.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
турToolStripMenuItem = new ToolStripMenuItem();
|
||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
||||
DirectoryReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
AddMoneyReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -103,7 +104,7 @@
|
||||
//
|
||||
// отчетыToolStripMenuItem
|
||||
//
|
||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem });
|
||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, AddMoneyReportToolStripMenuItem });
|
||||
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
||||
отчетыToolStripMenuItem.Size = new Size(88, 29);
|
||||
отчетыToolStripMenuItem.Text = "Отчеты";
|
||||
@ -116,6 +117,14 @@
|
||||
DirectoryReportToolStripMenuItem.Text = "Документы со справочниками";
|
||||
DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
|
||||
//
|
||||
// AddMoneyReportToolStripMenuItem
|
||||
//
|
||||
AddMoneyReportToolStripMenuItem.Name = "AddMoneyReportToolStripMenuItem";
|
||||
AddMoneyReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
|
||||
AddMoneyReportToolStripMenuItem.Size = new Size(434, 34);
|
||||
AddMoneyReportToolStripMenuItem.Text = "Денежная диаграмма";
|
||||
AddMoneyReportToolStripMenuItem.Click += AddMoneyReportToolStripMenuItem_Click;
|
||||
//
|
||||
// FormTourAgency
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
@ -148,5 +157,6 @@
|
||||
private ToolStripMenuItem пополнитьБалансПользователяToolStripMenuItem;
|
||||
private ToolStripMenuItem турToolStripMenuItem;
|
||||
private ToolStripMenuItem DirectoryReportToolStripMenuItem;
|
||||
private ToolStripMenuItem AddMoneyReportToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
@ -85,4 +85,16 @@ public partial class FormTourAgency : Form
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddMoneyReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormAddMoneyReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,4 +120,7 @@
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>32</value>
|
||||
</metadata>
|
||||
</root>
|
107
project/ProjectTourAgency/Forms/FormAddMoneyReport.Designer.cs
generated
Normal file
107
project/ProjectTourAgency/Forms/FormAddMoneyReport.Designer.cs
generated
Normal file
@ -0,0 +1,107 @@
|
||||
namespace ProjectTourAgency.Forms
|
||||
{
|
||||
partial class FormAddMoneyReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dateTimePicker1 = new DateTimePicker();
|
||||
buttonSelectFileName = new Button();
|
||||
buttonCreate = new Button();
|
||||
labelFileName = new Label();
|
||||
labelDate = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dateTimePicker1
|
||||
//
|
||||
dateTimePicker1.Location = new Point(102, 123);
|
||||
dateTimePicker1.Name = "dateTimePicker1";
|
||||
dateTimePicker1.Size = new Size(222, 31);
|
||||
dateTimePicker1.TabIndex = 0;
|
||||
//
|
||||
// buttonSelectFileName
|
||||
//
|
||||
buttonSelectFileName.Location = new Point(43, 50);
|
||||
buttonSelectFileName.Name = "buttonSelectFileName";
|
||||
buttonSelectFileName.Size = new Size(112, 34);
|
||||
buttonSelectFileName.TabIndex = 1;
|
||||
buttonSelectFileName.Text = "Выбрать";
|
||||
buttonSelectFileName.UseVisualStyleBackColor = true;
|
||||
buttonSelectFileName.Click += buttonSelectFileName_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(43, 195);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(144, 34);
|
||||
buttonCreate.TabIndex = 2;
|
||||
buttonCreate.Text = "Сформировать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// labelFileName
|
||||
//
|
||||
labelFileName.AutoSize = true;
|
||||
labelFileName.Location = new Point(193, 55);
|
||||
labelFileName.Name = "labelFileName";
|
||||
labelFileName.Size = new Size(53, 25);
|
||||
labelFileName.TabIndex = 3;
|
||||
labelFileName.Text = "Файл";
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
labelDate.AutoSize = true;
|
||||
labelDate.Location = new Point(43, 123);
|
||||
labelDate.Name = "labelDate";
|
||||
labelDate.Size = new Size(53, 25);
|
||||
labelDate.TabIndex = 4;
|
||||
labelDate.Text = "Дата:";
|
||||
//
|
||||
// FormAddMoneyReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(446, 269);
|
||||
Controls.Add(labelDate);
|
||||
Controls.Add(labelFileName);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonSelectFileName);
|
||||
Controls.Add(dateTimePicker1);
|
||||
Name = "FormAddMoneyReport";
|
||||
Text = "FormAddMoneyReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker dateTimePicker1;
|
||||
private Button buttonSelectFileName;
|
||||
private Button buttonCreate;
|
||||
private Label labelFileName;
|
||||
private Label labelDate;
|
||||
}
|
||||
}
|
66
project/ProjectTourAgency/Forms/FormAddMoneyReport.cs
Normal file
66
project/ProjectTourAgency/Forms/FormAddMoneyReport.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using ProjectTourAgency.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 ProjectTourAgency.Forms
|
||||
{
|
||||
public partial class FormAddMoneyReport : Form
|
||||
{
|
||||
private string _fileName = string.Empty;
|
||||
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormAddMoneyReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
private void buttonSelectFileName_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 buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_fileName))
|
||||
{
|
||||
throw new Exception("Отсутсвует имя файла для отчета");
|
||||
}
|
||||
if (_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePicker1.Value))
|
||||
{
|
||||
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", "Формирование документа",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
project/ProjectTourAgency/Forms/FormAddMoneyReport.resx
Normal file
120
project/ProjectTourAgency/Forms/FormAddMoneyReport.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>
|
52
project/ProjectTourAgency/Reports/ChartReport.cs
Normal file
52
project/ProjectTourAgency/Reports/ChartReport.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectTourAgency.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTourAgency.Reports;
|
||||
|
||||
internal class ChartReport
|
||||
{
|
||||
private readonly IAddMoneyRepository _addMoneyRepository;
|
||||
|
||||
private readonly ILogger<ChartReport> _logger;
|
||||
|
||||
public ChartReport(IAddMoneyRepository addMoneyRepository, ILogger<ChartReport> logger)
|
||||
{
|
||||
_addMoneyRepository = addMoneyRepository ??
|
||||
throw new ArgumentNullException(nameof(addMoneyRepository));
|
||||
_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 _addMoneyRepository
|
||||
.ReadAddMoneys()
|
||||
.Where(x => x.Date.Date == dateTime.Date)
|
||||
.GroupBy(x => x.ClientId, (key, group) => new { Id = key, Count = group.Count() })
|
||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||
.ToList();
|
||||
}
|
||||
}
|
@ -33,13 +33,7 @@ internal class TableReport
|
||||
{
|
||||
try
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по операциям пополнения", 0, 4)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddTable([15, 15, 15, 15], GetData(addMoneyId, startDate, endDate))
|
||||
.Build();
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -48,13 +42,7 @@ internal class TableReport
|
||||
}
|
||||
}
|
||||
|
||||
private List<string[]> GetData(int addMoneyId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var data = _addMoneyRepository
|
||||
.ReadAddMoneys()
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user