From 0bd1b174ebf9760f6c696e978fbce3a8c2b1b86c Mon Sep 17 00:00:00 2001 From: dimazhelovanov Date: Fri, 3 Nov 2023 11:07:28 +0400 Subject: [PATCH] =?UTF-8?q?2=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KOP_Labs/Classes/DataHistogramm.cs | 6 +- KOP_Labs/Classes/MyTableWithHead.cs | 4 +- .../NonVisualComponents/WordHistogramm.cs | 4 +- .../WordTableHeaderComponent.cs | 2 +- WinForm/Form1.cs | 6 +- WinForm/NonVisualForm.cs | 105 +++++++++++++----- 6 files changed, 90 insertions(+), 37 deletions(-) diff --git a/KOP_Labs/Classes/DataHistogramm.cs b/KOP_Labs/Classes/DataHistogramm.cs index 49ba0c2..1d8bdfd 100644 --- a/KOP_Labs/Classes/DataHistogramm.cs +++ b/KOP_Labs/Classes/DataHistogramm.cs @@ -8,15 +8,15 @@ namespace KOP_Labs.Classes { public class DataHistogramm { - public string _nameSeries { get; set; } = string.Empty; + public string _nameData { get; set; } = string.Empty; public double _data { get; set; } - public DataHistogramm(string nameSeries, string nameData, double data) + public DataHistogramm(string nameData, int data) { - _nameSeries = nameSeries; + _nameData = nameData; _data = data; } diff --git a/KOP_Labs/Classes/MyTableWithHead.cs b/KOP_Labs/Classes/MyTableWithHead.cs index 0a256d4..7dff7b8 100644 --- a/KOP_Labs/Classes/MyTableWithHead.cs +++ b/KOP_Labs/Classes/MyTableWithHead.cs @@ -12,15 +12,13 @@ namespace KOP_Labs.Classes public string _fileHeader = string.Empty; - //высота столбцов public List _heightRow = new(); - //высота колонок public List _widthCol = new(); public List _dataList; - //настройки соответствия столбец-поле + public Dictionary _columnsSettings; public MyTableWithHead(string filePath, string fileHeader, List heightRow, diff --git a/KOP_Labs/NonVisualComponents/WordHistogramm.cs b/KOP_Labs/NonVisualComponents/WordHistogramm.cs index fb53243..59dafbd 100644 --- a/KOP_Labs/NonVisualComponents/WordHistogramm.cs +++ b/KOP_Labs/NonVisualComponents/WordHistogramm.cs @@ -28,7 +28,7 @@ namespace KOP_Labs.NonVisualComponents public void CreateHistogramm(MyHistogramm myHistogramm) { - if(CheckData(myHistogramm._dataList)) { + if(!CheckData(myHistogramm._dataList)) { return; } Document doc = new Document(); @@ -76,7 +76,7 @@ namespace KOP_Labs.NonVisualComponents { foreach (var _data in data) { - if (string.IsNullOrEmpty(_data._nameSeries) || string.IsNullOrEmpty(_data._data.ToString())) + if (string.IsNullOrEmpty(_data._data.ToString())) { return false; } diff --git a/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs b/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs index e0bc955..856e7d0 100644 --- a/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs +++ b/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs @@ -153,7 +153,7 @@ namespace KOP_Labs.NonVisualComponents - for (int i = 1; i < myTable._dataList.Count; i++) + for (int i = 0; i < myTable._dataList.Count; i++) { var tr = new TableRow(); diff --git a/WinForm/Form1.cs b/WinForm/Form1.cs index 632e3c8..735a59e 100644 --- a/WinForm/Form1.cs +++ b/WinForm/Form1.cs @@ -45,9 +45,9 @@ namespace WinForm private void buttonTable_Click(object sender, EventArgs e) { - tableComponent.AddRow(new Book(1, "book1", "lalala")); - tableComponent.AddRow(new Book(1, "book2", "lalala2")); - tableComponent.AddRow(new Book(1, "book3", "lalala")); + tableComponent.AddRow(new Book("gfgdf",1, "book1", "lalala")); + tableComponent.AddRow(new Book("Pushkin", 1, "book2", "lalala2")); + tableComponent.AddRow(new Book("Pushkin", 1, "book3", "lalala")); } diff --git a/WinForm/NonVisualForm.cs b/WinForm/NonVisualForm.cs index fd7e0df..fceafeb 100644 --- a/WinForm/NonVisualForm.cs +++ b/WinForm/NonVisualForm.cs @@ -25,62 +25,117 @@ namespace WinForm private void buttonWordSave_Click(object sender, EventArgs e) { - string filePath = "C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Отчет.docx"; - string title = "Заголовок"; - string[,] row1 = { + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + string title = "Заголовок"; + string[,] row1 = { { "Стр1 Кол1", "Стр1 Кол2" } }; - string[,] row2 = { + string[,] row2 = { { "Стр2 Кол1", "Стр2 Кол2" } }; - string[,] row3 = { + string[,] row3 = { { "Стр3 Кол1", "Стр3 Кол3" } }; - MyTable table = new MyTable(filePath, title, new List { row1, row2, row3 }); - wordTableComponent1.CreateDoc(table); + MyTable table = new MyTable(dialog.FileName, title, new List { row1, row2, row3 }); + wordTableComponent1.CreateDoc(table); + + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } private void buttonSaveHist_Click(object sender, EventArgs e) { - histogram = new("C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Report.docx", "Третье задание", "Гистограмма", EnumLegends.Right, new List { - new DataHistogramm("Доход", "Январь", 300), new DataHistogramm("Доход", "Апрель", 600), - new DataHistogramm("Доход", "Июль", 400), new DataHistogramm("Доход", "Октябрь", 200) + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + histogram = new(dialog.FileName, "Заголовок", "Гистограмма", EnumLegends.Right, new List { + new DataHistogramm("Тихий дон", 170), new DataHistogramm("Мастер и Маргарита", 400), + new DataHistogramm("Сборник Пушкина", 240), new DataHistogramm("12 стульев", 200) }); - wordHistogramm1.CreateHistogramm(histogram); + wordHistogramm1.CreateHistogramm(histogram); + + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } List books; - Book book1 = new Book(1, "fgdf", "fdsds"); - Book book2 = new Book(1, "aa", "fdads"); - Book book3 = new Book(1, "fgdf", "ffsds"); - Book book4 = new Book(1, "ffdsff", "asds"); - Book book5 = new Book(1, "ffdsff", "asds"); + Book book1 = new Book("Pushkin", 1, "fgsddsdf", "fdsds"); + Book book2 = new Book("Pushkin", 2, "aa", "fdads"); + Book book3 = new Book("Pushkin", 3, "fgdf", "ffsds"); + Book book4 = new Book("Lermontov", 4, "ffsssff", "asdss"); + Book book5 = new Book("Lermontov", 5, "ffdsff", "asdsss"); + Book book6 = new Book("Pushkin", 6, "fgdf", "ffsds"); Dictionary colData; private void buttonHead_Click(object sender, EventArgs e) { + books = new() { - book1, book2, book3, book4, book5 + book1, book2, book3, book4, book5, book6 }; colData = new Dictionary() { - { 0, new ColumnParameters("Марка автомобиля", "Id") }, - { 1, new ColumnParameters("Модель", "Name") }, - { 2, new ColumnParameters("Год выпуска", "Annotation") } + { 0, new ColumnParameters("Автор", "Author") }, + { 1, new ColumnParameters("Id книги", "Id") }, + { 2, new ColumnParameters("Имя", "Name") }, + { 3, new ColumnParameters("Аннотация", "Annotation") } }; - MyTableWithHead myTable; - //сгруппируй - myTable = new("C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Report2.docx", "Второе задание", new List { 48, 24 }, - new List { 2000, 2000, 1500, 1500 }, books, colData); - wordTableHeaderComponent1.CreateDoc(myTable); + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + MyTableWithHead myTable = new(dialog.FileName, "Заголовок", new List { 50, 50 }, + new List { 2000, 2000, 1500, 1500 }, books.GroupBy(b => b.Author).SelectMany(a => a).ToList(), colData); + wordTableHeaderComponent1.CreateDoc(myTable); + + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + }