From 576a486a405dcb51c27c0abc63970d24fad67aa2 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Fri, 14 Jun 2024 16:56:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D1=87=D1=91=D1=82=20excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/FormMain.Designer.cs | 28 +++- GarmentFactory/FormMain.cs | 18 +++ .../FormReportGroupedOrders.Designer.cs | 86 +++++++++++++ GarmentFactory/FormReportGroupedOrders.cs | 80 ++++++++++++ GarmentFactory/FormReportGroupedOrders.resx | 120 ++++++++++++++++++ GarmentFactory/FormReportShops.Designer.cs | 112 ++++++++++++++++ GarmentFactory/FormReportShops.cs | 78 ++++++++++++ GarmentFactory/FormReportShops.resx | 120 ++++++++++++++++++ GarmentFactory/Program.cs | 2 + .../BusinessLogics/ReportLogic.cs | 18 +-- .../OfficePackage/AbstractSaveToExcel.cs | 77 ++++++++++- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- .../HelperModels/ExcelShopInfo.cs | 16 +++ .../OfficePackage/Implements/SaveToExcel.cs | 4 +- .../OfficePackage/Implements/SaveToWord.cs | 14 +- .../BusinessLogicsContracts/IReportLogic.cs | 4 +- 16 files changed, 752 insertions(+), 27 deletions(-) create mode 100644 GarmentFactory/FormReportGroupedOrders.Designer.cs create mode 100644 GarmentFactory/FormReportGroupedOrders.cs create mode 100644 GarmentFactory/FormReportGroupedOrders.resx create mode 100644 GarmentFactory/FormReportShops.Designer.cs create mode 100644 GarmentFactory/FormReportShops.cs create mode 100644 GarmentFactory/FormReportShops.resx create mode 100644 GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs diff --git a/GarmentFactory/FormMain.Designer.cs b/GarmentFactory/FormMain.Designer.cs index ad17815..273da04 100644 --- a/GarmentFactory/FormMain.Designer.cs +++ b/GarmentFactory/FormMain.Designer.cs @@ -47,6 +47,8 @@ textileComponentsToolStripMenuItem = new ToolStripMenuItem(); ordersToolStripMenuItem = new ToolStripMenuItem(); магазиныВDocToolStripMenuItem = new ToolStripMenuItem(); + загруженностьМагазиновToolStripMenuItem = new ToolStripMenuItem(); + заказыПоДатамToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -183,7 +185,7 @@ // // отчётыToolStripMenuItem // - отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem, магазиныВDocToolStripMenuItem }); + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem, магазиныВDocToolStripMenuItem, загруженностьМагазиновToolStripMenuItem, заказыПоДатамToolStripMenuItem }); отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; отчётыToolStripMenuItem.Size = new Size(73, 24); отчётыToolStripMenuItem.Text = "Отчёты"; @@ -191,31 +193,45 @@ // textilesToolStripMenuItem // textilesToolStripMenuItem.Name = "textilesToolStripMenuItem"; - textilesToolStripMenuItem.Size = new Size(274, 26); + textilesToolStripMenuItem.Size = new Size(276, 26); textilesToolStripMenuItem.Text = "Текстили"; textilesToolStripMenuItem.Click += TextilesToolStripMenuItem_Click; // // textileComponentsToolStripMenuItem // textileComponentsToolStripMenuItem.Name = "textileComponentsToolStripMenuItem"; - textileComponentsToolStripMenuItem.Size = new Size(274, 26); + textileComponentsToolStripMenuItem.Size = new Size(276, 26); textileComponentsToolStripMenuItem.Text = "Текстили с компонентами"; textileComponentsToolStripMenuItem.Click += ComponentTextilesToolStripMenuItem_Click; // // ordersToolStripMenuItem // ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - ordersToolStripMenuItem.Size = new Size(274, 26); + ordersToolStripMenuItem.Size = new Size(276, 26); ordersToolStripMenuItem.Text = "Заказы"; ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // // магазиныВDocToolStripMenuItem // магазиныВDocToolStripMenuItem.Name = "магазиныВDocToolStripMenuItem"; - магазиныВDocToolStripMenuItem.Size = new Size(274, 26); + магазиныВDocToolStripMenuItem.Size = new Size(276, 26); магазиныВDocToolStripMenuItem.Text = "Магазины в doc"; магазиныВDocToolStripMenuItem.Click += магазиныВDocToolStripMenuItem_Click; // + // загруженностьМагазиновToolStripMenuItem + // + загруженностьМагазиновToolStripMenuItem.Name = "загруженностьМагазиновToolStripMenuItem"; + загруженностьМагазиновToolStripMenuItem.Size = new Size(276, 26); + загруженностьМагазиновToolStripMenuItem.Text = "Загруженность магазинов"; + загруженностьМагазиновToolStripMenuItem.Click += загруженностьМагазиновToolStripMenuItem_Click; + // + // заказыПоДатамToolStripMenuItem + // + заказыПоДатамToolStripMenuItem.Name = "заказыПоДатамToolStripMenuItem"; + заказыПоДатамToolStripMenuItem.Size = new Size(276, 26); + заказыПоДатамToolStripMenuItem.Text = "Заказы по датам"; + заказыПоДатамToolStripMenuItem.Click += заказыПоДатамToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -260,5 +276,7 @@ private ToolStripMenuItem textileComponentsToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem магазиныВDocToolStripMenuItem; + private ToolStripMenuItem загруженностьМагазиновToolStripMenuItem; + private ToolStripMenuItem заказыПоДатамToolStripMenuItem; } } \ No newline at end of file diff --git a/GarmentFactory/FormMain.cs b/GarmentFactory/FormMain.cs index 6803151..671e91e 100644 --- a/GarmentFactory/FormMain.cs +++ b/GarmentFactory/FormMain.cs @@ -221,5 +221,23 @@ namespace GarmentFactoryView MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } + + private void загруженностьМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShops)); + if (service is FormReportShops form) + { + form.ShowDialog(); + } + } + + private void заказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + if (service is FormReportGroupedOrders form) + { + form.ShowDialog(); + } + } } } diff --git a/GarmentFactory/FormReportGroupedOrders.Designer.cs b/GarmentFactory/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..911a695 --- /dev/null +++ b/GarmentFactory/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,86 @@ +namespace GarmentFactoryView +{ + partial class FormReportGroupedOrders + { + /// + /// 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.buttonToPDF = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPDF); + this.panel.Controls.Add(this.buttonMake); + 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(970, 52); + this.panel.TabIndex = 1; + // + // buttonToPDF + // + this.buttonToPDF.Location = new System.Drawing.Point(486, 12); + this.buttonToPDF.Name = "buttonToPDF"; + this.buttonToPDF.Size = new System.Drawing.Size(411, 29); + this.buttonToPDF.TabIndex = 5; + this.buttonToPDF.Text = "В PDF"; + this.buttonToPDF.UseVisualStyleBackColor = true; + this.buttonToPDF.Click += new System.EventHandler(this.buttonToPDF_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(49, 12); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(377, 29); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // FormReportGroupedOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(970, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportGroupedOrders"; + this.Text = "Отчёт по группированным заказам "; + this.panel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonToPDF; + private Button buttonMake; + } +} \ No newline at end of file diff --git a/GarmentFactory/FormReportGroupedOrders.cs b/GarmentFactory/FormReportGroupedOrders.cs new file mode 100644 index 0000000..28a041b --- /dev/null +++ b/GarmentFactory/FormReportGroupedOrders.cs @@ -0,0 +1,80 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace GarmentFactoryView +{ + public partial class FormReportGroupedOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportGroupedOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupedOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetGroupedOrders(); + var source = new ReportDataSource("DataSetGroupedOrders", 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 buttonToPDF_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveGroupedOrdersToPdfFile(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/GarmentFactory/FormReportGroupedOrders.resx b/GarmentFactory/FormReportGroupedOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GarmentFactory/FormReportGroupedOrders.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/GarmentFactory/FormReportShops.Designer.cs b/GarmentFactory/FormReportShops.Designer.cs new file mode 100644 index 0000000..92476bd --- /dev/null +++ b/GarmentFactory/FormReportShops.Designer.cs @@ -0,0 +1,112 @@ +namespace GarmentFactoryView +{ + partial class FormReportShops + { + /// + /// 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() + { + buttonSaveToExcel = new Button(); + dataGridView = new DataGridView(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnTextile = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(12, 9); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(169, 29); + buttonSaveToExcel.TabIndex = 3; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnTextile, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 47); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(598, 403); + dataGridView.TabIndex = 2; + // + // ColumnShop + // + ColumnShop.FillWeight = 130F; + ColumnShop.HeaderText = "Магазин"; + ColumnShop.MinimumWidth = 6; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + // + // ColumnTextile + // + ColumnTextile.FillWeight = 140F; + ColumnTextile.HeaderText = "Текстиль"; + ColumnTextile.MinimumWidth = 6; + ColumnTextile.Name = "ColumnTextile"; + ColumnTextile.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.FillWeight = 90F; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormReportShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(598, 450); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Name = "FormReportShops"; + Text = "Загруженность магазинов"; + Load += FormReportShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnTextile; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/GarmentFactory/FormReportShops.cs b/GarmentFactory/FormReportShops.cs new file mode 100644 index 0000000..6429159 --- /dev/null +++ b/GarmentFactory/FormReportShops.cs @@ -0,0 +1,78 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +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 GarmentFactoryView +{ + public partial class FormReportShops : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShops(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShops_Load(object sender, EventArgs e) + { + try + { + var shops = _logic.GetShops(); + if (shops != null) + { + dataGridView.Rows.Clear(); + foreach (var shop in shops) + { + dataGridView.Rows.Add(new object[] { shop.ShopName, "", "" }); + foreach (var textile in shop.Textiles) + { + dataGridView.Rows.Add(new object[] { "", textile.Item1, textile.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", shop.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.SaveShopsToExcelFile(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/GarmentFactory/FormReportShops.resx b/GarmentFactory/FormReportShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/FormReportShops.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/GarmentFactory/Program.cs b/GarmentFactory/Program.cs index 52a7803..ff72909 100644 --- a/GarmentFactory/Program.cs +++ b/GarmentFactory/Program.cs @@ -67,6 +67,8 @@ namespace GarmentFactory services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs b/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs index c2aa447..06dc46e 100644 --- a/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs @@ -140,15 +140,15 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics }); } - //public void SaveShopsToExcelFile(ReportBindingModel model) - //{ - // _saveToExcel.CreateShopTextilesReport(new ExcelShop - // { - // FileName = model.FileName, - // Title = "Наполненость магазинов", - // ShopTextiles = GetShops() - // }); - //} + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopTextilesReport(new ExcelShopInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopTextiles = GetShops() + }); + } //public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) //{ diff --git a/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 6ac7f38..b83a78e 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -80,9 +80,82 @@ namespace GarmentFactoryBusinessLogic.OfficePackage SaveExcel(info); } - protected abstract void CreateExcel(ExcelInfo info); + + public void CreateShopTextilesReport(ExcelShopInfo 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 shop_textile in info.ShopTextiles) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = shop_textile.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (textile, count) in shop_textile.Textiles) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = textile, + 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 = shop_textile.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + protected abstract void CreateExcel(IDocumentInfo info); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); protected abstract void MergeCells(ExcelMergeParameters excelParams); - protected abstract void SaveExcel(ExcelInfo info); + protected abstract void SaveExcel(IDocumentInfo info); } } diff --git a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 1ebdd6d..e8acb1d 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels { - public class ExcelInfo + public class ExcelInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; diff --git a/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs new file mode 100644 index 0000000..5f056fd --- /dev/null +++ b/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelShopInfo.cs @@ -0,0 +1,16 @@ +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelShopInfo : IDocumentInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ShopTextiles { get; set; } = new(); + } +} diff --git a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index b32c1c9..c125141 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -159,7 +159,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements }; } - protected override void CreateExcel(ExcelInfo info) + protected override void CreateExcel(IDocumentInfo info) { _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); // Создание книги (в ней хранятся листы) @@ -288,7 +288,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements mergeCells.Append(mergeCell); } - protected override void SaveExcel(ExcelInfo info) + protected override void SaveExcel(IDocumentInfo info) { if (_spreadsheetDocument == null) { diff --git a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 05bf2f1..6a90822 100644 --- a/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -136,13 +136,13 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements _wordDocument.Close(); } - private Table? _lastTable; + private Table? _table; protected override void CreateTable(List columns) { if (_docBody == null) return; - _lastTable = new Table(); + _table = new Table(); var tableProp = new TableProperties(); tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); @@ -155,21 +155,21 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 } )); tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); - _lastTable.AppendChild(tableProp); + _table.AppendChild(tableProp); TableGrid tableGrid = new TableGrid(); foreach (var column in columns) { tableGrid.AppendChild(new GridColumn() { Width = column }); } - _lastTable.AppendChild(tableGrid); + _table.AppendChild(tableGrid); - _docBody.AppendChild(_lastTable); + _docBody.AppendChild(_table); } protected override void CreateRow(WordRowParameters rowParameters) { - if (_docBody == null || _lastTable == null) + if (_docBody == null || _table == null) return; TableRow docRow = new TableRow(); @@ -205,7 +205,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements docCell.AppendChild(docParagraph); docRow.AppendChild(docCell); } - _lastTable.AppendChild(docRow); + _table.AppendChild(docRow); } } } diff --git a/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs b/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs index 685ee72..cd762fb 100644 --- a/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs @@ -14,6 +14,8 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts List GetOrders(ReportBindingModel model); + List GetShops(); + void SaveTextilesToWordFile(ReportBindingModel model); void SaveTextileComponentToExcelFile(ReportBindingModel model); @@ -21,7 +23,7 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts void SaveOrdersToPdfFile(ReportBindingModel model); void SaveShopsToWordFile(ReportBindingModel model); - //void SaveShopsToExcelFile(ReportBindingModel model); + void SaveShopsToExcelFile(ReportBindingModel model); //void SaveGroupedOrdersToPdfFile(ReportBindingModel model); }