From fb17f2b58de62795226be128833d4aca7df486b5 Mon Sep 17 00:00:00 2001 From: bocchanskyy Date: Tue, 29 Oct 2024 10:43:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BD=20=D1=83=D1=81=D1=82=D0=B0=D0=BB?= =?UTF-8?q?=20=D0=BE=D1=82=20=D0=B3=D1=83=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=BE=D0=B4=D0=BE=D0=B2,=20=D1=83?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BB=20=D0=BE=D0=BD=20=D0=BC=D0=B5=D1=80?= =?UTF-8?q?=D1=86=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=BE=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=B2=20(=D1=8F=20=D0=BD=D0=B0=D0=B4=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=D0=B9=20=D0=BB=D0=B0=D0=B1=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=BB=D1=81=D1=8F=20=D0=BD=D0=B5=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D1=8E=20=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8.=20=D0=AF=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BF=D0=B5=D1=86=20=D1=83=D1=81=D1=82=D0=B0=D0=BB,=20?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BE=D0=BD=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMain.Designer.cs | 4 +- VolkovLabs/InternetShopOrdersApp/FormMain.cs | 156 +++++++++--------- .../InternetShopOrdersApp/FormMain.resx | 4 +- 3 files changed, 81 insertions(+), 83 deletions(-) diff --git a/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs b/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs index f4caa22..3e71a3d 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs @@ -42,7 +42,7 @@ controlDataTable = new ControlsLibraryNet60.Data.ControlDataTableTable(); excelImagesComponent = new WinFormsLibraryVolkov.NonVisualComponents.ExcelImagesComponent(components); componentHistogramToPdf = new FormLibrary.ComponentHistogramToPdf(components); - componentDocumentWithTableMultiHeaderWord = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord(components); + componentDocumentWithTableHeaderRowWord = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableHeaderRowWord(components); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -168,6 +168,6 @@ private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTable; private WinFormsLibraryVolkov.NonVisualComponents.ExcelImagesComponent excelImagesComponent; private FormLibrary.ComponentHistogramToPdf componentHistogramToPdf; - private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord componentDocumentWithTableMultiHeaderWord; + private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableHeaderRowWord componentDocumentWithTableHeaderRowWord; } } \ No newline at end of file diff --git a/VolkovLabs/InternetShopOrdersApp/FormMain.cs b/VolkovLabs/InternetShopOrdersApp/FormMain.cs index ba26c7d..f6d2643 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormMain.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormMain.cs @@ -23,6 +23,7 @@ using FormLibrary.HelperClasses; using FormLibrary; using System.Diagnostics; using DocumentFormat.OpenXml.Drawing.Charts; +using System.Runtime.CompilerServices; namespace InternetShopOrdersApp { @@ -95,13 +96,22 @@ namespace InternetShopOrdersApp private void документToolStripMenuItem_Click(object sender, EventArgs e) { - List orderImages = new List(); - foreach (var order in _logic.ReadList(null)) + using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { - orderImages.Add(order.OrderImage); - } - string path = AppDomain.CurrentDomain.BaseDirectory + "Фотокарточки заказов с интернет-магазина.xlsx"; - if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Фотокарточки заказов", orderImages.ToArray()))) MessageBox.Show("Документ был создан"); + saveFileDialog.Filter = "Excel Workbook (*.xlsx)|*.xlsx"; + saveFileDialog.Title = "Сохранить Excel файл"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + List orderImages = new List(); + foreach (var order in _logic.ReadList(null)) + { + orderImages.Add(order.OrderImage); + } + string path = saveFileDialog.FileName; + excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Фотокарточки заказов", orderImages.ToArray())); + } + MessageBox.Show("Excel успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } private void выбранныеТоварыToolStripMenuItem_Click(object sender, EventArgs e) @@ -115,91 +125,79 @@ namespace InternetShopOrdersApp private void документСТаблицейToolStripMenuItem_Click(object sender, EventArgs e) { - string path = AppDomain.CurrentDomain.BaseDirectory + "Отчет по всем товарам.docx"; - - // Получение списка заказов, который теперь должен возвращать список OrderViewModel - var orders = _logic.ReadList(null).Select(order => new OrderViewModel + using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { - Id = order.Id, - Fullname = order.Fullname, - Email = order.Email, - SelectedItemName = order.SelectedItemName, - OrderImage = order.OrderImage - }).ToList(); // Преобразование в список OrderViewModel + saveFileDialog.Filter = "Word Document (*.docx)|*.docx"; + saveFileDialog.Title = "Сохранить Word файл"; - // Настройка заголовков - var headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> - { - (0, 0, "Идентификатор", nameof(OrderViewModel.Id)), - (1, 0, "Личные данные", null), // Adjusting to show a single header for the merged fields - (2, 0, "Выбранный товар", nameof(OrderViewModel.SelectedItemName)) - }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + var orders = _logic.ReadList(null); + componentDocumentWithTableHeaderRowWord.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig + { + FilePath = saveFileDialog.FileName, + Header = "Заказы", + UseUnion = true, + ColumnsRowsWidth = new List<(int, int)> { (5, 0), (10, 0), (10, 0), (10, 0) }, + ColumnUnion = new List<(int StartIndex, int Count)> { (1, 2) }, + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "Id", "Id"), + (1, 0, "Личные данные", ""), + (1, 1, "ФИО заказчика", "Fullname"), + (2, 1, "Электронная почта", "Email"), + (3, 0, "Изображение заказа", "OrderImage"), + }, + Data = orders + }); - // Задайте количество данных и заголовков - var dataCount = orders.Count; // Количество строк данных - var headerCount = headers.Count; // Количество заголовков - - // Определение ширины колонок - var columnsRowsWidth = new List<(int Column, int Row)> - { - (0, 1), // Ширина для "Идентификатор" - (1, 1), // Ширина для "Личные данные" (объединение ФИО и Эл. почты) - (2, 1) // Ширина для "Выбранный товар" - }; - - // Определение объединения колонок - var columnUnion = new List<(int StartIndex, int Count)> - { - (1, 2) // Объединяем "ФИО" и "Эл. почта" в одну ячейку - }; - - // Создание документа - componentDocumentWithTableMultiHeaderWord.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig - { - Header = "Отчет по всем товарам", - Headers = headers, - ColumnsRowsDataCount = (headerCount, dataCount+1), // +1 для заголовка - ColumnsRowsWidth = columnsRowsWidth, - ColumnUnion = columnUnion, - UseUnion = true, - FilePath = path, - Data = orders // Передаем данные заказов в виде OrderViewModel - }); + MessageBox.Show("Word файл был успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } private void документСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e) { - try + using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { - var histogramGenerator = new ComponentHistogramToPdf(); - - var orders = _logic.ReadList(null); - - var itemCounts = new Dictionary(); - foreach (var order in orders) + saveFileDialog.Filter = "PDF Document (*.pdf)|*.pdf"; + saveFileDialog.Title = "Сохранить PDF файл"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (!itemCounts.ContainsKey(order.SelectedItemName)) + try { - itemCounts[order.SelectedItemName] = 0; + var histogramGenerator = new ComponentHistogramToPdf(); + + var orders = _logic.ReadList(null); + + var itemCounts = new Dictionary(); + foreach (var order in orders) + { + if (!itemCounts.ContainsKey(order.SelectedItemName)) + { + itemCounts[order.SelectedItemName] = 0; + } + itemCounts[order.SelectedItemName]++; + } + + var chartData = new List + { + new ChartData { SeriesName = "Заказы по товарам", Data = itemCounts.ToDictionary(kvp => kvp.Key, kvp => (double)kvp.Value) } + }; + + string filePath = saveFileDialog.FileName; + + histogramGenerator.CreateHistogramPdf(filePath, "Какие товары сколько раз заказывали", "Диаграмма заказов", OxyPlot.Legends.LegendPosition.BottomCenter, chartData); + + MessageBox.Show("PDF успешно сгенерирован!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show($"Ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - itemCounts[order.SelectedItemName]++; } - - var chartData = new List - { - new ChartData { SeriesName = "Заказы по товарам", Data = itemCounts.ToDictionary(kvp => kvp.Key, kvp => (double)kvp.Value) } - }; - - string filePath = AppDomain.CurrentDomain.BaseDirectory + "Какие товары сколько раз заказывали.pdf"; - - histogramGenerator.CreateHistogramPdf(filePath, "Какие товары сколько раз заказывали", "Диаграмма заказов", OxyPlot.Legends.LegendPosition.BottomCenter, chartData); - - MessageBox.Show("PDF успешно сгенерирован!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - catch (Exception ex) - { - MessageBox.Show($"Ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + } } } diff --git a/VolkovLabs/InternetShopOrdersApp/FormMain.resx b/VolkovLabs/InternetShopOrdersApp/FormMain.resx index c4d345e..303883a 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormMain.resx +++ b/VolkovLabs/InternetShopOrdersApp/FormMain.resx @@ -126,8 +126,8 @@ 734, 22 - - 347, 18 + + 328, 20 177