Lab3 alpha
This commit is contained in:
parent
0795b2dc32
commit
afda388a78
34
Workshop/FormWorkshop.Designer.cs
generated
34
Workshop/FormWorkshop.Designer.cs
generated
@ -37,6 +37,9 @@
|
||||
ProductCreateToolStripMenuItem = new ToolStripMenuItem();
|
||||
ChequeToolStripMenuItem = new ToolStripMenuItem();
|
||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
||||
EntitiesReport = new ToolStripMenuItem();
|
||||
ProductsMoveToolStripMenuItem = new ToolStripMenuItem();
|
||||
ProdCreateToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -59,21 +62,21 @@
|
||||
// ProductstoolStripMenuItem
|
||||
//
|
||||
ProductstoolStripMenuItem.Name = "ProductstoolStripMenuItem";
|
||||
ProductstoolStripMenuItem.Size = new Size(180, 22);
|
||||
ProductstoolStripMenuItem.Size = new Size(138, 22);
|
||||
ProductstoolStripMenuItem.Text = "Изделия";
|
||||
ProductstoolStripMenuItem.Click += ProductstoolStripMenuItem_Click;
|
||||
//
|
||||
// MastersToolStripMenuItem
|
||||
//
|
||||
MastersToolStripMenuItem.Name = "MastersToolStripMenuItem";
|
||||
MastersToolStripMenuItem.Size = new Size(180, 22);
|
||||
MastersToolStripMenuItem.Size = new Size(138, 22);
|
||||
MastersToolStripMenuItem.Text = "Мастера";
|
||||
MastersToolStripMenuItem.Click += MastersToolStripMenuItem_Click;
|
||||
//
|
||||
// MaterialsToolStripMenuItem
|
||||
//
|
||||
MaterialsToolStripMenuItem.Name = "MaterialsToolStripMenuItem";
|
||||
MaterialsToolStripMenuItem.Size = new Size(180, 22);
|
||||
MaterialsToolStripMenuItem.Size = new Size(138, 22);
|
||||
MaterialsToolStripMenuItem.Text = "Материалы";
|
||||
MaterialsToolStripMenuItem.Click += MaterialsToolStripMenuItem_Click;
|
||||
//
|
||||
@ -100,10 +103,32 @@
|
||||
//
|
||||
// отчетыToolStripMenuItem
|
||||
//
|
||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { EntitiesReport, ProductsMoveToolStripMenuItem, ProdCreateToolStripMenuItem });
|
||||
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
||||
отчетыToolStripMenuItem.Size = new Size(60, 20);
|
||||
отчетыToolStripMenuItem.Text = "Отчеты";
|
||||
//
|
||||
// EntitiesReport
|
||||
//
|
||||
EntitiesReport.Name = "EntitiesReport";
|
||||
EntitiesReport.Size = new Size(235, 22);
|
||||
EntitiesReport.Text = "Документ со справочниками";
|
||||
EntitiesReport.Click += EntitiesReport_Click;
|
||||
//
|
||||
// ProductsMoveToolStripMenuItem
|
||||
//
|
||||
ProductsMoveToolStripMenuItem.Name = "ProductsMoveToolStripMenuItem";
|
||||
ProductsMoveToolStripMenuItem.Size = new Size(235, 22);
|
||||
ProductsMoveToolStripMenuItem.Text = "Движение изделий";
|
||||
ProductsMoveToolStripMenuItem.Click += ProductsMoveToolStripMenuItem_Click;
|
||||
//
|
||||
// ProdCreateToolStripMenuItem
|
||||
//
|
||||
ProdCreateToolStripMenuItem.Name = "ProdCreateToolStripMenuItem";
|
||||
ProdCreateToolStripMenuItem.Size = new Size(235, 22);
|
||||
ProdCreateToolStripMenuItem.Text = "Создание изделий";
|
||||
ProdCreateToolStripMenuItem.Click += ProdCreateToolStripMenuItem_Click;
|
||||
//
|
||||
// FormWorkshop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -133,5 +158,8 @@
|
||||
private ToolStripMenuItem MaterialsToolStripMenuItem;
|
||||
private ToolStripMenuItem ProductCreateToolStripMenuItem;
|
||||
private ToolStripMenuItem ChequeToolStripMenuItem;
|
||||
private ToolStripMenuItem EntitiesReport;
|
||||
private ToolStripMenuItem ProductsMoveToolStripMenuItem;
|
||||
private ToolStripMenuItem ProdCreateToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
@ -73,5 +73,41 @@ namespace Workshop
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void EntitiesReport_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormDirectoryReport>().ShowDialog();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProductsMoveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormProductReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProdCreateToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormProductCreateReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
99
Workshop/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
99
Workshop/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
@ -0,0 +1,99 @@
|
||||
namespace Workshop.Forms
|
||||
{
|
||||
partial class FormDirectoryReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
checkBoxProduct = new CheckBox();
|
||||
checkBoxMasters = new CheckBox();
|
||||
checkBoxMaterials = new CheckBox();
|
||||
buttonMakeReport = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkBoxProduct
|
||||
//
|
||||
checkBoxProduct.AutoSize = true;
|
||||
checkBoxProduct.Location = new Point(38, 37);
|
||||
checkBoxProduct.Name = "checkBoxProduct";
|
||||
checkBoxProduct.Size = new Size(72, 19);
|
||||
checkBoxProduct.TabIndex = 0;
|
||||
checkBoxProduct.Text = "Изделия";
|
||||
checkBoxProduct.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxMasters
|
||||
//
|
||||
checkBoxMasters.AutoSize = true;
|
||||
checkBoxMasters.Location = new Point(38, 88);
|
||||
checkBoxMasters.Name = "checkBoxMasters";
|
||||
checkBoxMasters.Size = new Size(73, 19);
|
||||
checkBoxMasters.TabIndex = 1;
|
||||
checkBoxMasters.Text = "Мастера";
|
||||
checkBoxMasters.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxMaterials
|
||||
//
|
||||
checkBoxMaterials.AutoSize = true;
|
||||
checkBoxMaterials.Location = new Point(38, 141);
|
||||
checkBoxMaterials.Name = "checkBoxMaterials";
|
||||
checkBoxMaterials.Size = new Size(90, 19);
|
||||
checkBoxMaterials.TabIndex = 2;
|
||||
checkBoxMaterials.Text = "Материалы";
|
||||
checkBoxMaterials.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonMakeReport
|
||||
//
|
||||
buttonMakeReport.Location = new Point(168, 75);
|
||||
buttonMakeReport.Name = "buttonMakeReport";
|
||||
buttonMakeReport.Size = new Size(110, 43);
|
||||
buttonMakeReport.TabIndex = 3;
|
||||
buttonMakeReport.Text = "Сформировать отчёт";
|
||||
buttonMakeReport.UseVisualStyleBackColor = true;
|
||||
buttonMakeReport.Click += buttonMakeReport_Click;
|
||||
//
|
||||
// FormDirectoryReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(327, 201);
|
||||
Controls.Add(buttonMakeReport);
|
||||
Controls.Add(checkBoxMaterials);
|
||||
Controls.Add(checkBoxMasters);
|
||||
Controls.Add(checkBoxProduct);
|
||||
Name = "FormDirectoryReport";
|
||||
Text = "Выбор отчёта";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckBox checkBoxProduct;
|
||||
private CheckBox checkBoxMasters;
|
||||
private CheckBox checkBoxMaterials;
|
||||
private Button buttonMakeReport;
|
||||
}
|
||||
}
|
63
Workshop/Forms/FormDirectoryReport.cs
Normal file
63
Workshop/Forms/FormDirectoryReport.cs
Normal file
@ -0,0 +1,63 @@
|
||||
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;
|
||||
using Workshop.Reports;
|
||||
|
||||
namespace Workshop.Forms;
|
||||
|
||||
public partial class FormDirectoryReport : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
public FormDirectoryReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
private void buttonMakeReport_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!checkBoxProduct.Checked &&
|
||||
!checkBoxMaterials.Checked && !checkBoxMasters.Checked)
|
||||
{
|
||||
throw new Exception("Не выбран ни один справочник для выгрузки");
|
||||
}
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Docx Files | *.docx"
|
||||
};
|
||||
if (sfd.ShowDialog() != DialogResult.OK)
|
||||
{
|
||||
throw new Exception("Не выбран файла для отчета");
|
||||
}
|
||||
if
|
||||
(_container.Resolve<DocReport>().CreateDock(sfd.FileName, checkBoxProduct.Checked, checkBoxMasters.Checked,
|
||||
checkBoxMaterials.Checked))
|
||||
{
|
||||
MessageBox.Show("Документ сформирован",
|
||||
"Формирование документа",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах",
|
||||
"Формирование документа",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
120
Workshop/Forms/FormDirectoryReport.resx
Normal file
120
Workshop/Forms/FormDirectoryReport.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>
|
107
Workshop/Forms/FormProductCreateReport.Designer.cs
generated
Normal file
107
Workshop/Forms/FormProductCreateReport.Designer.cs
generated
Normal file
@ -0,0 +1,107 @@
|
||||
namespace Workshop.Forms
|
||||
{
|
||||
partial class FormProductCreateReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
buttonSelectFile = new Button();
|
||||
labelText = new Label();
|
||||
labelDate = new Label();
|
||||
dateTimePickerCreate = new DateTimePicker();
|
||||
buttonMakeReport = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonSelectFile
|
||||
//
|
||||
buttonSelectFile.Location = new Point(28, 21);
|
||||
buttonSelectFile.Name = "buttonSelectFile";
|
||||
buttonSelectFile.Size = new Size(75, 23);
|
||||
buttonSelectFile.TabIndex = 0;
|
||||
buttonSelectFile.Text = "Выбрать";
|
||||
buttonSelectFile.UseVisualStyleBackColor = true;
|
||||
buttonSelectFile.Click += buttonSelectFile_Click;
|
||||
//
|
||||
// labelText
|
||||
//
|
||||
labelText.AutoSize = true;
|
||||
labelText.Location = new Point(122, 25);
|
||||
labelText.Name = "labelText";
|
||||
labelText.Size = new Size(36, 15);
|
||||
labelText.TabIndex = 1;
|
||||
labelText.Text = "Файл";
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
labelDate.AutoSize = true;
|
||||
labelDate.Location = new Point(28, 69);
|
||||
labelDate.Name = "labelDate";
|
||||
labelDate.Size = new Size(35, 15);
|
||||
labelDate.TabIndex = 2;
|
||||
labelDate.Text = "Дата:";
|
||||
//
|
||||
// dateTimePickerCreate
|
||||
//
|
||||
dateTimePickerCreate.Location = new Point(69, 63);
|
||||
dateTimePickerCreate.Name = "dateTimePickerCreate";
|
||||
dateTimePickerCreate.Size = new Size(200, 23);
|
||||
dateTimePickerCreate.TabIndex = 3;
|
||||
//
|
||||
// buttonMakeReport
|
||||
//
|
||||
buttonMakeReport.Location = new Point(94, 107);
|
||||
buttonMakeReport.Name = "buttonMakeReport";
|
||||
buttonMakeReport.Size = new Size(106, 23);
|
||||
buttonMakeReport.TabIndex = 4;
|
||||
buttonMakeReport.Text = "Сформировать";
|
||||
buttonMakeReport.UseVisualStyleBackColor = true;
|
||||
buttonMakeReport.Click += buttonMakeReport_Click;
|
||||
//
|
||||
// FormProductCreateReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(300, 153);
|
||||
Controls.Add(buttonMakeReport);
|
||||
Controls.Add(dateTimePickerCreate);
|
||||
Controls.Add(labelDate);
|
||||
Controls.Add(labelText);
|
||||
Controls.Add(buttonSelectFile);
|
||||
Name = "FormProductCreateReport";
|
||||
Text = "FormProductCreateReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonSelectFile;
|
||||
private Label labelText;
|
||||
private Label labelDate;
|
||||
private DateTimePicker dateTimePickerCreate;
|
||||
private Button buttonMakeReport;
|
||||
}
|
||||
}
|
59
Workshop/Forms/FormProductCreateReport.cs
Normal file
59
Workshop/Forms/FormProductCreateReport.cs
Normal file
@ -0,0 +1,59 @@
|
||||
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;
|
||||
using Workshop.Reports;
|
||||
|
||||
namespace Workshop.Forms;
|
||||
|
||||
public partial class FormProductCreateReport : Form
|
||||
{
|
||||
private string _fileName = string.Empty;
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormProductCreateReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
private void buttonMakeReport_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_fileName))
|
||||
throw new Exception("Отсутствует имя файла для отчета");
|
||||
if (_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePickerCreate.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);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Pdf Files | *.pdf"
|
||||
};
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_fileName = sfd.FileName;
|
||||
labelDate.Text = Path.GetFileName(_fileName);
|
||||
}
|
||||
}
|
||||
}
|
120
Workshop/Forms/FormProductCreateReport.resx
Normal file
120
Workshop/Forms/FormProductCreateReport.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>
|
172
Workshop/Forms/FormProductReport.Designer.cs
generated
Normal file
172
Workshop/Forms/FormProductReport.Designer.cs
generated
Normal file
@ -0,0 +1,172 @@
|
||||
namespace Workshop.Forms
|
||||
{
|
||||
partial class FormProductReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
label3 = new Label();
|
||||
label4 = new Label();
|
||||
textBoxDirectory = new TextBox();
|
||||
buttonDirectoryDialog = new Button();
|
||||
comboBoxProduct = new ComboBox();
|
||||
dateTimePickerStart = new DateTimePicker();
|
||||
dateTimePickerEnd = new DateTimePicker();
|
||||
buttonMakeReport = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.Anchor = AnchorStyles.Left;
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(34, 32);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(87, 15);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Путь до файла";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.Anchor = AnchorStyles.Left;
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(34, 67);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(53, 15);
|
||||
label2.TabIndex = 1;
|
||||
label2.Text = "Изделие";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.Anchor = AnchorStyles.Left;
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(34, 107);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(74, 15);
|
||||
label3.TabIndex = 2;
|
||||
label3.Text = "Дата начала";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.Anchor = AnchorStyles.Left;
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(34, 143);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(68, 15);
|
||||
label4.TabIndex = 3;
|
||||
label4.Text = "Дата конца";
|
||||
//
|
||||
// textBoxDirectory
|
||||
//
|
||||
textBoxDirectory.Anchor = AnchorStyles.Right;
|
||||
textBoxDirectory.Location = new Point(127, 29);
|
||||
textBoxDirectory.Name = "textBoxDirectory";
|
||||
textBoxDirectory.Size = new Size(132, 23);
|
||||
textBoxDirectory.TabIndex = 4;
|
||||
//
|
||||
// buttonDirectoryDialog
|
||||
//
|
||||
buttonDirectoryDialog.Anchor = AnchorStyles.Right;
|
||||
buttonDirectoryDialog.Location = new Point(265, 29);
|
||||
buttonDirectoryDialog.Name = "buttonDirectoryDialog";
|
||||
buttonDirectoryDialog.Size = new Size(27, 23);
|
||||
buttonDirectoryDialog.TabIndex = 5;
|
||||
buttonDirectoryDialog.Text = "...";
|
||||
buttonDirectoryDialog.UseVisualStyleBackColor = true;
|
||||
buttonDirectoryDialog.Click += buttonDirectoryDialog_Click;
|
||||
//
|
||||
// comboBoxProduct
|
||||
//
|
||||
comboBoxProduct.Anchor = AnchorStyles.Right;
|
||||
comboBoxProduct.FormattingEnabled = true;
|
||||
comboBoxProduct.Location = new Point(127, 64);
|
||||
comboBoxProduct.Name = "comboBoxProduct";
|
||||
comboBoxProduct.Size = new Size(132, 23);
|
||||
comboBoxProduct.TabIndex = 6;
|
||||
//
|
||||
// dateTimePickerStart
|
||||
//
|
||||
dateTimePickerStart.Anchor = AnchorStyles.Right;
|
||||
dateTimePickerStart.Location = new Point(127, 101);
|
||||
dateTimePickerStart.Name = "dateTimePickerStart";
|
||||
dateTimePickerStart.Size = new Size(165, 23);
|
||||
dateTimePickerStart.TabIndex = 7;
|
||||
//
|
||||
// dateTimePickerEnd
|
||||
//
|
||||
dateTimePickerEnd.Anchor = AnchorStyles.Right;
|
||||
dateTimePickerEnd.Location = new Point(127, 137);
|
||||
dateTimePickerEnd.Name = "dateTimePickerEnd";
|
||||
dateTimePickerEnd.Size = new Size(165, 23);
|
||||
dateTimePickerEnd.TabIndex = 8;
|
||||
//
|
||||
// buttonMakeReport
|
||||
//
|
||||
buttonMakeReport.Anchor = AnchorStyles.Right;
|
||||
buttonMakeReport.Location = new Point(114, 169);
|
||||
buttonMakeReport.Name = "buttonMakeReport";
|
||||
buttonMakeReport.Size = new Size(120, 23);
|
||||
buttonMakeReport.TabIndex = 9;
|
||||
buttonMakeReport.Text = "Сформировать";
|
||||
buttonMakeReport.UseVisualStyleBackColor = true;
|
||||
buttonMakeReport.Click += buttonMakeReport_Click;
|
||||
//
|
||||
// FormProductReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(346, 204);
|
||||
Controls.Add(buttonMakeReport);
|
||||
Controls.Add(dateTimePickerEnd);
|
||||
Controls.Add(dateTimePickerStart);
|
||||
Controls.Add(comboBoxProduct);
|
||||
Controls.Add(buttonDirectoryDialog);
|
||||
Controls.Add(textBoxDirectory);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Name = "FormProductReport";
|
||||
Text = "Отчет по изделию";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private Label label4;
|
||||
private TextBox textBoxDirectory;
|
||||
private Button buttonDirectoryDialog;
|
||||
private ComboBox comboBoxProduct;
|
||||
private DateTimePicker dateTimePickerStart;
|
||||
private DateTimePicker dateTimePickerEnd;
|
||||
private Button buttonMakeReport;
|
||||
}
|
||||
}
|
77
Workshop/Forms/FormProductReport.cs
Normal file
77
Workshop/Forms/FormProductReport.cs
Normal file
@ -0,0 +1,77 @@
|
||||
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;
|
||||
using Workshop.Reports;
|
||||
using Workshop.Repositories;
|
||||
|
||||
namespace Workshop.Forms
|
||||
{
|
||||
public partial class FormProductReport : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
public FormProductReport(IUnityContainer container, IProductRepository productRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
comboBoxProduct.DataSource = productRepository.ReadProducts();
|
||||
comboBoxProduct.DisplayMember = "Name";
|
||||
comboBoxProduct.ValueMember = "Id";
|
||||
}
|
||||
|
||||
private void buttonMakeReport_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxDirectory.Text))
|
||||
{
|
||||
throw new Exception("Отсутствует имя файла для отчета");
|
||||
}
|
||||
if (comboBoxProduct.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Не выбрано изделие");
|
||||
}
|
||||
if (dateTimePickerEnd.Value <= dateTimePickerStart.Value)
|
||||
{
|
||||
throw new Exception("Дата начала должна быть раньше даты окончания");
|
||||
}
|
||||
if (_container.Resolve<TableReport>().CreateTable(textBoxDirectory.Text,
|
||||
(int)comboBoxProduct.SelectedValue!, dateTimePickerStart.Value, dateTimePickerEnd.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 buttonDirectoryDialog_Click(object sender, EventArgs e)
|
||||
{
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Excel Files | *.xlsx"
|
||||
};
|
||||
if (sfd.ShowDialog() != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
textBoxDirectory.Text = sfd.FileName;
|
||||
}
|
||||
}
|
||||
}
|
120
Workshop/Forms/FormProductReport.resx
Normal file
120
Workshop/Forms/FormProductReport.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>
|
56
Workshop/Reports/ChartReport.cs
Normal file
56
Workshop/Reports/ChartReport.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Workshop.Repositories;
|
||||
|
||||
namespace Workshop.Reports;
|
||||
internal class ChartReport
|
||||
{
|
||||
private readonly IProductCreateRepository _creatingRepository;
|
||||
private readonly ILogger<ChartReport> _logger;
|
||||
public ChartReport(IProductCreateRepository creatingRepository, ILogger<ChartReport> logger)
|
||||
{
|
||||
_creatingRepository = creatingRepository ?? throw new ArgumentNullException(nameof(creatingRepository));
|
||||
_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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных о изделиях и их кол-ве из операций создания
|
||||
/// </summary>
|
||||
/// <param name="dateTimeStart">Дата начала</param>
|
||||
/// <param name="dateTimeEnd">Дата окончания</param>
|
||||
/// <returns>Список пар строка-количество с Id изделия и количество его созданий</returns>
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _creatingRepository
|
||||
.ReadProductCreates()
|
||||
.Where(x => x.CreatingDate == dateTime)
|
||||
.GroupBy(x => x.ProductId, (key, group) => new
|
||||
{
|
||||
Id = key,
|
||||
Count = group.Count()
|
||||
})
|
||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||
.ToList();
|
||||
}
|
||||
}
|
73
Workshop/Reports/PDFBuilder.cs
Normal file
73
Workshop/Reports/PDFBuilder.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Workshop.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()
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer()
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(_filePath);
|
||||
}
|
||||
private void DefineStyles()
|
||||
{
|
||||
var style = _document.Styles.AddStyle("NormalBold", "Normal");
|
||||
style.Font.Bold = true;
|
||||
style.Font.Size = 16;
|
||||
style.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user