lab-4 add FormReportOrders
This commit is contained in:
parent
b0584bb0f5
commit
ea317508a9
145
BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs
generated
Normal file
145
BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.Designer.cs
generated
Normal file
@ -0,0 +1,145 @@
|
||||
namespace BlacksmithWorkshop
|
||||
{
|
||||
partial class FormReportOrders
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
panelTop = new Panel();
|
||||
ToPdfButton = new Button();
|
||||
MakeButton = new Button();
|
||||
labelUntill = new Label();
|
||||
labelFrom = new Label();
|
||||
dateTimePickerTo = new DateTimePicker();
|
||||
dateTimePickerFrom = new DateTimePicker();
|
||||
panelReport = new Panel();
|
||||
panelTop.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panelTop
|
||||
//
|
||||
panelTop.Controls.Add(ToPdfButton);
|
||||
panelTop.Controls.Add(MakeButton);
|
||||
panelTop.Controls.Add(labelUntill);
|
||||
panelTop.Controls.Add(labelFrom);
|
||||
panelTop.Controls.Add(dateTimePickerTo);
|
||||
panelTop.Controls.Add(dateTimePickerFrom);
|
||||
panelTop.Location = new Point(14, 16);
|
||||
panelTop.Margin = new Padding(3, 4, 3, 4);
|
||||
panelTop.Name = "panelTop";
|
||||
panelTop.Size = new Size(887, 57);
|
||||
panelTop.TabIndex = 0;
|
||||
//
|
||||
// ToPdfButton
|
||||
//
|
||||
ToPdfButton.Location = new Point(712, 23);
|
||||
ToPdfButton.Margin = new Padding(3, 4, 3, 4);
|
||||
ToPdfButton.Name = "ToPdfButton";
|
||||
ToPdfButton.Size = new Size(171, 31);
|
||||
ToPdfButton.TabIndex = 5;
|
||||
ToPdfButton.Text = "В Pdf";
|
||||
ToPdfButton.UseVisualStyleBackColor = true;
|
||||
ToPdfButton.Click += ButtonToPdf_Click;
|
||||
//
|
||||
// MakeButton
|
||||
//
|
||||
MakeButton.Location = new Point(537, 23);
|
||||
MakeButton.Margin = new Padding(3, 4, 3, 4);
|
||||
MakeButton.Name = "MakeButton";
|
||||
MakeButton.Size = new Size(168, 31);
|
||||
MakeButton.TabIndex = 4;
|
||||
MakeButton.Text = "Сформировать";
|
||||
MakeButton.UseVisualStyleBackColor = true;
|
||||
MakeButton.Click += MakeButton_Click;
|
||||
//
|
||||
// labelUntill
|
||||
//
|
||||
labelUntill.AutoSize = true;
|
||||
labelUntill.Location = new Point(269, 31);
|
||||
labelUntill.Name = "labelUntill";
|
||||
labelUntill.Size = new Size(29, 20);
|
||||
labelUntill.TabIndex = 3;
|
||||
labelUntill.Text = "По";
|
||||
//
|
||||
// labelFrom
|
||||
//
|
||||
labelFrom.AutoSize = true;
|
||||
labelFrom.Location = new Point(9, 31);
|
||||
labelFrom.Name = "labelFrom";
|
||||
labelFrom.Size = new Size(18, 20);
|
||||
labelFrom.TabIndex = 2;
|
||||
labelFrom.Text = "С";
|
||||
//
|
||||
// dateTimePickerTo
|
||||
//
|
||||
dateTimePickerTo.Location = new Point(302, 23);
|
||||
dateTimePickerTo.Margin = new Padding(3, 4, 3, 4);
|
||||
dateTimePickerTo.Name = "dateTimePickerTo";
|
||||
dateTimePickerTo.Size = new Size(228, 27);
|
||||
dateTimePickerTo.TabIndex = 1;
|
||||
//
|
||||
// dateTimePickerFrom
|
||||
//
|
||||
dateTimePickerFrom.Location = new Point(33, 23);
|
||||
dateTimePickerFrom.Margin = new Padding(3, 4, 3, 4);
|
||||
dateTimePickerFrom.Name = "dateTimePickerFrom";
|
||||
dateTimePickerFrom.Size = new Size(228, 27);
|
||||
dateTimePickerFrom.TabIndex = 0;
|
||||
//
|
||||
// panelReport
|
||||
//
|
||||
panelReport.Location = new Point(14, 80);
|
||||
panelReport.Name = "panelReport";
|
||||
panelReport.Size = new Size(888, 508);
|
||||
panelReport.TabIndex = 1;
|
||||
//
|
||||
// FormReportOrders
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 600);
|
||||
Controls.Add(panelReport);
|
||||
Controls.Add(panelTop);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormReportOrders";
|
||||
Text = "Заказы";
|
||||
panelTop.ResumeLayout(false);
|
||||
panelTop.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panelTop;
|
||||
private Button ToPdfButton;
|
||||
private Button MakeButton;
|
||||
private Label labelUntill;
|
||||
private Label labelFrom;
|
||||
private DateTimePicker dateTimePickerTo;
|
||||
private DateTimePicker dateTimePickerFrom;
|
||||
private Panel panelReport;
|
||||
}
|
||||
}
|
100
BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs
Normal file
100
BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using BlacksmithWorkshopContracts.BindingModels;
|
||||
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
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;
|
||||
|
||||
namespace BlacksmithWorkshop
|
||||
{
|
||||
public partial class FormReportOrders : Form
|
||||
{
|
||||
private readonly ReportViewer reportViewer;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReportLogic _logic;
|
||||
public FormReportOrders(ILogger<FormReportOrders> logger, IReportLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
reportViewer = new ReportViewer
|
||||
{
|
||||
Dock = DockStyle.Fill
|
||||
};
|
||||
reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open));
|
||||
panelReport.Controls.Add(reportViewer);
|
||||
}
|
||||
|
||||
private void MakeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
|
||||
{
|
||||
MessageBox.Show("Дата начала должна быть меньше даты окончания",
|
||||
"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var dataSource = _logic.GetOrders(new ReportBindingModel
|
||||
{
|
||||
DateFrom = dateTimePickerFrom.Value,
|
||||
DateTo = dateTimePickerTo.Value
|
||||
});
|
||||
var source = new ReportDataSource("DataSetOrders", dataSource);
|
||||
reportViewer.LocalReport.DataSources.Clear();
|
||||
reportViewer.LocalReport.DataSources.Add(source);
|
||||
var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") };
|
||||
reportViewer.LocalReport.SetParameters(parameters);
|
||||
reportViewer.RefreshReport();
|
||||
_logger.LogInformation("Загрузка списка заказов на период {From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(),
|
||||
dateTimePickerTo.Value.ToShortDateString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка заказов на период");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonToPdf_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
|
||||
{
|
||||
MessageBox.Show("Дата начала должна быть меньше даты окончания",
|
||||
"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "pdf|*.pdf"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SaveOrdersToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName,
|
||||
DateFrom = dateTimePickerFrom.Value,
|
||||
DateTo = dateTimePickerTo.Value
|
||||
});
|
||||
_logger.LogInformation("Сохранение списка заказов на период { From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(),
|
||||
dateTimePickerTo.Value.ToShortDateString());
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.resx
Normal file
120
BlacksmithWorkshop/BlacksmithWorkshop/FormReportOrders.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>
|
@ -36,7 +36,7 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ComputerName, order.Sum.ToString(), order.OrderStatus.ToString() },
|
||||
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ManufactureName, order.Sum.ToString(), order.OrderStatus.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user