From 3feb33895e4571b1c1c7c350de81aa1188bae4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= <Илья@WIN-RANNDDD> Date: Sun, 22 Sep 2024 13:24:14 +0400 Subject: [PATCH] =?UTF-8?q?1=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HelperModels/WordLongTextInfo.cs | 11 ++ .../WordDiagramComponent.Designer.cs | 36 +++++ .../WordDiagramComponent.cs | 19 +++ .../WordLongTextComponent.Designer.cs | 36 +++++ .../WordLongTextComponent.cs | 95 +++++++++++++ .../WordTableComponent.Designer.cs | 36 +++++ .../NonVisualComponents/WordTableComponent.cs | 19 +++ COP/RodionovLibrary/RodionovLibrary.csproj | 4 + COP/WinForms/FormTest.Designer.cs | 125 ++++++++++++++---- COP/WinForms/FormTest.cs | 35 +++++ COP/WinForms/FormTest.resx | 3 + 11 files changed, 390 insertions(+), 29 deletions(-) create mode 100644 COP/RodionovLibrary/NonVisualComponents/HelperModels/WordLongTextInfo.cs create mode 100644 COP/RodionovLibrary/NonVisualComponents/WordDiagramComponent.Designer.cs create mode 100644 COP/RodionovLibrary/NonVisualComponents/WordDiagramComponent.cs create mode 100644 COP/RodionovLibrary/NonVisualComponents/WordLongTextComponent.Designer.cs create mode 100644 COP/RodionovLibrary/NonVisualComponents/WordLongTextComponent.cs create mode 100644 COP/RodionovLibrary/NonVisualComponents/WordTableComponent.Designer.cs create mode 100644 COP/RodionovLibrary/NonVisualComponents/WordTableComponent.cs diff --git a/COP/RodionovLibrary/NonVisualComponents/HelperModels/WordLongTextInfo.cs b/COP/RodionovLibrary/NonVisualComponents/HelperModels/WordLongTextInfo.cs new file mode 100644 index 0000000..6b9adf4 --- /dev/null +++ b/COP/RodionovLibrary/NonVisualComponents/HelperModels/WordLongTextInfo.cs @@ -0,0 +1,11 @@ +namespace RodionovLibrary.NonVisualComponents.HelperModels +{ + public class WordLongTextInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public string[] Paragraphs { get; set; } = Array.Empty(); + } +} diff --git a/COP/RodionovLibrary/NonVisualComponents/WordDiagramComponent.Designer.cs b/COP/RodionovLibrary/NonVisualComponents/WordDiagramComponent.Designer.cs new file mode 100644 index 0000000..dd06f44 --- /dev/null +++ b/COP/RodionovLibrary/NonVisualComponents/WordDiagramComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace RodionovLibrary.NonVisualComponents +{ + partial class WordDiagramComponent + { + /// + /// Обязательная переменная конструктора. + /// + 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/RodionovLibrary/NonVisualComponents/WordDiagramComponent.cs b/COP/RodionovLibrary/NonVisualComponents/WordDiagramComponent.cs new file mode 100644 index 0000000..ba7e42a --- /dev/null +++ b/COP/RodionovLibrary/NonVisualComponents/WordDiagramComponent.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; + +namespace RodionovLibrary.NonVisualComponents +{ + public partial class WordDiagramComponent : Component + { + public WordDiagramComponent() + { + InitializeComponent(); + } + + public WordDiagramComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + } +} diff --git a/COP/RodionovLibrary/NonVisualComponents/WordLongTextComponent.Designer.cs b/COP/RodionovLibrary/NonVisualComponents/WordLongTextComponent.Designer.cs new file mode 100644 index 0000000..6ad1c80 --- /dev/null +++ b/COP/RodionovLibrary/NonVisualComponents/WordLongTextComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace RodionovLibrary.NonVisualComponents +{ + partial class WordLongTextComponent + { + /// + /// Обязательная переменная конструктора. + /// + 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/RodionovLibrary/NonVisualComponents/WordLongTextComponent.cs b/COP/RodionovLibrary/NonVisualComponents/WordLongTextComponent.cs new file mode 100644 index 0000000..59f660d --- /dev/null +++ b/COP/RodionovLibrary/NonVisualComponents/WordLongTextComponent.cs @@ -0,0 +1,95 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using RodionovLibrary.NonVisualComponents.HelperModels; +using System.ComponentModel; + +namespace RodionovLibrary.NonVisualComponents +{ + public partial class WordLongTextComponent : Component + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + + public WordLongTextComponent() + { + InitializeComponent(); + } + + public WordLongTextComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateWordText(WordLongTextInfo textInfo) + { + if (string.IsNullOrEmpty(textInfo.FileName) || string.IsNullOrEmpty(textInfo.Title) || !CheckData(textInfo.Paragraphs)) + { + throw new Exception("Не все данные заполнены"); + } + + _wordDocument = WordprocessingDocument.Create(textInfo.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + + AddText(textInfo); + + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + } + + private void AddText(WordLongTextInfo textInfo) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + + AddParagraph(textInfo.Title, fontSize: "48", isBold: true); + + foreach (var paragraph in textInfo.Paragraphs) + { + AddParagraph(paragraph, fontSize: "24", isBold: false); + } + } + + private void AddParagraph(string text, string fontSize, bool isBold) + { + if (_docBody == null) + { + return; + } + + ParagraphProperties paragraphProperties = new(); + paragraphProperties.AppendChild(new Justification { Val = JustificationValues.Both }); + + Paragraph paragraph = new(); + paragraph.AppendChild(paragraphProperties); + + Run docRun = new(); + + RunProperties runProperties = new(); + runProperties.AppendChild(new FontSize { Val = fontSize }); + if (isBold) + { + runProperties.AppendChild(new Bold()); + } + + docRun.AppendChild(runProperties); + docRun.AppendChild(new Text(text)); + + paragraph.AppendChild(docRun); + + _docBody.Append(paragraph); + } + + private bool CheckData(string[] data) + { + return data != null && data.Any() && data.All(d => !string.IsNullOrEmpty(d)); + } + } +} diff --git a/COP/RodionovLibrary/NonVisualComponents/WordTableComponent.Designer.cs b/COP/RodionovLibrary/NonVisualComponents/WordTableComponent.Designer.cs new file mode 100644 index 0000000..cebfb7c --- /dev/null +++ b/COP/RodionovLibrary/NonVisualComponents/WordTableComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace RodionovLibrary.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/COP/RodionovLibrary/NonVisualComponents/WordTableComponent.cs b/COP/RodionovLibrary/NonVisualComponents/WordTableComponent.cs new file mode 100644 index 0000000..14fca0e --- /dev/null +++ b/COP/RodionovLibrary/NonVisualComponents/WordTableComponent.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; + +namespace RodionovLibrary.NonVisualComponents +{ + public partial class WordTableComponent : Component + { + public WordTableComponent() + { + InitializeComponent(); + } + + public WordTableComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + } +} diff --git a/COP/RodionovLibrary/RodionovLibrary.csproj b/COP/RodionovLibrary/RodionovLibrary.csproj index 060aa1c..f44618b 100644 --- a/COP/RodionovLibrary/RodionovLibrary.csproj +++ b/COP/RodionovLibrary/RodionovLibrary.csproj @@ -7,4 +7,8 @@ enable + + + + diff --git a/COP/WinForms/FormTest.Designer.cs b/COP/WinForms/FormTest.Designer.cs index a7fea44..156e54c 100644 --- a/COP/WinForms/FormTest.Designer.cs +++ b/COP/WinForms/FormTest.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); comboBoxControl = new RodionovLibrary.VisualComponents.ComboBoxControl(); listBoxControl = new RodionovLibrary.VisualComponents.ListBoxControl(); textBoxControl = new RodionovLibrary.VisualComponents.TextBoxControl(); @@ -40,46 +41,50 @@ buttonGetObject = new Button(); buttonGetIndex = new Button(); buttonSetIndex = new Button(); + panel1 = new Panel(); + buttonWordDiagram = new Button(); + buttonWordTable = new Button(); + buttonWordText = new Button(); + wordLongTextComponent = new RodionovLibrary.NonVisualComponents.WordLongTextComponent(components); + panel1.SuspendLayout(); SuspendLayout(); // // comboBoxControl // comboBoxControl.AutoSize = true; comboBoxControl.AutoSizeMode = AutoSizeMode.GrowAndShrink; - comboBoxControl.Location = new Point(45, 27); - comboBoxControl.Margin = new Padding(3, 4, 3, 4); + comboBoxControl.Location = new Point(39, 125); comboBoxControl.Name = "comboBoxControl"; comboBoxControl.SelectedValue = ""; - comboBoxControl.Size = new Size(210, 32); + comboBoxControl.Size = new Size(185, 26); comboBoxControl.TabIndex = 0; // // listBoxControl // listBoxControl.AutoSize = true; listBoxControl.AutoSizeMode = AutoSizeMode.GrowAndShrink; - listBoxControl.Location = new Point(45, 276); - listBoxControl.Margin = new Padding(3, 4, 3, 4); + listBoxControl.Location = new Point(39, 312); listBoxControl.Name = "listBoxControl"; listBoxControl.SelectedIndex = -1; - listBoxControl.Size = new Size(647, 488); + listBoxControl.Size = new Size(567, 367); listBoxControl.TabIndex = 1; // // textBoxControl // textBoxControl.AutoSize = true; textBoxControl.AutoSizeMode = AutoSizeMode.GrowAndShrink; - textBoxControl.Location = new Point(446, 27); - textBoxControl.Margin = new Padding(3, 4, 3, 4); + textBoxControl.Location = new Point(390, 125); textBoxControl.Name = "textBoxControl"; textBoxControl.Pattern = null; - textBoxControl.Size = new Size(246, 31); + textBoxControl.Size = new Size(216, 26); textBoxControl.TabIndex = 2; // // buttonClear // - buttonClear.Location = new Point(47, 66); + buttonClear.Location = new Point(41, 155); + buttonClear.Margin = new Padding(3, 2, 3, 2); buttonClear.Name = "buttonClear"; - buttonClear.Size = new Size(94, 29); + buttonClear.Size = new Size(82, 22); buttonClear.TabIndex = 3; buttonClear.Text = "Отчистка"; buttonClear.UseVisualStyleBackColor = true; @@ -87,9 +92,10 @@ // // buttonGetComboBox // - buttonGetComboBox.Location = new Point(47, 114); + buttonGetComboBox.Location = new Point(41, 191); + buttonGetComboBox.Margin = new Padding(3, 2, 3, 2); buttonGetComboBox.Name = "buttonGetComboBox"; - buttonGetComboBox.Size = new Size(165, 29); + buttonGetComboBox.Size = new Size(144, 22); buttonGetComboBox.TabIndex = 4; buttonGetComboBox.Text = "Получение значения"; buttonGetComboBox.UseVisualStyleBackColor = true; @@ -97,9 +103,10 @@ // // buttonSetComboBox // - buttonSetComboBox.Location = new Point(47, 165); + buttonSetComboBox.Location = new Point(41, 229); + buttonSetComboBox.Margin = new Padding(3, 2, 3, 2); buttonSetComboBox.Name = "buttonSetComboBox"; - buttonSetComboBox.Size = new Size(165, 29); + buttonSetComboBox.Size = new Size(144, 22); buttonSetComboBox.TabIndex = 5; buttonSetComboBox.Text = "Установка значения"; buttonSetComboBox.UseVisualStyleBackColor = true; @@ -107,9 +114,10 @@ // // buttonGetTextBox // - buttonGetTextBox.Location = new Point(446, 66); + buttonGetTextBox.Location = new Point(390, 155); + buttonGetTextBox.Margin = new Padding(3, 2, 3, 2); buttonGetTextBox.Name = "buttonGetTextBox"; - buttonGetTextBox.Size = new Size(165, 29); + buttonGetTextBox.Size = new Size(144, 22); buttonGetTextBox.TabIndex = 6; buttonGetTextBox.Text = "Получение значения"; buttonGetTextBox.UseVisualStyleBackColor = true; @@ -117,9 +125,10 @@ // // buttonSetTextBox // - buttonSetTextBox.Location = new Point(446, 114); + buttonSetTextBox.Location = new Point(390, 191); + buttonSetTextBox.Margin = new Padding(3, 2, 3, 2); buttonSetTextBox.Name = "buttonSetTextBox"; - buttonSetTextBox.Size = new Size(165, 29); + buttonSetTextBox.Size = new Size(144, 22); buttonSetTextBox.TabIndex = 7; buttonSetTextBox.Text = "Установка значения"; buttonSetTextBox.UseVisualStyleBackColor = true; @@ -127,9 +136,10 @@ // // buttonSetWrongTextBox // - buttonSetWrongTextBox.Location = new Point(446, 165); + buttonSetWrongTextBox.Location = new Point(390, 229); + buttonSetWrongTextBox.Margin = new Padding(3, 2, 3, 2); buttonSetWrongTextBox.Name = "buttonSetWrongTextBox"; - buttonSetWrongTextBox.Size = new Size(246, 29); + buttonSetWrongTextBox.Size = new Size(215, 22); buttonSetWrongTextBox.TabIndex = 8; buttonSetWrongTextBox.Text = "Установка значения (неверное)"; buttonSetWrongTextBox.UseVisualStyleBackColor = true; @@ -137,9 +147,10 @@ // // buttonGetObject // - buttonGetObject.Location = new Point(699, 463); + buttonGetObject.Location = new Point(612, 452); + buttonGetObject.Margin = new Padding(3, 2, 3, 2); buttonGetObject.Name = "buttonGetObject"; - buttonGetObject.Size = new Size(165, 29); + buttonGetObject.Size = new Size(144, 22); buttonGetObject.TabIndex = 9; buttonGetObject.Text = "Получение объекта"; buttonGetObject.UseVisualStyleBackColor = true; @@ -147,9 +158,10 @@ // // buttonGetIndex // - buttonGetIndex.Location = new Point(699, 516); + buttonGetIndex.Location = new Point(612, 492); + buttonGetIndex.Margin = new Padding(3, 2, 3, 2); buttonGetIndex.Name = "buttonGetIndex"; - buttonGetIndex.Size = new Size(165, 29); + buttonGetIndex.Size = new Size(144, 22); buttonGetIndex.TabIndex = 10; buttonGetIndex.Text = "Получение индекса"; buttonGetIndex.UseVisualStyleBackColor = true; @@ -157,19 +169,66 @@ // // buttonSetIndex // - buttonSetIndex.Location = new Point(699, 569); + buttonSetIndex.Location = new Point(612, 532); + buttonSetIndex.Margin = new Padding(3, 2, 3, 2); buttonSetIndex.Name = "buttonSetIndex"; - buttonSetIndex.Size = new Size(165, 29); + buttonSetIndex.Size = new Size(144, 22); buttonSetIndex.TabIndex = 11; buttonSetIndex.Text = "Установка индекса"; buttonSetIndex.UseVisualStyleBackColor = true; buttonSetIndex.Click += ButtonSetIndex_Click; // + // panel1 + // + panel1.BackColor = Color.White; + panel1.BorderStyle = BorderStyle.FixedSingle; + panel1.Controls.Add(buttonWordDiagram); + panel1.Controls.Add(buttonWordTable); + panel1.Controls.Add(buttonWordText); + panel1.Location = new Point(41, 10); + panel1.Name = "panel1"; + panel1.Size = new Size(715, 100); + panel1.TabIndex = 12; + // + // buttonWordDiagram + // + buttonWordDiagram.Location = new Point(528, 29); + buttonWordDiagram.Margin = new Padding(3, 2, 3, 2); + buttonWordDiagram.Name = "buttonWordDiagram"; + buttonWordDiagram.Size = new Size(135, 34); + buttonWordDiagram.TabIndex = 15; + buttonWordDiagram.Text = "Word (диаграмма)"; + buttonWordDiagram.UseVisualStyleBackColor = true; + buttonWordDiagram.Click += ButtonWordDiagram_Click; + // + // buttonWordTable + // + buttonWordTable.Location = new Point(288, 29); + buttonWordTable.Margin = new Padding(3, 2, 3, 2); + buttonWordTable.Name = "buttonWordTable"; + buttonWordTable.Size = new Size(135, 34); + buttonWordTable.TabIndex = 14; + buttonWordTable.Text = "Word (таблица)"; + buttonWordTable.UseVisualStyleBackColor = true; + buttonWordTable.Click += ButtonWordTable_Click; + // + // buttonWordText + // + buttonWordText.Location = new Point(47, 29); + buttonWordText.Margin = new Padding(3, 2, 3, 2); + buttonWordText.Name = "buttonWordText"; + buttonWordText.Size = new Size(135, 34); + buttonWordText.TabIndex = 13; + buttonWordText.Text = "Word (текст)"; + buttonWordText.UseVisualStyleBackColor = true; + buttonWordText.Click += ButtonWordText_Click; + // // FormTest // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(878, 787); + ClientSize = new Size(779, 692); + Controls.Add(panel1); Controls.Add(buttonSetIndex); Controls.Add(buttonGetIndex); Controls.Add(buttonGetObject); @@ -182,8 +241,11 @@ Controls.Add(textBoxControl); Controls.Add(listBoxControl); Controls.Add(comboBoxControl); + Margin = new Padding(3, 2, 3, 2); Name = "FormTest"; + StartPosition = FormStartPosition.CenterScreen; Text = "FormTest"; + panel1.ResumeLayout(false); ResumeLayout(false); PerformLayout(); } @@ -202,5 +264,10 @@ private Button buttonGetObject; private Button buttonGetIndex; private Button buttonSetIndex; + private Panel panel1; + private Button buttonWordDiagram; + private Button buttonWordTable; + private Button buttonWordText; + private RodionovLibrary.NonVisualComponents.WordLongTextComponent wordLongTextComponent; } } diff --git a/COP/WinForms/FormTest.cs b/COP/WinForms/FormTest.cs index c5ff199..62b83ad 100644 --- a/COP/WinForms/FormTest.cs +++ b/COP/WinForms/FormTest.cs @@ -1,3 +1,6 @@ +using RodionovLibrary.NonVisualComponents.HelperModels; +using System.Windows.Forms; + namespace WinForms { public partial class FormTest : Form @@ -64,5 +67,37 @@ namespace WinForms { listBoxControl.SelectedIndex = 0; } + + private void ButtonWordText_Click(object sender, EventArgs e) + { + try + { + wordLongTextComponent.CreateWordText(new WordLongTextInfo() + { + FileName = AppDomain.CurrentDomain.BaseDirectory + "test.docx", + Title = " 1. ", + Paragraphs = new string[] { "- . - , , , . , , .", + " , , , , . , , , : , , , , .", + " , , . - . : , , , ( ), ( ), , , , .", + " , , ."} + }); + MessageBox.Show("!"); + } + catch (Exception ex) + { + MessageBox.Show(" : " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + private void ButtonWordTable_Click(object sender, EventArgs e) + { + + } + + private void ButtonWordDiagram_Click(object sender, EventArgs e) + { + + } } } diff --git a/COP/WinForms/FormTest.resx b/COP/WinForms/FormTest.resx index 8b2ff64..3da41b6 100644 --- a/COP/WinForms/FormTest.resx +++ b/COP/WinForms/FormTest.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file