From 7b727b6b8fef248e266bf1a779133b373d949c9f Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Wed, 1 Mar 2023 15:55:49 +0400 Subject: [PATCH] =?UTF-8?q?Pdf:=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D1=8B=20=D0=B2=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=20=D0=B8=20=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssembly/FormMain.Designer.cs | 1 + .../FurnitureAssembly/FormMain.cs | 9 + .../FormReportCountOrdersByPeriod.Designer.cs | 167 +++++++ .../FormReportCountOrdersByPeriod.cs | 100 ++++ .../FormReportCountOrdersByPeriod.resx | 60 +++ .../FurnitureAssembly.csproj | 4 + .../FurnitureAssembly/Program.cs | 1 + .../FurnitureAssembly/ReportOrdersCount.rdlc | 459 ++++++++++++++++++ .../OfficePackage/AbstractSaveToPdf.cs | 66 ++- .../OfficePackage/HelperModels/PdfInfo.cs | 1 - .../HelperModels/PdfInfoCountOrders.cs | 14 + .../HelperModels/PdfInfoOrders.cs | 14 + .../ReportLogic.cs | 23 +- .../BusinessLogicsContarcts/IReportLogic.cs | 8 +- .../ViewModels/ReportCountOrdersViewModel.cs | 15 + 15 files changed, 937 insertions(+), 5 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.resx create mode 100644 FurnitureAssembly/FurnitureAssembly/ReportOrdersCount.rdlc create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfoCountOrders.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportCountOrdersViewModel.cs diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index 849bbff..25c1e5c 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -214,6 +214,7 @@ this.OrderDateToolStripMenuItem.Name = "OrderDateToolStripMenuItem"; this.OrderDateToolStripMenuItem.Size = new System.Drawing.Size(216, 22); this.OrderDateToolStripMenuItem.Text = "Список заказов по датам"; + this.OrderDateToolStripMenuItem.Click += new System.EventHandler(this.OrderDateToolStripMenuItem_Click); // // buttonSell // diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 14d6c1d..aff2407 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -243,5 +243,14 @@ namespace FurnitureAssembly form.ShowDialog(); } } + + private void OrderDateToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportCountOrdersByPeriod)); + if (service is FormReportCountOrdersByPeriod form) + { + form.ShowDialog(); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.Designer.cs new file mode 100644 index 0000000..cf6cc18 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.Designer.cs @@ -0,0 +1,167 @@ +namespace FurnitureAssembly +{ + partial class FormReportCountOrdersByPeriod + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel = new System.Windows.Forms.Panel(); + this.buttonMake_Pdf = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.buttonToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.labelTo = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.labelFrom = new System.Windows.Forms.Label(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonMake_Pdf); + this.panel.Controls.Add(this.button1); + this.panel.Controls.Add(this.buttonToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.labelTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Controls.Add(this.labelFrom); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(987, 40); + this.panel.TabIndex = 2; + // + // buttonMake_Pdf + // + this.buttonMake_Pdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonMake_Pdf.Location = new System.Drawing.Point(826, 8); + this.buttonMake_Pdf.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonMake_Pdf.Name = "buttonMake_Pdf"; + this.buttonMake_Pdf.Size = new System.Drawing.Size(139, 27); + this.buttonMake_Pdf.TabIndex = 7; + this.buttonMake_Pdf.Text = "В Pdf"; + this.buttonMake_Pdf.UseVisualStyleBackColor = true; + this.buttonMake_Pdf.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(1564, 8); + this.button1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(139, 27); + this.button1.TabIndex = 6; + this.button1.Text = "В Pdf"; + this.button1.UseVisualStyleBackColor = true; + // + // buttonToPdf + // + this.buttonToPdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonToPdf.Location = new System.Drawing.Point(2452, 8); + this.buttonToPdf.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonToPdf.Name = "buttonToPdf"; + this.buttonToPdf.Size = new System.Drawing.Size(139, 27); + this.buttonToPdf.TabIndex = 5; + this.buttonToPdf.Text = "В Pdf"; + this.buttonToPdf.UseVisualStyleBackColor = true; + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(476, 8); + this.buttonMake.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(139, 27); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.buttonMake_Click); + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(237, 7); + this.dateTimePickerTo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + this.labelTo.AutoSize = true; + this.labelTo.Location = new System.Drawing.Point(208, 10); + this.labelTo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelTo.Name = "labelTo"; + this.labelTo.Size = new System.Drawing.Size(21, 15); + this.labelTo.TabIndex = 2; + this.labelTo.Text = "по"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(37, 7); + this.dateTimePickerFrom.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(14, 10); + this.labelFrom.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(15, 15); + this.labelFrom.TabIndex = 0; + this.labelFrom.Text = "С"; + // + // FormReportCountOrdersByPeriod + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(987, 596); + this.Controls.Add(this.panel); + this.Name = "FormReportCountOrdersByPeriod"; + this.Text = "Заказы по датам"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button button1; + private Button buttonToPdf; + private Button buttonMake; + private DateTimePicker dateTimePickerTo; + private Label labelTo; + private DateTimePicker dateTimePickerFrom; + private Label labelFrom; + private Button buttonMake_Pdf; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.cs b/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.cs new file mode 100644 index 0000000..b432798 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.cs @@ -0,0 +1,100 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +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 FurnitureAssembly +{ + public partial class FormReportCountOrdersByPeriod : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportCountOrdersByPeriod(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrdersCount.rdlc", FileMode.Open)); // другой файл + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void buttonMake_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetCountOrders(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.SaveCountOrdersToPdfFile(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); + } + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.resx b/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormReportCountOrdersByPeriod.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj index 7eb04fa..71f961d 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj @@ -11,6 +11,7 @@ + @@ -20,6 +21,9 @@ Always + + Always + diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 7044ee0..8382cfb 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -65,6 +65,7 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/ReportOrdersCount.rdlc b/FurnitureAssembly/FurnitureAssembly/ReportOrdersCount.rdlc new file mode 100644 index 0000000..73d8265 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/ReportOrdersCount.rdlc @@ -0,0 +1,459 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + FurnitureAssemblyContractsViewModels + /* Local Query */ + + + + DateCreate + System.DateTime + + + CountOrders + System.Decimal + + + TotalSumOrders + System.Double + + + + FurnitureAssemblyContracts.ViewModels + ReportCountOrdersViewModel + FurnitureAssemblyContracts.ViewModels.ReportCountOrdersViewModel, FurnitureAssemblyContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 1cm + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Заказы + + + + + + + 1cm + 21cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 3cm + + + 3cm + + + 7cm + + + + + 0.6cm + + + + + true + true + + + + + Дата создания + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!CountOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!TotalSumOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 19.84713cm + 2 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 15.39958cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!TotalSumOrders.Value, "DataSetOrders") + + + + + + + 4cm + 17.89958cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +