From 3704947e84418d293afcf8c56f4b7511e04701cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Thu, 30 Nov 2023 01:39:27 +0400 Subject: [PATCH] =?UTF-8?q?Excel=20=D0=BD=D0=B5=D0=B2=D0=B5=D1=80=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsProject/AppView/FormMain.Designer.cs | 3 ++ WinFormsProject/AppView/FormMain.cs | 48 +++++++++++++++++++- WinFormsProject/AppView/FormMain.resx | 3 ++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/WinFormsProject/AppView/FormMain.Designer.cs b/WinFormsProject/AppView/FormMain.Designer.cs index 72e4b40..3b0720f 100644 --- a/WinFormsProject/AppView/FormMain.Designer.cs +++ b/WinFormsProject/AppView/FormMain.Designer.cs @@ -40,6 +40,7 @@ this.сформироватьExcelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.documentWithImage1 = new WinFormsLibrary.DocumentWithImage(this.components); this.table2column1 = new WinFormsLibrary.Table2column(this.components); + this.componentDocumentWithChartBarExcel1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarExcel(this.components); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -112,6 +113,7 @@ this.сформироватьExcelToolStripMenuItem.Name = "сформироватьExcelToolStripMenuItem"; this.сформироватьExcelToolStripMenuItem.Size = new System.Drawing.Size(204, 22); this.сформироватьExcelToolStripMenuItem.Text = "Сформировать Excel"; + this.сформироватьExcelToolStripMenuItem.Click += new System.EventHandler(this.сформироватьExcelToolStripMenuItem_Click); // // FormMain // @@ -140,5 +142,6 @@ private ToolStripMenuItem сформироватьExcelToolStripMenuItem; private WinFormsLibrary.DocumentWithImage documentWithImage1; private WinFormsLibrary.Table2column table2column1; + private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarExcel componentDocumentWithChartBarExcel1; } } \ No newline at end of file diff --git a/WinFormsProject/AppView/FormMain.cs b/WinFormsProject/AppView/FormMain.cs index 3e85a45..57dd75f 100644 --- a/WinFormsProject/AppView/FormMain.cs +++ b/WinFormsProject/AppView/FormMain.cs @@ -1,3 +1,4 @@ +using ComponentsLibraryNet60.Models; using Contracts.StorageContracts; using Contracts.ViewModels; using ControlsLibraryNet60.Data; @@ -174,14 +175,57 @@ namespace AppView new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30}, }; - var orders = _providerStorage.GetFullList(); + var providers = _providerStorage.GetFullList(); List mergedColums = new() { new int[] { 1, 2 } }; - BigTable info = new(fileName, "Table", columnDefinitionsUp, columnDefinitionsDown, orders, mergedColums); + BigTable info = new(fileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums); table2column1.CreateTable(info); MessageBox.Show(""); } + + private void ExcelToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("", "", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + + var providers = _providerStorage.GetFullList(); + + var uniqueTypes = providers.Select(p => p.Type).Distinct(); + + Dictionary> data = new Dictionary>(); + + foreach (var uniqueType in uniqueTypes) + { + var typeProviders = providers.Where(p => p.Type == uniqueType).ToList(); + + var dataList = new List<(int Date, double Value)>(); + + for (int i = 0; i < typeProviders.Count; i++) + { + dataList.Add((i + 1, i + 1)); // (Date, Value), + } + + data.Add(uniqueType, dataList); + } + + componentDocumentWithChartBarExcel1.CreateDoc(new ComponentDocumentWithChartConfig() + { + FilePath = fileName, + Header = " .", + ChartTitle = " ", + LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom, + Data = data + }); + } } } \ No newline at end of file diff --git a/WinFormsProject/AppView/FormMain.resx b/WinFormsProject/AppView/FormMain.resx index a39f414..01068d2 100644 --- a/WinFormsProject/AppView/FormMain.resx +++ b/WinFormsProject/AppView/FormMain.resx @@ -66,4 +66,7 @@ 345, 17 + + 478, 17 + \ No newline at end of file