diff --git a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs index 1e9efd6..555faec 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs @@ -37,6 +37,9 @@ 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.buttonSupplyShop = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); @@ -90,7 +93,10 @@ this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокАвтомобилейToolStripMenuItem, this.компонентыПоАвтомобилямToolStripMenuItem, - this.списокЗаказовToolStripMenuItem}); + this.списокЗаказовToolStripMenuItem, + this.списокМагазиновToolStripMenuItem, + this.автомобилиВМагазинахToolStripMenuItem, + this.списокЗаказовПоДатеToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -116,7 +122,6 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // - // // магазиныToolStripMenuItem // this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; @@ -124,6 +129,20 @@ this.магазиныToolStripMenuItem.Text = "Магазины"; this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(259, 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(259, 26); + this.автомобилиВМагазинахToolStripMenuItem.Text = "Автомобили в магазинах"; + this.автомобилиВМагазинахToolStripMenuItem.Click += new System.EventHandler(this.автомобилиВМагазинахToolStripMenuItem_Click); + // // buttonSupplyShop // this.buttonSupplyShop.Location = new System.Drawing.Point(969, 182); @@ -204,6 +223,13 @@ this.buttonSellCars.UseVisualStyleBackColor = true; this.buttonSellCars.Click += new System.EventHandler(this.buttonSellCars_Click); // + // списокЗаказовПоДатеToolStripMenuItem + // + this.списокЗаказовПоДатеToolStripMenuItem.Name = "списокЗаказовПоДатеToolStripMenuItem"; + this.списокЗаказовПоДатеToolStripMenuItem.Size = new System.Drawing.Size(259, 26); + this.списокЗаказовПоДатеToolStripMenuItem.Text = "Список заказов по дате"; + this.списокЗаказовПоДатеToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовПоДатеToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -249,5 +275,8 @@ private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonSupplyShop; private Button buttonSellCars; + 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 5ecd55e..0401724 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.cs @@ -105,6 +105,37 @@ namespace AutomobilePlant } + private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void автомобилиВМагазинахToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopCars)); + if (service is FormReportShopCars form) + { + form.ShowDialog(); + } + } + + private void списокЗаказовПоДатеToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders)); + if (service is FormReportDateOrders form) + { + form.ShowDialog(); + } + } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); diff --git a/AutomobilePlant/AutomobilePlant/FormReportDateOrders.Designer.cs b/AutomobilePlant/AutomobilePlant/FormReportDateOrders.Designer.cs new file mode 100644 index 0000000..3a509db --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportDateOrders.Designer.cs @@ -0,0 +1,85 @@ +namespace AutomobilePlant +{ + partial class FormReportDateOrders + { + /// <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() + { + this.panel = new System.Windows.Forms.Panel(); + this.buttonCreateToPdf = new System.Windows.Forms.Button(); + this.buttonCreateReport = new System.Windows.Forms.Button(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonCreateToPdf); + this.panel.Controls.Add(this.buttonCreateReport); + 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(978, 69); + this.panel.TabIndex = 1; + // + // buttonCreateToPdf + // + this.buttonCreateToPdf.Location = new System.Drawing.Point(769, 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); + // + // FormReportDateOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(978, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportDateOrders"; + this.Text = "Заказы по датам"; + this.panel.ResumeLayout(false); + this.ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonCreateToPdf; + private Button buttonCreateReport; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormReportDateOrders.cs b/AutomobilePlant/AutomobilePlant/FormReportDateOrders.cs new file mode 100644 index 0000000..d14acd7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportDateOrders.cs @@ -0,0 +1,79 @@ +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 FormReportDateOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + public FormReportDateOrders(ILogger<FormReportDateOrders> logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrdersByDate.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void buttonCreateReport_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetDateOrders(); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на весь период по датам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCreateToPdf_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveDateOrdersToPdfFile(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/FormReportDateOrders.resx b/AutomobilePlant/AutomobilePlant/FormReportDateOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportDateOrders.resx @@ -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> \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormReportShopCars.Designer.cs b/AutomobilePlant/AutomobilePlant/FormReportShopCars.Designer.cs new file mode 100644 index 0000000..aec7835 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportShopCars.Designer.cs @@ -0,0 +1,106 @@ +namespace AutomobilePlant +{ + partial class FormReportShopCars + { + /// <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() + { + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Shop = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Car = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 8); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(176, 29); + this.buttonSaveToExcel.TabIndex = 0; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Shop, + this.Car, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 43); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(776, 395); + this.dataGridView.TabIndex = 1; + // + // Shop + // + this.Shop.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Shop.HeaderText = "Магазин"; + this.Shop.MinimumWidth = 6; + this.Shop.Name = "Shop"; + // + // Car + // + this.Car.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Car.HeaderText = "Автомобиль"; + this.Car.MinimumWidth = 6; + this.Car.Name = "Car"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // FormReportShopCars + // + 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.dataGridView); + this.Controls.Add(this.buttonSaveToExcel); + this.Name = "FormReportShopCars"; + this.Text = "Автомобили в магазинах"; + this.Load += new System.EventHandler(this.FormReportShopCars_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Shop; + private DataGridViewTextBoxColumn Car; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormReportShopCars.cs b/AutomobilePlant/AutomobilePlant/FormReportShopCars.cs new file mode 100644 index 0000000..811dc7f --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportShopCars.cs @@ -0,0 +1,84 @@ +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 FormReportShopCars : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShopCars(ILogger<FormReportShopCars> logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopCarsToExcelFile(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); + } + } + } + + private void FormReportShopCars_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopCars(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Cars) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Всего:", "", elem.Count }); + dataGridView.Rows.Add(Array.Empty<object>()); + } + } + _logger.LogInformation("Загрузка списка магазинов с авто в них"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов с авто в них"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormReportShopCars.resx b/AutomobilePlant/AutomobilePlant/FormReportShopCars.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormReportShopCars.resx @@ -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> \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/Program.cs b/AutomobilePlant/AutomobilePlant/Program.cs index 88383f1..04840e2 100644 --- a/AutomobilePlant/AutomobilePlant/Program.cs +++ b/AutomobilePlant/AutomobilePlant/Program.cs @@ -53,12 +53,14 @@ namespace AutomobilePlant services.AddTransient<FormCar>(); services.AddTransient<FormCarComponent>(); services.AddTransient<FormCars>(); - services.AddTransient<FormReportCarComponents>(); - services.AddTransient<FormReportOrder>(); services.AddTransient<FormShop>(); services.AddTransient<FormShops>(); services.AddTransient<FormShopSupply>(); services.AddTransient<FormShopSell>(); + services.AddTransient<FormReportCarComponents>(); + services.AddTransient<FormReportOrder>(); + services.AddTransient<FormReportShopCars>(); + services.AddTransient<FormReportDateOrders>(); } } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/ReportOrdersByDate.rdlc b/AutomobilePlant/AutomobilePlant/ReportOrdersByDate.rdlc new file mode 100644 index 0000000..3f130a1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/ReportOrdersByDate.rdlc @@ -0,0 +1,424 @@ +<?xml version="1.0" encoding="utf-8"?> +<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"> + <AutoRefresh>0</AutoRefresh> + <DataSources> + <DataSource Name="AutomobilePlantContractsViewModels"> + <ConnectionProperties> + <DataProvider>System.Data.DataSet</DataProvider> + <ConnectString>/* Local Connection */</ConnectString> + </ConnectionProperties> + <rd:DataSourceID>10791c83-cee8-4a38-bbd0-245fc17cefb3</rd:DataSourceID> + </DataSource> + </DataSources> + <DataSets> + <DataSet Name="DataSetOrders"> + <Query> + <DataSourceName>AutomobilePlantContractsViewModels</DataSourceName> + <CommandText>/* Local Query */</CommandText> + </Query> + <Fields> + <Field Name="DateCreate"> + <DataField>DateCreate</DataField> + <rd:TypeName>System.DateTime</rd:TypeName> + </Field> + <Field Name="CountOrders"> + <DataField>CountOrders</DataField> + <rd:TypeName>System.Decimal</rd:TypeName> + </Field> + <Field Name="SumOrders"> + <DataField>SumOrders</DataField> + <rd:TypeName>System.Double</rd:TypeName> + </Field> + </Fields> + <rd:DataSetInfo> + <rd:DataSetName>AutomobilePlantContracts.ViewModels</rd:DataSetName> + <rd:TableName>ReportDateOrdersViewModel</rd:TableName> + <rd:ObjectDataSourceType>AutomobilePlantContracts.ViewModels.ReportDateOrdersViewModel, AutomobilePlantContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType> + </rd:DataSetInfo> + </DataSet> + </DataSets> + <ReportSections> + <ReportSection> + <Body> + <ReportItems> + <Textbox Name="TextboxTitle"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>Заказы</Value> + <Style> + <FontSize>16pt</FontSize> + <FontWeight>Bold</FontWeight> + </Style> + </TextRun> + </TextRuns> + <Style> + <TextAlign>Center</TextAlign> + </Style> + </Paragraph> + </Paragraphs> + <Height>1cm</Height> + <Width>21cm</Width> + <Style> + <Border> + <Style>None</Style> + </Border> + <VerticalAlign>Middle</VerticalAlign> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + <Tablix Name="Tablix1"> + <TablixBody> + <TablixColumns> + <TablixColumn> + <Width>3cm</Width> + </TablixColumn> + <TablixColumn> + <Width>3cm</Width> + </TablixColumn> + <TablixColumn> + <Width>7cm</Width> + </TablixColumn> + </TablixColumns> + <TablixRows> + <TablixRow> + <Height>0.6cm</Height> + <TablixCells> + <TablixCell> + <CellContents> + <Textbox Name="Textbox1"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>Дата</Value> + <Style> + <FontWeight>Bold</FontWeight> + </Style> + </TextRun> + </TextRuns> + <Style /> + </Paragraph> + </Paragraphs> + <rd:DefaultName>Textbox1</rd:DefaultName> + <Style> + <Border> + <Color>LightGrey</Color> + <Style>Solid</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + </CellContents> + </TablixCell> + <TablixCell> + <CellContents> + <Textbox Name="Textbox3"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>Количество</Value> + <Style> + <FontWeight>Bold</FontWeight> + </Style> + </TextRun> + </TextRuns> + <Style /> + </Paragraph> + </Paragraphs> + <rd:DefaultName>Textbox3</rd:DefaultName> + <Style> + <Border> + <Color>LightGrey</Color> + <Style>Solid</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + </CellContents> + </TablixCell> + <TablixCell> + <CellContents> + <Textbox Name="Textbox2"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>Сумма</Value> + <Style> + <FontWeight>Bold</FontWeight> + </Style> + </TextRun> + </TextRuns> + <Style /> + </Paragraph> + </Paragraphs> + <rd:DefaultName>Textbox2</rd:DefaultName> + <Style> + <Border> + <Color>LightGrey</Color> + <Style>Solid</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + </CellContents> + </TablixCell> + </TablixCells> + </TablixRow> + <TablixRow> + <Height>0.6cm</Height> + <TablixCells> + <TablixCell> + <CellContents> + <Textbox Name="DateCreate"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>=Fields!DateCreate.Value</Value> + <Style> + <Format>d</Format> + </Style> + </TextRun> + </TextRuns> + <Style /> + </Paragraph> + </Paragraphs> + <rd:DefaultName>DateCreate</rd:DefaultName> + <Style> + <Border> + <Color>LightGrey</Color> + <Style>Solid</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + </CellContents> + </TablixCell> + <TablixCell> + <CellContents> + <Textbox Name="CountOrders"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>=Fields!CountOrders.Value</Value> + <Style /> + </TextRun> + </TextRuns> + <Style /> + </Paragraph> + </Paragraphs> + <rd:DefaultName>CountOrders</rd:DefaultName> + <Style> + <Border> + <Color>LightGrey</Color> + <Style>Solid</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + </CellContents> + </TablixCell> + <TablixCell> + <CellContents> + <Textbox Name="SumOrders"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>=Fields!SumOrders.Value</Value> + <Style /> + </TextRun> + </TextRuns> + <Style /> + </Paragraph> + </Paragraphs> + <rd:DefaultName>SumOrders</rd:DefaultName> + <Style> + <Border> + <Color>LightGrey</Color> + <Style>Solid</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + </CellContents> + </TablixCell> + </TablixCells> + </TablixRow> + </TablixRows> + </TablixBody> + <TablixColumnHierarchy> + <TablixMembers> + <TablixMember /> + <TablixMember /> + <TablixMember /> + </TablixMembers> + </TablixColumnHierarchy> + <TablixRowHierarchy> + <TablixMembers> + <TablixMember> + <KeepWithGroup>After</KeepWithGroup> + </TablixMember> + <TablixMember> + <Group Name="Подробности" /> + </TablixMember> + </TablixMembers> + </TablixRowHierarchy> + <DataSetName>DataSetOrders</DataSetName> + <Top>2.48391cm</Top> + <Left>0.55245cm</Left> + <Height>1.2cm</Height> + <Width>13cm</Width> + <ZIndex>1</ZIndex> + <Style> + <Border> + <Style>Double</Style> + </Border> + </Style> + </Tablix> + <Textbox Name="TextboxTotalSum"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>Всего:</Value> + <Style> + <FontWeight>Bold</FontWeight> + </Style> + </TextRun> + </TextRuns> + <Style> + <TextAlign>Right</TextAlign> + </Style> + </Paragraph> + </Paragraphs> + <Top>4cm</Top> + <Left>8.55245cm</Left> + <Height>0.6cm</Height> + <Width>2.5cm</Width> + <ZIndex>2</ZIndex> + <Style> + <Border> + <Style>None</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + <Textbox Name="SumTotal"> + <CanGrow>true</CanGrow> + <KeepTogether>true</KeepTogether> + <Paragraphs> + <Paragraph> + <TextRuns> + <TextRun> + <Value>=Sum(Fields!SumOrders.Value, "DataSetOrders")</Value> + <Style> + <FontWeight>Bold</FontWeight> + </Style> + </TextRun> + </TextRuns> + <Style> + <TextAlign>Right</TextAlign> + </Style> + </Paragraph> + </Paragraphs> + <Top>4cm</Top> + <Left>11.05245cm</Left> + <Height>0.6cm</Height> + <Width>2.5cm</Width> + <ZIndex>3</ZIndex> + <Style> + <Border> + <Style>None</Style> + </Border> + <PaddingLeft>2pt</PaddingLeft> + <PaddingRight>2pt</PaddingRight> + <PaddingTop>2pt</PaddingTop> + <PaddingBottom>2pt</PaddingBottom> + </Style> + </Textbox> + </ReportItems> + <Height>5.72875cm</Height> + <Style /> + </Body> + <Width>21cm</Width> + <Page> + <PageHeight>29.7cm</PageHeight> + <PageWidth>21cm</PageWidth> + <LeftMargin>2cm</LeftMargin> + <RightMargin>2cm</RightMargin> + <TopMargin>2cm</TopMargin> + <BottomMargin>2cm</BottomMargin> + <ColumnSpacing>0.13cm</ColumnSpacing> + <Style /> + </Page> + </ReportSection> + </ReportSections> + <ReportParameters> + <ReportParameter Name="ReportParameterPeriod"> + <DataType>String</DataType> + <Nullable>true</Nullable> + <Prompt>ReportParameter1</Prompt> + </ReportParameter> + </ReportParameters> + <ReportParametersLayout> + <GridLayoutDefinition> + <NumberOfColumns>4</NumberOfColumns> + <NumberOfRows>2</NumberOfRows> + <CellDefinitions> + <CellDefinition> + <ColumnIndex>0</ColumnIndex> + <RowIndex>0</RowIndex> + <ParameterName>ReportParameterPeriod</ParameterName> + </CellDefinition> + </CellDefinitions> + </GridLayoutDefinition> + </ReportParametersLayout> + <rd:ReportUnitType>Cm</rd:ReportUnitType> + <rd:ReportID>2de0031a-4d17-449d-922d-d9fc54572312</rd:ReportID> +</Report> \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs index 426e586..b1a73b9 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ReportLogic.cs @@ -18,14 +18,16 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly ICarStorage _carStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ICarStorage carStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(ICarStorage carStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _carStorage = carStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -103,5 +105,64 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics }); } + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateTableDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + public void SaveShopCarsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopCars = GetShopCars() + }); + } + + public List<ReportShopCarsViewModel> GetShopCars() + { + var shops = _shopStorage.GetFullList(); + var list = new List<ReportShopCarsViewModel>(); + foreach (var shop in shops) + { + var record = new ReportShopCarsViewModel + { + ShopName = shop.Name, + Cars = new List<Tuple<string, int>>(), + Count = 0 + }; + foreach (var carCount in shop.ShopCars.Values) + { + record.Cars.Add(new Tuple<string, int>(carCount.Item1.CarName, carCount.Item2)); + record.Count += carCount.Item2; + } + list.Add(record); + } + return list; + } + + public List<ReportDateOrdersViewModel> GetDateOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel + { + DateCreate = x.Key, + CountOrders = x.Count(), + SumOrders = x.Sum(y => y.Sum) + }).ToList(); + } + public void SaveDateOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateReportDateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Заказы по датам", + DateOrders = GetDateOrders() + }); + } } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index fe05818..354b0b3 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -73,6 +73,70 @@ namespace AutomobilePlantBusinessLogic.OfficePackage } SaveExcel(info); } + + public void CreateShopReport(ExcelInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var pc in info.ShopCars) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var (CarName, Count) in pc.Cars) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = CarName, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.Count.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } + /// Создание excel-файла protected abstract void CreateExcel(ExcelInfo info); /// Добавляем новую ячейку в лист diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 4cbe16c..35ab9fe 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -49,6 +49,41 @@ namespace AutomobilePlantBusinessLogic.OfficePackage }); SavePdf(info); } + + public void CreateReportDateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List<string> { "3cm", "3cm", "7cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List<string> { "Дата", "Количество", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.DateOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List<string> { order.DateCreate.ToShortDateString(), order.CountOrders.ToString(), order.SumOrders.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.DateOrders.Sum(x => x.SumOrders)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + SavePdf(info); + } + /// Создание pdf-файла protected abstract void CreatePdf(PdfInfo info); /// Создание параграфа с текстом diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 7f02d0f..562412e 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -38,11 +38,35 @@ namespace AutomobilePlantBusinessLogic.OfficePackage } SaveWord(info); } + + public void CreateTableDoc(WordInfo wordInfo) + { + CreateWord(wordInfo); + var list = new List<string>(); + foreach (var shop in wordInfo.Shops) + { + list.Add(shop.Name); + list.Add(shop.Address); + list.Add(shop.OpeningDate.ToString()); + } + var wordTable = new WordTable + { + Headers = new List<string> { + "Название", + "Адрес", + "Дата открытия"}, + Texts = list + }; + CreateTable(wordTable); + SaveWord(wordInfo); + } + /// Создание doc-файла protected abstract void CreateWord(WordInfo info); /// Создание абзаца с текстом protected abstract void CreateParagraph(WordParagraph paragraph); /// Сохранение файла protected abstract void SaveWord(WordInfo info); + protected abstract void CreateTable(WordTable info); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 8f1a228..77dd534 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -12,5 +12,6 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List<ReportCarComponentViewModel> CarComponents { get; set; } = new(); + public List<ReportShopCarsViewModel> ShopCars { get; set; } = new(); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 3063878..6b46120 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -14,5 +14,6 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } public List<ReportOrdersViewModel> Orders { get; set; } = new(); + public List<ReportDateOrdersViewModel> DateOrders { get; set; } = new(); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index cd72eb8..8e0ef58 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -12,5 +12,6 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List<CarViewModel> Cars { get; set; } = new(); + public List<ShopViewModel> Shops { get; set; } = new(); } } diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..45c6541 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List<string> Headers { get; set; } = new(); + public List<string> Texts { get; set; } = new(); + } +} diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs index b439162..248a388 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -41,8 +41,7 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.Implements } /// Задание форматирования для абзаца - private static ParagraphProperties? - CreateParagraphProperties(WordTextProperties? paragraphProperties) + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) { if (paragraphProperties == null) { @@ -78,6 +77,7 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.Implements mainPart.Document = new Document(); _docBody = mainPart.Document.AppendChild(new Body()); } + protected override void CreateParagraph(WordParagraph paragraph) { if (_docBody == null || paragraph == null) @@ -106,6 +106,7 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.Implements } _docBody.AppendChild(docParagraph); } + protected override void SaveWord(WordInfo info) { if (_docBody == null || _wordDocument == null) @@ -116,5 +117,87 @@ namespace AutomobilePlantBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Close(); } + + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + Table tab = new Table(); + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue<BorderValues>(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue<BorderValues>(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue<BorderValues>(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue<BorderValues>(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue<BorderValues>(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue<BorderValues>(BorderValues.Single), + Size = 12 + } + ) + ); + tab.AppendChild<TableProperties>(props); + TableGrid tableGrid = new TableGrid(); + for (int i = 0; i < table.Headers.Count; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + tab.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + tab.AppendChild(tableRow); + int height = table.Texts.Count / table.Headers.Count; + int width = table.Headers.Count; + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) + { + var element = table.Texts[i * table.Headers.Count + j]; + tableRow.AppendChild(CreateTableCell(element)); + } + tab.AppendChild(tableRow); + } + + _docBody.AppendChild(tab); + + } + + private TableCell CreateTableCell(string element) + { + var tableParagraph = new Paragraph(); + var run = new Run(); + run.AppendChild(new Text { Text = element }); + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + return tableCell; + } } } diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IReportLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IReportLogic.cs index d6d28b2..dd8c65f 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IReportLogic.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IReportLogic.cs @@ -20,5 +20,11 @@ namespace AutomobilePlantContracts.BusinessLogicContracts void SaveCarComponentToExcelFile(ReportBindingModel model); /// Сохранение заказов в файл-Pdf void SaveOrdersToPdfFile(ReportBindingModel model); + /// Сохранение магазинов в файл-Word + void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopCarsToExcelFile(ReportBindingModel model); + List<ReportShopCarsViewModel> GetShopCars(); + List<ReportDateOrdersViewModel> GetDateOrders(); + void SaveDateOrdersToPdfFile(ReportBindingModel model); } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportDateOrdersViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportDateOrdersViewModel.cs new file mode 100644 index 0000000..fc46ac2 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportDateOrdersViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.ViewModels +{ + public class ReportDateOrdersViewModel + { + public DateTime DateCreate { get; set; } + public int CountOrders { get; set; } + public double SumOrders { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportShopCarsViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportShopCarsViewModel.cs new file mode 100644 index 0000000..36f11f7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ReportShopCarsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.ViewModels +{ + public class ReportShopCarsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int Count { get; set; } + public List<Tuple<string, int>> Cars { get; set; } = new(); + } +}