From b4a83591995578f6c5f73c6fbe723bc631c6cfe5 Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Mon, 30 Sep 2024 20:51:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=B0=20=D0=B2=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5?= =?UTF-8?q?=D1=81=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP/Components/Components.csproj | 6 + .../WordLineChart.Designer.cs | 36 +++++ .../NonVisualComponents/WordLineChart.cs | 91 +++++++++++ .../NonVisualComponents/WordTable.Designer.cs | 36 +++++ .../NonVisualComponents/WordTable.cs | 133 ++++++++++++++++ .../NonVisualComponents/WordText.Designer.cs | 36 +++++ .../NonVisualComponents/WordText.cs | 142 ++++++++++++++++++ COP/Components/SupportClasses/BigTable.cs | 31 ++++ .../SupportClasses/ColumnDefenition.cs | 15 ++ .../SupportClasses/DataLineChart.cs | 24 +++ .../SupportClasses/Enums/EnumAreaLegend.cs | 23 +++ COP/Components/SupportClasses/LargeText.cs | 24 +++ .../SupportClasses/SimpleLineChart.cs | 31 ++++ COP/WinForms/FormForComponents.cs | 2 + COP/WinForms/FormWord.Designer.cs | 134 +++++++++++++++++ COP/WinForms/FormWord.cs | 136 +++++++++++++++++ COP/WinForms/FormWord.resx | 120 +++++++++++++++ COP/WinForms/Program.cs | 2 +- COP/WinForms/WinForms.csproj | 4 + COP/WinForms/Worker.cs | 6 + 20 files changed, 1031 insertions(+), 1 deletion(-) create mode 100644 COP/Components/NonVisualComponents/WordLineChart.Designer.cs create mode 100644 COP/Components/NonVisualComponents/WordLineChart.cs create mode 100644 COP/Components/NonVisualComponents/WordTable.Designer.cs create mode 100644 COP/Components/NonVisualComponents/WordTable.cs create mode 100644 COP/Components/NonVisualComponents/WordText.Designer.cs create mode 100644 COP/Components/NonVisualComponents/WordText.cs create mode 100644 COP/Components/SupportClasses/BigTable.cs create mode 100644 COP/Components/SupportClasses/ColumnDefenition.cs create mode 100644 COP/Components/SupportClasses/DataLineChart.cs create mode 100644 COP/Components/SupportClasses/Enums/EnumAreaLegend.cs create mode 100644 COP/Components/SupportClasses/LargeText.cs create mode 100644 COP/Components/SupportClasses/SimpleLineChart.cs create mode 100644 COP/WinForms/FormWord.Designer.cs create mode 100644 COP/WinForms/FormWord.cs create mode 100644 COP/WinForms/FormWord.resx diff --git a/COP/Components/Components.csproj b/COP/Components/Components.csproj index 060aa1c..47dd229 100644 --- a/COP/Components/Components.csproj +++ b/COP/Components/Components.csproj @@ -7,4 +7,10 @@ enable + + + + + + diff --git a/COP/Components/NonVisualComponents/WordLineChart.Designer.cs b/COP/Components/NonVisualComponents/WordLineChart.Designer.cs new file mode 100644 index 0000000..0c99b7b --- /dev/null +++ b/COP/Components/NonVisualComponents/WordLineChart.Designer.cs @@ -0,0 +1,36 @@ +namespace Components.NonVisualComponents +{ + partial class WordLineChart + { + /// + /// Обязательная переменная конструктора. + /// + 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/COP/Components/NonVisualComponents/WordLineChart.cs b/COP/Components/NonVisualComponents/WordLineChart.cs new file mode 100644 index 0000000..7184e0f --- /dev/null +++ b/COP/Components/NonVisualComponents/WordLineChart.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Reflection.Metadata; +using System.Text; +using System.Threading.Tasks; +using Aspose.Words; +using Aspose.Words.Drawing; +using Aspose.Words.Drawing.Charts; +using Components.SupportClasses; +using Document = Aspose.Words.Document; + +namespace Components.NonVisualComponents +{ + public partial class WordLineChart : Component + { + public WordLineChart() + { + InitializeComponent(); + } + + public WordLineChart(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + public void AddLineChart(SimpleLineChart simpleLineChart) + { + if (!CheckData(simpleLineChart.DataList)) + { + throw new Exception("Не данные заполнены"); + } + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + Aspose.Words.Font font = builder.Font; + font.Size = 24; + font.Bold = true; + font.Color = 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(simpleLineChart.FileHeader); + + Shape shape = builder.InsertChart(ChartType.Line, 500, 270); + + Chart chart = shape.Chart; + + chart.Title.Text = simpleLineChart.LineChartName; + + ChartSeriesCollection seriesColl = chart.Series; + + Console.WriteLine(seriesColl.Count); + + seriesColl.Clear(); + + foreach (var data in simpleLineChart.DataList) + { + seriesColl.Add(data.NameSeries, data.NameData, data.Data); + } + + ChartLegend legend = chart.Legend; + + legend.Position = (LegendPosition)simpleLineChart.AreaLegend; + + legend.Overlay = true; + + doc.Save(simpleLineChart.FilePath); + } + static bool CheckData(List data) + { + foreach (var _data in data) + { + if (string.IsNullOrEmpty(_data.NameSeries) || string.IsNullOrEmpty(_data.NameData.ToString()) || string.IsNullOrEmpty(_data.Data.ToString())) + { + return false; + } + } + + return true; + } + } +} diff --git a/COP/Components/NonVisualComponents/WordTable.Designer.cs b/COP/Components/NonVisualComponents/WordTable.Designer.cs new file mode 100644 index 0000000..ee151e2 --- /dev/null +++ b/COP/Components/NonVisualComponents/WordTable.Designer.cs @@ -0,0 +1,36 @@ +namespace Components.NonVisualComponents +{ + partial class WordTable + { + /// + /// Обязательная переменная конструктора. + /// + 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/COP/Components/NonVisualComponents/WordTable.cs b/COP/Components/NonVisualComponents/WordTable.cs new file mode 100644 index 0000000..13b8551 --- /dev/null +++ b/COP/Components/NonVisualComponents/WordTable.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Components.SupportClasses; +using Aspose.Words; +using Aspose.Words.Tables; + +namespace Components.NonVisualComponents +{ + public partial class WordTable : Component + { + public WordTable() + { + InitializeComponent(); + } + + public WordTable(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + public void CreateTable(BigTable bigTable) + { + if (bigTable.Data == null) + { + throw new ArgumentException("Не заданы все данные"); + } + + foreach (var columnDefinition in bigTable.ColumnDefinitions) + { + if (string.IsNullOrEmpty(columnDefinition.PropertyName)) + { + throw new ArgumentException($"Не задано свойство столбца: {columnDefinition.Header}"); + } + } + + Document document = new Document(); + DocumentBuilder builder = new DocumentBuilder(document); + + Style titleStyle = builder.Document.Styles.Add(StyleType.Paragraph, "Title"); + titleStyle.Font.Size = 16; + titleStyle.Font.Bold = true; + + builder.ParagraphFormat.Style = titleStyle; + builder.Writeln(bigTable.DocumentTitle); + + Table table = builder.StartTable(); + + + foreach (var columnDefinition in bigTable.ColumnDefinitions) + { + builder.InsertCell(); + builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition.Weight); + builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; + builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; + builder.Write(columnDefinition.Header); + } + + foreach (var mergedColumn in bigTable.MergedColumns) + { + int startCellIndex = mergedColumn[0]; + int endCellIndex = mergedColumn[mergedColumn.Length - 1]; + + for (int i = startCellIndex; i <= endCellIndex; i++) + { + table.Rows[0].Cells[i].CellFormat.HorizontalMerge = CellMerge.First; + table.Rows[0].Cells[i].CellFormat.VerticalMerge = CellMerge.First; + } + + for (int i = startCellIndex + 1; i <= endCellIndex; i++) + { + table.Rows[0].Cells[i].CellFormat.HorizontalMerge = CellMerge.Previous; + table.Rows[0].Cells[i].CellFormat.VerticalMerge = CellMerge.First; + } + + + } + builder.EndRow(); + + foreach (var columnDefinition2 in bigTable.ColumnDefinitions2) + { + builder.InsertCell(); + builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition2.Weight); + builder.Write(columnDefinition2.Header); + } + + builder.EndRow(); + + int columnIndex; + foreach (var columnDefinition in bigTable.ColumnDefinitions) + { + string currentPropertyName = columnDefinition.PropertyName; + columnIndex = 0; + foreach (var columnDefinition2 in bigTable.ColumnDefinitions2) + { + string currentPropertyName1 = columnDefinition2.PropertyName; + + if (currentPropertyName == currentPropertyName1) + { + table.Rows[0].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.First; + table.Rows[1].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.Previous; + + } + columnIndex++; + } + } + + foreach (var item in bigTable.Data) + { + foreach (var columnDefinition2 in bigTable.ColumnDefinitions2) + { + builder.InsertCell(); + var propertyValue = item.GetType() + .GetProperty(columnDefinition2.PropertyName)? + .GetValue(item)?.ToString(); + + builder.Write(propertyValue ?? ""); + } + + builder.EndRow(); + } + + builder.EndTable(); + + document.Save(bigTable.FilePath); + } + } +} diff --git a/COP/Components/NonVisualComponents/WordText.Designer.cs b/COP/Components/NonVisualComponents/WordText.Designer.cs new file mode 100644 index 0000000..2c732f1 --- /dev/null +++ b/COP/Components/NonVisualComponents/WordText.Designer.cs @@ -0,0 +1,36 @@ +namespace Components.NonVisualComponents +{ + partial class WordText + { + /// + /// Обязательная переменная конструктора. + /// + 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/COP/Components/NonVisualComponents/WordText.cs b/COP/Components/NonVisualComponents/WordText.cs new file mode 100644 index 0000000..cbe643a --- /dev/null +++ b/COP/Components/NonVisualComponents/WordText.cs @@ -0,0 +1,142 @@ +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.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using Components.SupportClasses; +using Aspose.Words; +using Document = DocumentFormat.OpenXml.Wordprocessing.Document; +using Paragraph = DocumentFormat.OpenXml.Wordprocessing.Paragraph; +using Run = DocumentFormat.OpenXml.Wordprocessing.Run; +using Body = DocumentFormat.OpenXml.Wordprocessing.Body; + +namespace Components.NonVisualComponents +{ + public partial class WordText : Component + { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + public WordText() + { + InitializeComponent(); + } + + public WordText(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + public void CreateWordText(LargeText largeText) + { + if (string.IsNullOrEmpty(largeText.FilePath) || string.IsNullOrEmpty(largeText.DocumentTitle) || !CheckData(largeText.TextData)) + { + throw new Exception("Не все данные заполнены"); + } + _wordDocument = WordprocessingDocument.Create(largeText.FilePath, WordprocessingDocumentType.Document); + + //вытаскиваем главную часть из вордовского документа + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + + mainPart.Document = new Document(); + + //генерируем тело основной части документа + _docBody = mainPart.Document.AppendChild(new Body()); + + _wordDocument.Clone(); + + AddText(largeText); + } + + private void AddText(LargeText largeText) + { + using (var document = WordprocessingDocument.Open(largeText.FilePath, true)) + { + var doc = document.MainDocumentPart.Document; + + #region Создание заголовка + + ParagraphProperties paragraphProperties = new(); + + paragraphProperties.AppendChild(new Justification + { + Val = JustificationValues.Center + }); + + paragraphProperties.AppendChild(new Indentation()); + + Paragraph header = new(); + + header.AppendChild(paragraphProperties); + + var docRun = new Run(); + + var properties = new RunProperties(); + + properties.AppendChild(new FontSize + { + Val = "48" + }); + + properties.AppendChild(new Bold()); + + docRun.AppendChild(properties); + + docRun.AppendChild(new Text(largeText.DocumentTitle)); + + header.AppendChild(docRun); + doc.Body.Append(header); + #endregion + + #region Создание текста + for (int i = 0; i < largeText.TextData.Length; i++) + { + ParagraphProperties paragraphProperties2 = new(); + + paragraphProperties2.AppendChild(new Justification + { + Val = JustificationValues.Both + }); + + paragraphProperties2.AppendChild(new Indentation()); + + Paragraph text = new(); + + text.AppendChild(paragraphProperties2); + + var docRun2 = new Run(); + + var properties2 = new RunProperties(); + + properties2.AppendChild(new FontSize + { + Val = "24" + }); + + docRun2.AppendChild(properties2); + docRun2.AppendChild(new Text(largeText.TextData[i])); + + text.AppendChild(docRun2); + doc.Body.Append(text); + } + #endregion + doc.Save(); + } + } + + bool CheckData(string[] data) + { + for (int i = 0; i < data.Length; i++) + { + if (string.IsNullOrEmpty(data[i])) return false; + } + + return true; + } + } +} diff --git a/COP/Components/SupportClasses/BigTable.cs b/COP/Components/SupportClasses/BigTable.cs new file mode 100644 index 0000000..fb29a03 --- /dev/null +++ b/COP/Components/SupportClasses/BigTable.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.SupportClasses +{ + public class BigTable + { + public string FilePath = string.Empty; + + public string DocumentTitle = string.Empty; + + public List ColumnDefinitions; + public List ColumnDefinitions2; + + public List Data; + + public List MergedColumns; + public BigTable(string filePath, string documentTitle, List columnDefinitions, List columnDefinitions2, List data, List mergedColumns) + { + FilePath = filePath; + DocumentTitle = documentTitle; + ColumnDefinitions = columnDefinitions; + Data = data; + MergedColumns = mergedColumns; + ColumnDefinitions2 = columnDefinitions2; + } + } +} diff --git a/COP/Components/SupportClasses/ColumnDefenition.cs b/COP/Components/SupportClasses/ColumnDefenition.cs new file mode 100644 index 0000000..e419247 --- /dev/null +++ b/COP/Components/SupportClasses/ColumnDefenition.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.SupportClasses +{ + public class ColumnDefinition + { + public string Header; + public string PropertyName; + public double Weight; + } +} diff --git a/COP/Components/SupportClasses/DataLineChart.cs b/COP/Components/SupportClasses/DataLineChart.cs new file mode 100644 index 0000000..601d040 --- /dev/null +++ b/COP/Components/SupportClasses/DataLineChart.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.SupportClasses +{ + public class DataLineChart + { + public string NameSeries { get; set; } = string.Empty; + + public string[] NameData { get; set; } + + public double[] Data { get; set; } + + public DataLineChart(string nameSeries, string[] nameData, double[] data) + { + NameSeries = nameSeries; + NameData = nameData; + Data = data; + } + } +} diff --git a/COP/Components/SupportClasses/Enums/EnumAreaLegend.cs b/COP/Components/SupportClasses/Enums/EnumAreaLegend.cs new file mode 100644 index 0000000..10d484b --- /dev/null +++ b/COP/Components/SupportClasses/Enums/EnumAreaLegend.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.SupportClasses.Enums +{ + public enum EnumAreaLegend + { + None, + + Left, + + Top, + + Right, + + Bottom, + + TopRight + } +} diff --git a/COP/Components/SupportClasses/LargeText.cs b/COP/Components/SupportClasses/LargeText.cs new file mode 100644 index 0000000..de22ca4 --- /dev/null +++ b/COP/Components/SupportClasses/LargeText.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.SupportClasses +{ + public class LargeText + { + public string FilePath = string.Empty; + + public string DocumentTitle = string.Empty; + + public string[] TextData; + + public LargeText(string filePath, string documentTitle, string[] textData) + { + FilePath = filePath; + DocumentTitle = documentTitle; + TextData = textData; + } + } +} diff --git a/COP/Components/SupportClasses/SimpleLineChart.cs b/COP/Components/SupportClasses/SimpleLineChart.cs new file mode 100644 index 0000000..876699d --- /dev/null +++ b/COP/Components/SupportClasses/SimpleLineChart.cs @@ -0,0 +1,31 @@ +using Components.SupportClasses.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.SupportClasses +{ + public class SimpleLineChart + { + public string FilePath = string.Empty; + + public string FileHeader = string.Empty; + + public string LineChartName = string.Empty; + + public EnumAreaLegend AreaLegend; + + public List DataList = new(); + + public SimpleLineChart(string filePath, string fileHeader, string lineChartName, EnumAreaLegend areaLegend, List dataList) + { + FilePath = filePath; + FileHeader = fileHeader; + LineChartName = lineChartName; + AreaLegend = areaLegend; + DataList = dataList; + } + } +} diff --git a/COP/WinForms/FormForComponents.cs b/COP/WinForms/FormForComponents.cs index 9cd06d2..2b516ee 100644 --- a/COP/WinForms/FormForComponents.cs +++ b/COP/WinForms/FormForComponents.cs @@ -69,5 +69,7 @@ namespace WinForms MessageBox.Show(ex.Message); } } + + } } diff --git a/COP/WinForms/FormWord.Designer.cs b/COP/WinForms/FormWord.Designer.cs new file mode 100644 index 0000000..632dcc7 --- /dev/null +++ b/COP/WinForms/FormWord.Designer.cs @@ -0,0 +1,134 @@ +namespace WinForms +{ + partial class FormWord + { + /// + /// 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(); + wordText = new Components.NonVisualComponents.WordText(components); + groupBox1 = new GroupBox(); + button1 = new Button(); + wordLineChart = new Components.NonVisualComponents.WordLineChart(components); + groupBox3 = new GroupBox(); + button3 = new Button(); + groupBox2 = new GroupBox(); + button2 = new Button(); + wordTable = new Components.NonVisualComponents.WordTable(components); + groupBox1.SuspendLayout(); + groupBox3.SuspendLayout(); + groupBox2.SuspendLayout(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(button1); + groupBox1.Location = new Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(120, 80); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Большой текст"; + // + // button1 + // + button1.Location = new Point(6, 45); + button1.Name = "button1"; + button1.Size = new Size(94, 29); + button1.TabIndex = 0; + button1.Text = "Создать"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // + // groupBox3 + // + groupBox3.Controls.Add(button3); + groupBox3.Location = new Point(331, 12); + groupBox3.Name = "groupBox3"; + groupBox3.Size = new Size(120, 80); + groupBox3.TabIndex = 1; + groupBox3.TabStop = false; + groupBox3.Text = "Линейная диаграмма"; + // + // button3 + // + button3.Location = new Point(6, 45); + button3.Name = "button3"; + button3.Size = new Size(94, 29); + button3.TabIndex = 0; + button3.Text = "Создать"; + button3.UseVisualStyleBackColor = true; + button3.Click += button3_Click; + // + // groupBox2 + // + groupBox2.Controls.Add(button2); + groupBox2.Location = new Point(171, 12); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(120, 80); + groupBox2.TabIndex = 1; + groupBox2.TabStop = false; + groupBox2.Text = "Таблица"; + // + // button2 + // + button2.Location = new Point(6, 45); + button2.Name = "button2"; + button2.Size = new Size(94, 29); + button2.TabIndex = 0; + button2.Text = "Создать"; + button2.UseVisualStyleBackColor = true; + button2.Click += button2_Click; + // + // FormWord + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(463, 114); + Controls.Add(groupBox2); + Controls.Add(groupBox3); + Controls.Add(groupBox1); + Name = "FormWord"; + Text = "Невизуальные компоненты"; + groupBox1.ResumeLayout(false); + groupBox3.ResumeLayout(false); + groupBox2.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Components.NonVisualComponents.WordText wordText; + private GroupBox groupBox1; + private Button button1; + private Components.NonVisualComponents.WordLineChart wordLineChart; + private GroupBox groupBox3; + private Button button3; + private GroupBox groupBox2; + private Button button2; + private Components.NonVisualComponents.WordTable wordTable; + } +} \ No newline at end of file diff --git a/COP/WinForms/FormWord.cs b/COP/WinForms/FormWord.cs new file mode 100644 index 0000000..7b60840 --- /dev/null +++ b/COP/WinForms/FormWord.cs @@ -0,0 +1,136 @@ +using Components.NonVisualComponents; +using Components.SupportClasses.Enums; +using Components.SupportClasses; +using DocumentFormat.OpenXml.Wordprocessing; +using Components.Components; +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; +using static System.Net.WebRequestMethods; + +namespace WinForms +{ + public partial class FormWord : Form + { + string[] testArray = { "У психолога Сергея Васнецова большие проблемы. От него ушла жена, оставив пятерых дочерей. Да каких - с ума сойти! Первая - модница, вторая - отличница, третья - неформалка, " + + "четвертая - спортсменка, а пятая - совсем крошка Пуговка. Все очень шумные. " + + "И никто не умеет убирать и готовить! Кажется, доктору Васнецову самому скоро понадобится помощь специалиста..."}; + public FormWord() + { + InitializeComponent(); + } + private void button1_Click(object sender, EventArgs e) + { + //фильтрация файлов для диалогового окна + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + LargeText largeText = new(dialog.FileName, "Папины дочки", testArray); + wordText.CreateWordText(largeText); + + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void button2_Click(object sender, EventArgs e) + { + List mergedColumns = new() + { + new int[] { 0, 1, 2 } + }; + + + + List columnDefinitions = new List + { + new ColumnDefinition { Header = "Идентификатор", PropertyName = "Id", Weight = 35 }, + new ColumnDefinition { Header = "Пол", PropertyName = "Gender", Weight = 35 }, + new ColumnDefinition { Header = "Имя", PropertyName = "Name", Weight = 10 }, + new ColumnDefinition { Header = "Фамилия", PropertyName = "LastName", Weight = 20 }, + + }; + + List columnDefinitions2 = new List + { + new ColumnDefinition { Header = "Возраст", PropertyName = "Age", Weight = 20 }, + new ColumnDefinition { Header = "Опыт", PropertyName = "Experience", Weight = 20 }, + new ColumnDefinition { Header = "Должность", PropertyName = "Position", Weight = 20 } + }; + + List data = new List + { + new Worker {Id = 1, Gender = "мужской", Name = "Егор", LastName = "Булаткин", Age = 30, Experience = 10, Position="певец"}, + new Worker {Id = 2, Gender = "женский", Name = "Алевтина", LastName = "Антонова", Age = 22, Experience = 3, Position="стоматолог"}, + new Worker {Id = 3, Gender = "женский", Name = "Брошка", LastName = "Кулончикова", Age = 25, Experience = 15, Position="комик"}, + new Worker {Id = 4, Gender = "мужской", Name = "Милош", LastName = "Коваль", Age = 33, Experience = 1, Position="актер"}, + new Worker {Id = 5, Gender = "женский", Name = "Василина", LastName = "Моисеева", Age = 20, Experience = 5, Position="Программист"} + }; + + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + BigTable bigTable = new(dialog.FileName, "Задание 2", columnDefinitions, columnDefinitions2, data, mergedColumns); + wordTable.CreateTable(bigTable); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void button3_Click(object sender, EventArgs e) + { + //фильтрация файлов для диалогового окна + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + string[] month = { "Январь", "Февраль", "Март" }; + double[] profit1 = { 300, 440, 270 }; + double[] profit2 = { 500, 620, 310 }; + double[] profit3 = { 420, 189, 430 }; + SimpleLineChart lineChart = new(dialog.FileName, "Третье задание", "График прибыли", EnumAreaLegend.Right, new List { + new DataLineChart("Компания 1", month, profit1), new DataLineChart("Компания 2", month, profit2), new DataLineChart("Компания 3", month, profit3), + }); + + wordLineChart.AddLineChart(lineChart); + + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} + diff --git a/COP/WinForms/FormWord.resx b/COP/WinForms/FormWord.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/WinForms/FormWord.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/COP/WinForms/Program.cs b/COP/WinForms/Program.cs index 09cad38..c1b2fb8 100644 --- a/COP/WinForms/Program.cs +++ b/COP/WinForms/Program.cs @@ -11,7 +11,7 @@ namespace WinForms // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormForComponents()); + Application.Run(new FormWord()); } } } \ No newline at end of file diff --git a/COP/WinForms/WinForms.csproj b/COP/WinForms/WinForms.csproj index a813ce4..598625a 100644 --- a/COP/WinForms/WinForms.csproj +++ b/COP/WinForms/WinForms.csproj @@ -8,6 +8,10 @@ enable + + + + diff --git a/COP/WinForms/Worker.cs b/COP/WinForms/Worker.cs index 3795c9b..c46b3b5 100644 --- a/COP/WinForms/Worker.cs +++ b/COP/WinForms/Worker.cs @@ -8,6 +8,10 @@ namespace WinForms { public class Worker { + public int Id { get; set; } + + public string Gender { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; public string LastName { get; set; } = string.Empty; @@ -15,5 +19,7 @@ namespace WinForms public int Age { get; set; } public int Experience { get; set; } + + public string Position { get; set; } = string.Empty; } }