From 27ea0895d308db8d0317322a7f54e393a3c6cd83 Mon Sep 17 00:00:00 2001 From: dimazhelovanov Date: Fri, 3 Nov 2023 09:59:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B4=D0=B8=D0=BC=D1=8B=20=D0=B4=D0=BE=D0=BB?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KOP_Labs/Classes/Book.cs | 5 +- KOP_Labs/Classes/ColumnParameters.cs | 21 ++ KOP_Labs/Classes/DataHistogramm.cs | 24 ++ KOP_Labs/Classes/EnumLegends.cs | 17 ++ KOP_Labs/Classes/MyHistogramm.cs | 30 +++ KOP_Labs/Classes/MyTable.cs | 22 ++ KOP_Labs/Classes/MyTableWithHead.cs | 37 +++ KOP_Labs/Classes/TableParameters.cs | 27 ++ KOP_Labs/KOP_Labs.csproj | 3 +- .../WordHistogramm.Designer.cs | 36 +++ .../NonVisualComponents/WordHistogramm.cs | 88 +++++++ .../WordTableComponent.Designer.cs | 36 +++ .../NonVisualComponents/WordTableComponent.cs | 166 ++++++++++++ .../WordTableHeaderComponent.Designer.cs | 36 +++ .../WordTableHeaderComponent.cs | 243 ++++++++++++++++++ KOP_Labs/TableComponent.cs | 17 +- KOP_Labs/TextBoxComponent.cs | 4 +- WinForm/Form1.cs | 11 +- WinForm/NonVisualForm.Designer.cs | 92 +++++++ WinForm/NonVisualForm.cs | 88 +++++++ WinForm/NonVisualForm.resx | 69 +++++ WinForm/Program.cs | 2 +- WinForm/WinForm.csproj | 4 + 23 files changed, 1061 insertions(+), 17 deletions(-) create mode 100644 KOP_Labs/Classes/ColumnParameters.cs create mode 100644 KOP_Labs/Classes/DataHistogramm.cs create mode 100644 KOP_Labs/Classes/EnumLegends.cs create mode 100644 KOP_Labs/Classes/MyHistogramm.cs create mode 100644 KOP_Labs/Classes/MyTable.cs create mode 100644 KOP_Labs/Classes/MyTableWithHead.cs create mode 100644 KOP_Labs/Classes/TableParameters.cs create mode 100644 KOP_Labs/NonVisualComponents/WordHistogramm.Designer.cs create mode 100644 KOP_Labs/NonVisualComponents/WordHistogramm.cs create mode 100644 KOP_Labs/NonVisualComponents/WordTableComponent.Designer.cs create mode 100644 KOP_Labs/NonVisualComponents/WordTableComponent.cs create mode 100644 KOP_Labs/NonVisualComponents/WordTableHeaderComponent.Designer.cs create mode 100644 KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs create mode 100644 WinForm/NonVisualForm.Designer.cs create mode 100644 WinForm/NonVisualForm.cs create mode 100644 WinForm/NonVisualForm.resx diff --git a/KOP_Labs/Classes/Book.cs b/KOP_Labs/Classes/Book.cs index 81794ec..d55b2ce 100644 --- a/KOP_Labs/Classes/Book.cs +++ b/KOP_Labs/Classes/Book.cs @@ -8,6 +8,8 @@ namespace KOP_Labs.Classes { public class Book { + + public string Author { get; private set; } = string.Empty; public int Id { get; private set; } public string Name { get; private set; } = string.Empty; @@ -18,8 +20,9 @@ namespace KOP_Labs.Classes { } - public Book(int id, string name, string annotation) + public Book(string author, int id, string name, string annotation) { + Author = author; Id = id; Name = name; Annotation = annotation; diff --git a/KOP_Labs/Classes/ColumnParameters.cs b/KOP_Labs/Classes/ColumnParameters.cs new file mode 100644 index 0000000..53a4c95 --- /dev/null +++ b/KOP_Labs/Classes/ColumnParameters.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.Classes +{ + public class ColumnParameters + { + public string _nameColumn { get; set; } = string.Empty; + + public string _nameField { get; set; } = string.Empty; + + public ColumnParameters(string nameColumn, string nameField) + { + _nameColumn = nameColumn; + _nameField = nameField; + } + } +} diff --git a/KOP_Labs/Classes/DataHistogramm.cs b/KOP_Labs/Classes/DataHistogramm.cs new file mode 100644 index 0000000..49ba0c2 --- /dev/null +++ b/KOP_Labs/Classes/DataHistogramm.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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) + { + _nameSeries = nameSeries; + _nameData = nameData; + _data = data; + } + } +} diff --git a/KOP_Labs/Classes/EnumLegends.cs b/KOP_Labs/Classes/EnumLegends.cs new file mode 100644 index 0000000..b162dbe --- /dev/null +++ b/KOP_Labs/Classes/EnumLegends.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.Classes +{ + public enum EnumLegends + { + None = 0, + Left = 1, + Right = 2, + Top = 3, + Bottom = 4 + } +} diff --git a/KOP_Labs/Classes/MyHistogramm.cs b/KOP_Labs/Classes/MyHistogramm.cs new file mode 100644 index 0000000..50e84f3 --- /dev/null +++ b/KOP_Labs/Classes/MyHistogramm.cs @@ -0,0 +1,30 @@ +using DocumentFormat.OpenXml.Drawing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.Classes +{ + public class MyHistogramm + { + public string _filePath = string.Empty; + + public string _fileHeader = string.Empty; + + public string _histogramName = string.Empty; + + public EnumLegends _legends; + + public List _dataList = new(); + public MyHistogramm(string filePath, string fileHeader, string histogramName, EnumLegends legends, List dataList) { + _filePath = filePath; + _fileHeader = fileHeader; + _histogramName = histogramName; + _legends = legends; + _dataList = dataList; + } + + } +} diff --git a/KOP_Labs/Classes/MyTable.cs b/KOP_Labs/Classes/MyTable.cs new file mode 100644 index 0000000..df21d97 --- /dev/null +++ b/KOP_Labs/Classes/MyTable.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.Classes +{ + public class MyTable + { + public string _filePath = string.Empty; + + public string _fileHeader = string.Empty; + public List _dataList = new(); + public MyTable(string filePath, string fileHeader, List dataList) { + _filePath = filePath; + _fileHeader = fileHeader; + _dataList = dataList; + } + + } +} diff --git a/KOP_Labs/Classes/MyTableWithHead.cs b/KOP_Labs/Classes/MyTableWithHead.cs new file mode 100644 index 0000000..0a256d4 --- /dev/null +++ b/KOP_Labs/Classes/MyTableWithHead.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.Classes +{ + public class MyTableWithHead + { + public string _filePath = string.Empty; + + 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, + List widthCol, List dataList, Dictionary columnsSettings) + { + _filePath = filePath; + _fileHeader = fileHeader; + _heightRow = heightRow; + _widthCol = widthCol; + _dataList = dataList; + _columnsSettings = columnsSettings; + } + } +} diff --git a/KOP_Labs/Classes/TableParameters.cs b/KOP_Labs/Classes/TableParameters.cs new file mode 100644 index 0000000..e47e35e --- /dev/null +++ b/KOP_Labs/Classes/TableParameters.cs @@ -0,0 +1,27 @@ +using DocumentFormat.OpenXml.Bibliography; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.Classes +{ + public class TableParameters + { + + public string? _header { get; set; } + public int _width { get; set; } + public bool _isVisual { get; set; } + public string? _name { get; set; } + + public TableParameters(string header, int width, bool isVisual, string name) + { + + _header = header; + _width = width; + _isVisual = isVisual; + _name = name; + } + } +} diff --git a/KOP_Labs/KOP_Labs.csproj b/KOP_Labs/KOP_Labs.csproj index 80cecdc..462f673 100644 --- a/KOP_Labs/KOP_Labs.csproj +++ b/KOP_Labs/KOP_Labs.csproj @@ -8,7 +8,8 @@ - + + diff --git a/KOP_Labs/NonVisualComponents/WordHistogramm.Designer.cs b/KOP_Labs/NonVisualComponents/WordHistogramm.Designer.cs new file mode 100644 index 0000000..44cf84d --- /dev/null +++ b/KOP_Labs/NonVisualComponents/WordHistogramm.Designer.cs @@ -0,0 +1,36 @@ +namespace KOP_Labs.NonVisualComponents +{ + partial class WordHistogramm + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/KOP_Labs/NonVisualComponents/WordHistogramm.cs b/KOP_Labs/NonVisualComponents/WordHistogramm.cs new file mode 100644 index 0000000..fb53243 --- /dev/null +++ b/KOP_Labs/NonVisualComponents/WordHistogramm.cs @@ -0,0 +1,88 @@ +using Aspose.Words; +using Aspose.Words.Drawing; +using Aspose.Words.Drawing.Charts; +using KOP_Labs.Classes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KOP_Labs.NonVisualComponents +{ + public partial class WordHistogramm : Component + { + public WordHistogramm() + { + InitializeComponent(); + } + + public WordHistogramm(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateHistogramm(MyHistogramm myHistogramm) + { + if(CheckData(myHistogramm._dataList)) { + return; + } + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + Aspose.Words.Font font = builder.Font; + font.Size = 14; + font.Bold = true; + font.Color = System.Drawing.Color.Black; + font.Name = "Times New Roman"; + + ParagraphFormat paragraphFormat = builder.ParagraphFormat; + paragraphFormat.FirstLineIndent = 8; + paragraphFormat.SpaceAfter = 24; + paragraphFormat.Alignment = ParagraphAlignment.Center; + paragraphFormat.KeepTogether = true; + + builder.Writeln(myHistogramm._fileHeader); + + Shape shape = builder.InsertChart(ChartType.Column, 500, 270); + Chart chart = shape.Chart; + chart.Title.Text = myHistogramm._fileHeader; + ChartSeriesCollection seriesColl = chart.Series; + + seriesColl.Clear(); + + string[] categories = new string[] { myHistogramm._dataList[0]._nameData }; + + + foreach (var data in myHistogramm._dataList) + { + seriesColl.Add(data._nameData, categories, new double[] { data._data }); + } + + ChartLegend legend = chart.Legend; + + legend.Position = (LegendPosition)myHistogramm._legends; + legend.Overlay = true; + + + doc.Save(myHistogramm._filePath); + + } + private bool CheckData(List data) + { + foreach (var _data in data) + { + if (string.IsNullOrEmpty(_data._nameSeries) || string.IsNullOrEmpty(_data._data.ToString())) + { + return false; + } + } + + return true; + } + } +} diff --git a/KOP_Labs/NonVisualComponents/WordTableComponent.Designer.cs b/KOP_Labs/NonVisualComponents/WordTableComponent.Designer.cs new file mode 100644 index 0000000..591b1a8 --- /dev/null +++ b/KOP_Labs/NonVisualComponents/WordTableComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace KOP_Labs.NonVisualComponents +{ + partial class WordTableComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/KOP_Labs/NonVisualComponents/WordTableComponent.cs b/KOP_Labs/NonVisualComponents/WordTableComponent.cs new file mode 100644 index 0000000..d5e9aaa --- /dev/null +++ b/KOP_Labs/NonVisualComponents/WordTableComponent.cs @@ -0,0 +1,166 @@ + +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.ExtendedProperties; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; + +using KOP_Labs.Classes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using Bold = DocumentFormat.OpenXml.Wordprocessing.Bold; +using BottomBorder = DocumentFormat.OpenXml.Wordprocessing.BottomBorder; +using LeftBorder = DocumentFormat.OpenXml.Wordprocessing.LeftBorder; +using RightBorder = DocumentFormat.OpenXml.Wordprocessing.RightBorder; +using Run = DocumentFormat.OpenXml.Wordprocessing.Run; +using RunProperties = DocumentFormat.OpenXml.Wordprocessing.RunProperties; +using Table = DocumentFormat.OpenXml.Wordprocessing.Table; +using Text = DocumentFormat.OpenXml.Wordprocessing.Text; +using TopBorder = DocumentFormat.OpenXml.Wordprocessing.TopBorder; + +namespace KOP_Labs.NonVisualComponents +{ + public partial class WordTableComponent : Component + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + + public WordTableComponent() + { + InitializeComponent(); + } + + public WordTableComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateDoc(MyTable myTable) + { + if(!CheckData(myTable._dataList)) return; + _wordDocument = WordprocessingDocument.Create(myTable._filePath, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + _wordDocument.Close(); + + using (WordprocessingDocument doc = WordprocessingDocument.Open(myTable._filePath, true)) + { + + var mainDoc = doc.MainDocumentPart.Document; + mainPart.Document = new Document(); + Body body = mainPart.Document.AppendChild(new Body()); + + Paragraph headerParagraph = new Paragraph(); + + Run headerRun = new Run(new Text(myTable._fileHeader)); + RunProperties runProperties = new RunProperties(); + Bold bold = new Bold(); + runProperties.Append(bold); + + headerRun.Append(runProperties); + + headerParagraph.Append(headerRun); + + Table table = new Table(); + + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + )); + + table.AppendChild(props); + for (var i = 0; i < myTable._dataList.Count; i++) + { + var tr = new TableRow(); + + for (var j = 0; j < myTable._dataList[i].Length; j++) + { + var tc = new TableCell(); + + tc.Append(new TableCellProperties(new TableCellWidth + { + Type = TableWidthUnitValues.Dxa, + Width = "2000" + } + )); + + tc.Append(new Paragraph(new Run(new Text(myTable._dataList[i][0, j])))); + + tr.Append(tc); + } + + table.Append(tr); + } + + + + mainDoc.Body.Append(headerParagraph); + mainDoc.Body.Append(table); + + + mainDoc.Save(); + } + + + + } + + private bool CheckData(List data) + { + for (int i = 0; i < data.Count; i++) + { + for (int j = 0; j < data[i].Length; j++) + { + if (data[i][0, j] == null) { + return false; + } + } + } + + return true; + } + } + } + + \ No newline at end of file diff --git a/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.Designer.cs b/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.Designer.cs new file mode 100644 index 0000000..c236ad5 --- /dev/null +++ b/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace KOP_Labs.NonVisualComponents +{ + partial class WordTableHeaderComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs b/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs new file mode 100644 index 0000000..e0bc955 --- /dev/null +++ b/KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs @@ -0,0 +1,243 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml; +using KOP_Labs.Classes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace KOP_Labs.NonVisualComponents +{ + public partial class WordTableHeaderComponent : Component + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + public WordTableHeaderComponent() + { + InitializeComponent(); + } + + public WordTableHeaderComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateDoc(MyTableWithHead myTable) + { + if (!CheckData(myTable._dataList)) return; + _wordDocument = WordprocessingDocument.Create(myTable._filePath, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + + mainPart.Document = new Document(); + + _docBody = mainPart.Document.AppendChild(new Body()); + _wordDocument.Close(); + + using (WordprocessingDocument doc = WordprocessingDocument.Open(myTable._filePath, true)) + { + + var mainDoc = doc.MainDocumentPart.Document; + mainPart.Document = new Document(); + Body body = mainPart.Document.AppendChild(new Body()); + + + Paragraph headerParagraph = new Paragraph(); + Run headerRun = new Run(new Text(myTable._fileHeader)); + + RunProperties runProperties = new RunProperties(); + Bold bold = new Bold(); + runProperties.Append(bold); + headerRun.Append(runProperties); + + headerParagraph.Append(headerRun); + + + Table table = new Table(); + + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + )); + + table.AppendChild(props); + + var _tr = new TableRow(); + + int indexHeaderHeigh = 0; + int indexHeaderWidth = 0; + + foreach (var item in myTable._columnsSettings) + { + _tr.Append(new TableRowProperties(new TableRowHeight + { + Val = Convert.ToUInt32(myTable._heightRow[indexHeaderHeigh]) + })); + + var tc = new TableCell(); + + tc.Append(new TableCellProperties(new TableCellWidth + { + Type = TableWidthUnitValues.Dxa, + Width = myTable._widthCol[indexHeaderWidth].ToString(), + } + )); + + if (string.IsNullOrEmpty(myTable._columnsSettings[indexHeaderWidth]._nameField) || + string.IsNullOrEmpty(myTable._columnsSettings[indexHeaderWidth]._nameColumn)) + { + return; + } + + Paragraph tableHeader = new(); + + var Run = new Run(); + + var headerProperties = new RunProperties(); + + headerProperties.Append(new Bold()); + + Run.AppendChild(headerProperties); + + Run.AppendChild(new Text(item.Value._nameColumn)); + + tableHeader.AppendChild(Run); + + tc.Append(tableHeader); + + _tr.Append(tc); + + indexHeaderWidth++; + } + + table.Append(_tr); + + + indexHeaderHeigh++; + indexHeaderWidth = 0; + + + + for (int i = 1; i < myTable._dataList.Count; i++) + { + var tr = new TableRow(); + + + foreach (var item in myTable._columnsSettings) + { + tr.Append(new TableRowProperties(new TableRowHeight + { + Val = Convert.ToUInt32(myTable._heightRow[indexHeaderHeigh]) + })); + + var tc = new TableCell(); + + tc.Append(new TableCellProperties(new TableCellWidth + { + Type = TableWidthUnitValues.Dxa, + Width = myTable._widthCol[indexHeaderWidth].ToString(), + } + )); + + + foreach (var val in myTable._dataList[i].GetType().GetProperties()) + { + if (val.Name == item.Value._nameField) + { + var newParagraph = new Paragraph(); + + var newRun = new Run(); + + var runPropertiesInd = new RunProperties(); + + if (indexHeaderWidth == 0) + { + runPropertiesInd.Append(new Bold()); + } + + newRun.AppendChild(runPropertiesInd); + + newRun.AppendChild(new Text(val.GetValue(myTable._dataList[i]).ToString())); + + newParagraph.AppendChild(newRun); + + tc.Append(newParagraph); + + break; + } + } + + tr.Append(tc); + + indexHeaderWidth++; + } + + indexHeaderWidth = 0; + + table.Append(tr); + } + + + + mainDoc.Body.Append(headerParagraph); + + mainDoc.Body.Append(table); + + mainDoc.Save(); + } + } + + private bool CheckData(List dataList) + { + foreach (var data in dataList) + { + foreach (var value in data.GetType().GetProperties()) + { + + if (string.IsNullOrEmpty(value.GetValue(data).ToString())) + { + return false; + } + } + } + + return true; + } + + } +} diff --git a/KOP_Labs/TableComponent.cs b/KOP_Labs/TableComponent.cs index 065b727..353ea81 100644 --- a/KOP_Labs/TableComponent.cs +++ b/KOP_Labs/TableComponent.cs @@ -1,4 +1,5 @@ -using System; +using KOP_Labs.Classes; +using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; @@ -33,16 +34,16 @@ namespace KOP_Labs { InitializeComponent(); } - public void TableConfiguration(int columnsQuantity, List headers, List widths, List isVisual, List names) + public void TableConfiguration(int countCol, List parameters) { - for (int i = 0; i < columnsQuantity; i++) - + if (parameters.Count != parameters.Count) { return; } + for (int i = 0; i < countCol; i++) { DataGridViewColumn column = new DataGridViewColumn(); - column.Name = names[i]; - column.HeaderText = headers[i]; - column.Width = widths[i]; - column.Visible = isVisual[i]; + column.Name = parameters[i]._name; + column.HeaderText = parameters[i]._header; + column.Width = parameters[i]._width; + column.Visible = parameters[i]._isVisual; column.CellTemplate = new DataGridViewTextBoxCell(); dataGridView.Columns.Add(column); diff --git a/KOP_Labs/TextBoxComponent.cs b/KOP_Labs/TextBoxComponent.cs index 3155acc..4fa13fa 100644 --- a/KOP_Labs/TextBoxComponent.cs +++ b/KOP_Labs/TextBoxComponent.cs @@ -1,4 +1,5 @@ -using KOP_Labs.Exceptions; +using DocumentFormat.OpenXml.Drawing.Diagrams; +using KOP_Labs.Exceptions; using System; using System.Collections.Generic; using System.ComponentModel; @@ -38,6 +39,7 @@ namespace KOP_Labs return null; + } set { diff --git a/WinForm/Form1.cs b/WinForm/Form1.cs index ecedf5a..632e3c8 100644 --- a/WinForm/Form1.cs +++ b/WinForm/Form1.cs @@ -54,11 +54,12 @@ namespace WinForm private void buttonConfig_Click(object sender, EventArgs e) { - tableComponent.TableConfiguration(3, - new List() { "fds", "fds", "fds" }, - new List() { 80, 80, 80 }, - new List { true, true, true }, - new List { "Id", "Name", "Annotation" }); + List tableParameters = new List(); + tableParameters.Add(new TableParameters("fds", 80, true, "Id")); + tableParameters.Add(new TableParameters("fds", 80, true, "Name")); + tableParameters.Add(new TableParameters("fds", 80, true, "Annotation")); + + tableComponent.TableConfiguration(3, tableParameters); } private void buttonCleatTable_Click(object sender, EventArgs e) diff --git a/WinForm/NonVisualForm.Designer.cs b/WinForm/NonVisualForm.Designer.cs new file mode 100644 index 0000000..eb479bc --- /dev/null +++ b/WinForm/NonVisualForm.Designer.cs @@ -0,0 +1,92 @@ +namespace WinForm +{ + partial class NonVisualForm + { + /// + /// 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() + { + components = new System.ComponentModel.Container(); + wordTableComponent1 = new KOP_Labs.NonVisualComponents.WordTableComponent(components); + buttonWordSave = new Button(); + buttonSaveHist = new Button(); + wordHistogramm1 = new KOP_Labs.NonVisualComponents.WordHistogramm(components); + wordTableHeaderComponent1 = new KOP_Labs.NonVisualComponents.WordTableHeaderComponent(components); + buttonHead = new Button(); + SuspendLayout(); + // + // buttonWordSave + // + buttonWordSave.Location = new Point(54, 262); + buttonWordSave.Name = "buttonWordSave"; + buttonWordSave.Size = new Size(94, 29); + buttonWordSave.TabIndex = 0; + buttonWordSave.Text = "Сохранить"; + buttonWordSave.UseVisualStyleBackColor = true; + buttonWordSave.Click += buttonWordSave_Click; + // + // buttonSaveHist + // + buttonSaveHist.Location = new Point(279, 262); + buttonSaveHist.Name = "buttonSaveHist"; + buttonSaveHist.Size = new Size(94, 29); + buttonSaveHist.TabIndex = 1; + buttonSaveHist.Text = "xlsx"; + buttonSaveHist.UseVisualStyleBackColor = true; + buttonSaveHist.Click += buttonSaveHist_Click; + // + // buttonHead + // + buttonHead.Location = new Point(499, 262); + buttonHead.Name = "buttonHead"; + buttonHead.Size = new Size(169, 29); + buttonHead.TabIndex = 2; + buttonHead.Text = "Таблица с шапкой"; + buttonHead.UseVisualStyleBackColor = true; + buttonHead.Click += buttonHead_Click; + // + // NonVisualForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonHead); + Controls.Add(buttonSaveHist); + Controls.Add(buttonWordSave); + Name = "NonVisualForm"; + Text = "NonVisualForm"; + ResumeLayout(false); + } + + #endregion + + private KOP_Labs.NonVisualComponents.WordTableComponent wordTableComponent1; + private Button buttonWordSave; + private Button buttonSaveHist; + private KOP_Labs.NonVisualComponents.WordHistogramm wordHistogramm1; + private KOP_Labs.NonVisualComponents.WordTableHeaderComponent wordTableHeaderComponent1; + private Button buttonHead; + } +} \ No newline at end of file diff --git a/WinForm/NonVisualForm.cs b/WinForm/NonVisualForm.cs new file mode 100644 index 0000000..fd7e0df --- /dev/null +++ b/WinForm/NonVisualForm.cs @@ -0,0 +1,88 @@ +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Spreadsheet; +using KOP_Labs.Classes; +using Microsoft.VisualBasic.ApplicationServices; +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 WinForm +{ + public partial class NonVisualForm : Form + { + public NonVisualForm() + { + InitializeComponent(); + } + MyHistogramm histogram; + + + private void buttonWordSave_Click(object sender, EventArgs e) + { + string filePath = "C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Отчет.docx"; + string title = "Заголовок"; + string[,] row1 = { + { "Стр1 Кол1", "Стр1 Кол2" } + }; + + string[,] row2 = { + { "Стр2 Кол1", "Стр2 Кол2" } + }; + + string[,] row3 = { + { "Стр3 Кол1", "Стр3 Кол3" } + }; + MyTable table = new MyTable(filePath, title, new List { row1, row2, row3 }); + wordTableComponent1.CreateDoc(table); + + } + + 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) + }); + + wordHistogramm1.CreateHistogramm(histogram); + + } + + 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"); + + Dictionary colData; + private void buttonHead_Click(object sender, EventArgs e) + { + books = new() + { + book1, book2, book3, book4, book5 + }; + + colData = new Dictionary() + { + { 0, new ColumnParameters("Марка автомобиля", "Id") }, + { 1, new ColumnParameters("Модель", "Name") }, + { 2, 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); + + + } + } +} diff --git a/WinForm/NonVisualForm.resx b/WinForm/NonVisualForm.resx new file mode 100644 index 0000000..49a07ee --- /dev/null +++ b/WinForm/NonVisualForm.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + + 230, 17 + + + 410, 17 + + \ No newline at end of file diff --git a/WinForm/Program.cs b/WinForm/Program.cs index a2172dc..e639b4c 100644 --- a/WinForm/Program.cs +++ b/WinForm/Program.cs @@ -11,7 +11,7 @@ namespace WinForm // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new NonVisualForm()); } } } \ No newline at end of file diff --git a/WinForm/WinForm.csproj b/WinForm/WinForm.csproj index ea1be9c..215edb0 100644 --- a/WinForm/WinForm.csproj +++ b/WinForm/WinForm.csproj @@ -8,6 +8,10 @@ enable + + + +