From e288679fecf85124d545038401f274a73f9d69f4 Mon Sep 17 00:00:00 2001 From: Safgerd Date: Mon, 13 Mar 2023 00:05:47 +0400 Subject: [PATCH 1/2] =?UTF-8?q?LabWork04=5FBase:=20=D0=93=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE,=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20=D0=B1?= =?UTF-8?q?=D1=8B=D1=82=D1=8C,=20=D0=B0=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82?= =?UTF-8?q?=20=D0=B8=20=D0=BD=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomobilePlant/AutomobilePlant.csproj | 7 + .../AutomobilePlant/FormMain.Designer.cs | 43 +- AutomobilePlant/AutomobilePlant/FormMain.cs | 39 +- .../FormReportCarComponents.Designer.cs | 110 ++++ .../FormReportCarComponents.cs | 85 +++ .../FormReportCarComponents.resx | 60 ++ .../FormReportOrder.Designer.cs | 130 ++++ .../AutomobilePlant/FormReportOrder.cs | 101 +++ .../AutomobilePlant/FormReportOrder.resx | 120 ++++ AutomobilePlant/AutomobilePlant/Program.cs | 9 + .../AutomobilePlant/ReportOrders.rdlc | 600 ++++++++++++++++++ .../AutomobilePlantBusinessLogic.csproj | 2 + .../BusinessLogics/ReportLogic.cs | 111 ++++ .../OfficePackage/AbstractSaveToExcel.cs | 85 +++ .../OfficePackage/AbstractSaveToPdf.cs | 63 ++ .../OfficePackage/AbstractSaveToWord.cs | 48 ++ .../HelperEnums/ExcelStyleInfoType.cs | 15 + .../HelperEnums/PdfParagraphAlignmentType.cs | 15 + .../HelperEnums/WordJustificationType.cs | 14 + .../HelperModels/ExcelCellParameters.cs | 18 + .../OfficePackage/HelperModels/ExcelInfo.cs | 16 + .../HelperModels/ExcelMergeParameters.cs | 15 + .../OfficePackage/HelperModels/PdfInfo.cs | 18 + .../HelperModels/PdfParagraph.cs | 16 + .../HelperModels/PdfRowParameters.cs | 16 + .../OfficePackage/HelperModels/WordInfo.cs | 16 + .../HelperModels/WordParagraph.cs | 14 + .../HelperModels/WordTextProperties.cs | 16 + .../OfficePackage/Implements/SaveToExcel.cs | 312 +++++++++ .../OfficePackage/Implements/SaveToPdf.cs | 96 +++ .../OfficePackage/Implements/SaveToWord.cs | 120 ++++ .../BindingModels/ReportBindingModel.cs | 15 + .../BusinessLogicContracts/IReportLogic.cs | 24 + .../SearchModels/OrderSearchModel.cs | 2 + .../ViewModels/ReportCarComponentViewModel.cs | 15 + .../ViewModels/ReportOrdersViewModel.cs | 18 + .../Implements/OrderStorage.cs | 4 +- .../Implements/OrderStorage.cs | 8 +- .../Implements/OrderStorage.cs | 6 +- 39 files changed, 2408 insertions(+), 14 deletions(-) create mode 100644 AutomobilePlant/AutomobilePlant/FormReportCarComponents.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormReportCarComponents.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormReportCarComponents.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormReportOrder.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormReportOrder.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormReportOrder.resx create mode 100644 AutomobilePlant/AutomobilePlant/ReportOrders.rdlc create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToExcel.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToPdf.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BindingModels/ReportBindingModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IReportLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportCarComponentViewModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportOrdersViewModel.cs diff --git a/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj b/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj index c64daed..cb30119 100644 --- a/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj +++ b/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj @@ -15,6 +15,7 @@ + @@ -26,4 +27,10 @@ + + + Always + + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs index 8ad81b0..7b0b9de 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs @@ -32,6 +32,10 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокАвтомобилейToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыПоАвтомобилямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); @@ -46,7 +50,8 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); + this.справочникиToolStripMenuItem, + this.отчетыToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1176, 28); @@ -76,6 +81,38 @@ this.автомобилиToolStripMenuItem.Text = "Автомобили"; this.автомобилиToolStripMenuItem.Click += new System.EventHandler(this.автомобилиToolStripMenuItem_Click); // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.списокАвтомобилейToolStripMenuItem, + this.компонентыПоАвтомобилямToolStripMenuItem, + this.списокЗаказовToolStripMenuItem}); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокАвтомобилейToolStripMenuItem + // + this.списокАвтомобилейToolStripMenuItem.Name = "списокАвтомобилейToolStripMenuItem"; + this.списокАвтомобилейToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокАвтомобилейToolStripMenuItem.Text = "Список автомобилей"; + this.списокАвтомобилейToolStripMenuItem.Click += new System.EventHandler(this.списокАвтомобилейToolStripMenuItem_Click); + // + // компонентыПоАвтомобилямToolStripMenuItem + // + this.компонентыПоАвтомобилямToolStripMenuItem.Name = "компонентыПоАвтомобилямToolStripMenuItem"; + this.компонентыПоАвтомобилямToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.компонентыПоАвтомобилямToolStripMenuItem.Text = "Компоненты по автомобилям"; + this.компонентыПоАвтомобилямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоАвтомобилямToolStripMenuItem_Click); + // + // списокЗаказовToolStripMenuItem + // + this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; + this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); + // + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -172,5 +209,9 @@ private Button buttonSetToDone; private Button buttonSetToFinish; private Button buttonUpdate; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem списокАвтомобилейToolStripMenuItem; + private ToolStripMenuItem компонентыПоАвтомобилямToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormMain.cs b/AutomobilePlant/AutomobilePlant/FormMain.cs index 02cfdf1..72f6283 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.cs @@ -1,4 +1,5 @@ -using AutomobilePlantContracts.BindingModels; +using AutomobilePlantBusinessLogic.BusinessLogics; +using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicContracts; using AutomobilePlantDataModels.Enums; using Microsoft.Extensions.Logging; @@ -18,11 +19,13 @@ namespace AutomobilePlant { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) + private readonly IReportLogic _reportLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + _reportLogic = reportLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -69,6 +72,38 @@ namespace AutomobilePlant } } + private void компонентыПоАвтомобилямToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportCarComponents)); + if (service is FormReportCarComponents form) + { + form.ShowDialog(); + } + } + + private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrder)); + if (service is FormReportOrder form) + { + form.ShowDialog(); + } + } + + private void списокАвтомобилейToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveCarsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/AutomobilePlant/AutomobilePlant/FormReportCarComponents.Designer.cs b/AutomobilePlant/AutomobilePlant/FormReportCarComponents.Designer.cs new file mode 100644 index 0000000..e286896 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportCarComponents.Designer.cs @@ -0,0 +1,110 @@ +namespace AutomobilePlant +{ + partial class FormReportCarComponents + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.Car = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Car, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 37); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(776, 401); + this.dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 2); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(220, 29); + this.buttonSaveToExcel.TabIndex = 1; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click); + // + // Car + // + this.Car.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Car.HeaderText = "Автомобиль"; + this.Car.MinimumWidth = 6; + this.Car.Name = "Car"; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // FormReportCarComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportCarComponents"; + this.Text = "Компоненты по автомобилям"; + this.Load += new System.EventHandler(this.FormReportCarComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonSaveToExcel; + private DataGridViewTextBoxColumn Car; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormReportCarComponents.cs b/AutomobilePlant/AutomobilePlant/FormReportCarComponents.cs new file mode 100644 index 0000000..3416a7a --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportCarComponents.cs @@ -0,0 +1,85 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +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 AutomobilePlant +{ + public partial class FormReportCarComponents : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportCarComponents(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportCarComponents_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetCarComponents(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.CarName, "", "" }); + foreach (var listElem in elem.Components) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка автомобилей по компонентам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка автомобилей по компонентам"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveCarComponentToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка автомобилей по компонентам"); + + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка автомобилей по компонентам"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormReportCarComponents.resx b/AutomobilePlant/AutomobilePlant/FormReportCarComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportCarComponents.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/AutomobilePlant/AutomobilePlant/FormReportOrder.Designer.cs b/AutomobilePlant/AutomobilePlant/FormReportOrder.Designer.cs new file mode 100644 index 0000000..cb1d939 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportOrder.Designer.cs @@ -0,0 +1,130 @@ +namespace AutomobilePlant +{ + partial class FormReportOrder + { + /// + /// 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.buttonCreateToPdf = new System.Windows.Forms.Button(); + this.buttonCreateReport = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimePickerEnd = new System.Windows.Forms.DateTimePicker(); + this.dateTimePickerStart = new System.Windows.Forms.DateTimePicker(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonCreateToPdf); + this.panel.Controls.Add(this.buttonCreateReport); + this.panel.Controls.Add(this.label2); + this.panel.Controls.Add(this.label1); + this.panel.Controls.Add(this.dateTimePickerEnd); + this.panel.Controls.Add(this.dateTimePickerStart); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(984, 69); + this.panel.TabIndex = 0; + // + // buttonCreateToPdf + // + this.buttonCreateToPdf.Location = new System.Drawing.Point(782, 39); + this.buttonCreateToPdf.Name = "buttonCreateToPdf"; + this.buttonCreateToPdf.Size = new System.Drawing.Size(190, 27); + this.buttonCreateToPdf.TabIndex = 5; + this.buttonCreateToPdf.Text = "PDF"; + this.buttonCreateToPdf.UseVisualStyleBackColor = true; + this.buttonCreateToPdf.Click += new System.EventHandler(this.buttonCreateToPdf_Click); + // + // buttonCreateReport + // + this.buttonCreateReport.Location = new System.Drawing.Point(554, 39); + this.buttonCreateReport.Name = "buttonCreateReport"; + this.buttonCreateReport.Size = new System.Drawing.Size(190, 27); + this.buttonCreateReport.TabIndex = 4; + this.buttonCreateReport.Text = "Сформировать"; + this.buttonCreateReport.UseVisualStyleBackColor = true; + this.buttonCreateReport.Click += new System.EventHandler(this.buttonCreateReport_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(369, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(56, 20); + this.label2.TabIndex = 3; + this.label2.Text = "Конец:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(87, 6); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(64, 20); + this.label1.TabIndex = 2; + this.label1.Text = "Начало:"; + // + // dateTimePickerEnd + // + this.dateTimePickerEnd.Location = new System.Drawing.Point(307, 39); + this.dateTimePickerEnd.Name = "dateTimePickerEnd"; + this.dateTimePickerEnd.Size = new System.Drawing.Size(187, 27); + this.dateTimePickerEnd.TabIndex = 1; + // + // dateTimePickerStart + // + this.dateTimePickerStart.Location = new System.Drawing.Point(35, 39); + this.dateTimePickerStart.Name = "dateTimePickerStart"; + this.dateTimePickerStart.Size = new System.Drawing.Size(187, 27); + this.dateTimePickerStart.TabIndex = 0; + // + // FormReportOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(984, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportOrder"; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + } + + #endregion + + private Panel panel; + private DateTimePicker dateTimePickerEnd; + private DateTimePicker dateTimePickerStart; + private Button buttonCreateToPdf; + private Button buttonCreateReport; + private Label label2; + private Label label1; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormReportOrder.cs b/AutomobilePlant/AutomobilePlant/FormReportOrder.cs new file mode 100644 index 0000000..20f215f --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportOrder.cs @@ -0,0 +1,101 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicContracts; +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 AutomobilePlant +{ + public partial class FormReportOrder : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportOrder(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void buttonCreateReport_Click(object sender, EventArgs e) + { + if (dateTimePickerStart.Value.Date >= dateTimePickerEnd.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = dateTimePickerStart.Value, + DateTo = dateTimePickerEnd.Value + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c{dateTimePickerStart.Value.ToShortDateString()} по {dateTimePickerEnd.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{ To}", dateTimePickerStart.Value.ToShortDateString(), dateTimePickerEnd.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } + + private void buttonCreateToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerStart.Value.Date >= dateTimePickerEnd.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 = dateTimePickerStart.Value, + DateTo = dateTimePickerEnd.Value + }); + _logger.LogInformation("Сохранение списка заказов на период { From} -{ To}", dateTimePickerStart.Value.ToShortDateString(), dateTimePickerEnd.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/AutomobilePlant/AutomobilePlant/FormReportOrder.resx b/AutomobilePlant/AutomobilePlant/FormReportOrder.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/AutomobilePlant/AutomobilePlant/Program.cs b/AutomobilePlant/AutomobilePlant/Program.cs index 1255289..7e1df73 100644 --- a/AutomobilePlant/AutomobilePlant/Program.cs +++ b/AutomobilePlant/AutomobilePlant/Program.cs @@ -1,4 +1,6 @@ using AutomobilePlantBusinessLogic.BusinessLogics; +using AutomobilePlantBusinessLogic.OfficePackage; +using AutomobilePlantBusinessLogic.OfficePackage.Implements; using AutomobilePlantContracts.BusinessLogicContracts; using AutomobilePlantContracts.StorageContracts; using AutomobilePlantDatabaseImplement.Implements; @@ -37,6 +39,11 @@ namespace AutomobilePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -45,6 +52,8 @@ namespace AutomobilePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/ReportOrders.rdlc b/AutomobilePlant/AutomobilePlant/ReportOrders.rdlc new file mode 100644 index 0000000..b90e3c8 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/ReportOrders.rdlc @@ -0,0 +1,600 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + AutomobilePlantContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + CarName + System.String + + + Sum + System.Decimal + + + Status + System.String + + + + AutomobilePlantContracts.ViewModels + ReportOrdersViewModel + AutomobilePlantContracts.ViewModels.ReportOrdersViewModel, AutomobilePlantContracts, 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 + + + + + + + 2.5cm + + + 3.21438cm + + + 8.23317cm + + + 2.5cm + + + 2.5cm + + + + + 0.6cm + + + + + true + true + + + + + Номер + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Дата создания + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Автомобиль + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Статус + + + + + + 2pt + 2pt + 2pt + 2pt + + + true + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!CarName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Status.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 18.94755cm + 2 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 12cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 14.5cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +