че то закину 2
This commit is contained in:
parent
f17a388a73
commit
bd06976aea
36
COP_1/cop_2/WordBigText.Designer.cs
generated
Normal file
36
COP_1/cop_2/WordBigText.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace COP_1.cop_2
|
||||
{
|
||||
partial class WordBigText
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
127
COP_1/cop_2/WordBigText.cs
Normal file
127
COP_1/cop_2/WordBigText.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using DocumentFormat.OpenXml;
|
||||
using System.ComponentModel;
|
||||
using COP_1.cop_2.helpers;
|
||||
|
||||
namespace COP_1.cop_2
|
||||
{
|
||||
public partial class WordBigText : Component
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
private Body? _docBody;
|
||||
|
||||
public WordBigText()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public WordBigText(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateWordText(WordBigTextInfo largeText)
|
||||
{
|
||||
if (string.IsNullOrEmpty(largeText.FilePath) || string.IsNullOrEmpty(largeText.Title) || !CheckData(largeText.Paragraphs))
|
||||
{
|
||||
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.Dispose();
|
||||
|
||||
AddText(largeText);
|
||||
}
|
||||
|
||||
private void AddText(WordBigTextInfo largeText)
|
||||
{
|
||||
using (var document = WordprocessingDocument.Open(largeText.FilePath, true))
|
||||
{
|
||||
var doc = document.MainDocumentPart.Document;
|
||||
//Создание заголовка
|
||||
|
||||
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.Title));
|
||||
|
||||
header.AppendChild(docRun);
|
||||
doc.Body.Append(header);
|
||||
|
||||
//Создание текста
|
||||
|
||||
for (int i = 0; i < largeText.Paragraphs.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.Paragraphs[i]));
|
||||
|
||||
text.AppendChild(docRun2);
|
||||
doc.Body.Append(text);
|
||||
}
|
||||
doc.Save();
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckData(string[] data)
|
||||
{
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(data[i])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
36
COP_1/cop_2/WordDiagram.Designer.cs
generated
Normal file
36
COP_1/cop_2/WordDiagram.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace COP_1.cop_2
|
||||
{
|
||||
partial class WordDiagram
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
107
COP_1/cop_2/WordDiagram.cs
Normal file
107
COP_1/cop_2/WordDiagram.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using Aspose.Words;
|
||||
using Aspose.Words.Drawing;
|
||||
using Aspose.Words.Drawing.Charts;
|
||||
using COP_1.cop_2.helpers;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace COP_1.cop_2
|
||||
{
|
||||
public partial class WordDiagram : Component
|
||||
{
|
||||
public WordDiagram()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public WordDiagram(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
string[] cats;
|
||||
string[] doubs;
|
||||
|
||||
public void AddDiagram(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 = "Correction Tape";
|
||||
|
||||
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();
|
||||
string[] cats;
|
||||
double[] doubs;
|
||||
|
||||
foreach (var data in simpleLineChart.DataList)
|
||||
{
|
||||
cats = new string[simpleLineChart.DataList.Count];
|
||||
doubs = new double[simpleLineChart.DataList.Count];
|
||||
int i = 0;
|
||||
foreach(var (name, value) in data.LineData)
|
||||
{
|
||||
cats[i] = name;
|
||||
doubs[i] = value;
|
||||
i++;
|
||||
}
|
||||
|
||||
//var (name, values) = data.LineData;
|
||||
seriesColl.Add(data.LineName, cats, doubs);
|
||||
}
|
||||
|
||||
ChartLegend legend = chart.Legend;
|
||||
|
||||
legend.Position = (LegendPosition)simpleLineChart.AreaLegend;
|
||||
|
||||
legend.Overlay = true;
|
||||
|
||||
doc.Save(simpleLineChart.FilePath);
|
||||
}
|
||||
static bool CheckData(List<DataLineChart> data)
|
||||
{
|
||||
string[] cats = new string[data.Count];
|
||||
double[] doubs = new double[data.Count];
|
||||
|
||||
foreach (var _data in data)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var (name, value) in _data.LineData)
|
||||
{
|
||||
cats[i] = name;
|
||||
doubs[i] = value;
|
||||
i++;
|
||||
}
|
||||
if (string.IsNullOrEmpty(_data.LineName) || cats.Length == 0 || doubs.Length == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
36
COP_1/cop_2/WordTable.Designer.cs
generated
Normal file
36
COP_1/cop_2/WordTable.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace COP_1.cop_2
|
||||
{
|
||||
partial class WordTable
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
115
COP_1/cop_2/WordTable.cs
Normal file
115
COP_1/cop_2/WordTable.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Aspose.Words;
|
||||
using Aspose.Words.Tables;
|
||||
using COP_1.cop_2.helpers;
|
||||
|
||||
namespace COP_1.cop_2
|
||||
{
|
||||
public partial class WordTable : Component
|
||||
{
|
||||
public WordTable()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public WordTable(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateTable<T>(WordTableInfo<T> tableWord) where T : class
|
||||
{
|
||||
// Проверка наличия данных и определений столбцов
|
||||
if (tableWord.Items == null || tableWord.Items.Count == 0 || tableWord.ColumnParameters == null || tableWord.ColumnParameters.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("Data or column definitions are null or empty");
|
||||
}
|
||||
|
||||
// Проверка, что все ячейки шапки заполнены и для каждого столбца определено свойство/поле класса
|
||||
foreach (var columnDefinition in tableWord.ColumnParameters)
|
||||
{
|
||||
if (string.IsNullOrEmpty(columnDefinition.PropertyName))
|
||||
{
|
||||
throw new ArgumentException($"Incomplete column definition: {columnDefinition.FirstRowHeader}");
|
||||
}
|
||||
}
|
||||
|
||||
// Создание документа
|
||||
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(tableWord.Title);
|
||||
|
||||
// Создание таблицы
|
||||
Table table = builder.StartTable();
|
||||
|
||||
// Создание первой строки (заголовок)
|
||||
foreach (var columnDefinition in tableWord.ColumnParameters)
|
||||
{
|
||||
builder.InsertCell();
|
||||
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition.Width);
|
||||
builder.Write(columnDefinition.FirstRowHeader);
|
||||
}
|
||||
// Создание второй строки (вторые заголовки)
|
||||
builder.EndRow(); // Завершение первой строки заголовка
|
||||
foreach (var columnDefinition in tableWord.ColumnParameters)
|
||||
{
|
||||
builder.InsertCell();
|
||||
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition.Width);
|
||||
builder.Write(columnDefinition.SecondRowHeader);
|
||||
}
|
||||
builder.EndRow();
|
||||
|
||||
int startCellIndex = -1;
|
||||
int endCellIndex = -1;
|
||||
// Объединение ячеек в первой строке шапки таблицы (если необходимо)
|
||||
foreach (var mergedColumn in tableWord.MergedColumns)
|
||||
{
|
||||
startCellIndex = mergedColumn[0];
|
||||
endCellIndex = mergedColumn[^1];
|
||||
|
||||
for (int i = startCellIndex; i <= endCellIndex; i++)
|
||||
{
|
||||
table.Rows[0].Cells[i].CellFormat.HorizontalMerge = i == startCellIndex ? CellMerge.First : CellMerge.Previous;
|
||||
}
|
||||
}
|
||||
|
||||
// Установка вертикального объединения заголовков
|
||||
for (int columnIndex = 0; columnIndex < tableWord.ColumnParameters.Count; columnIndex++)
|
||||
{
|
||||
if (startCellIndex == columnIndex || endCellIndex == columnIndex)
|
||||
continue;
|
||||
table.Rows[0].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.First;
|
||||
table.Rows[1].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.Previous;
|
||||
}
|
||||
|
||||
// Вставка данных в таблицу
|
||||
foreach (var item in tableWord.Items)
|
||||
{
|
||||
foreach (var columnDefinition in tableWord.ColumnParameters)
|
||||
{
|
||||
builder.InsertCell();
|
||||
// Получение значения свойства/поля объекта по заданному имени
|
||||
var propertyValue = item.GetType().GetProperty(columnDefinition.PropertyName)?.GetValue(item)?.ToString();
|
||||
builder.Write(propertyValue ?? string.Empty);
|
||||
}
|
||||
builder.EndRow();
|
||||
}
|
||||
|
||||
builder.EndTable();
|
||||
|
||||
// Сохранение документа в файл
|
||||
document.Save(tableWord.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
11
COP_1/cop_2/helpers/ColumnParams.cs
Normal file
11
COP_1/cop_2/helpers/ColumnParams.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace COP_1.cop_2.helpers
|
||||
{
|
||||
public class ColumnParams
|
||||
{
|
||||
public string FirstRowHeader { get; set; } = string.Empty;
|
||||
public string SecondRowHeader { get; set; } = string.Empty;
|
||||
public string PropertyName { get; set; } = string.Empty;
|
||||
public double Width { get; set; }
|
||||
}
|
||||
}
|
||||
|
15
COP_1/cop_2/helpers/DataLineChart.cs
Normal file
15
COP_1/cop_2/helpers/DataLineChart.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace COP_1.cop_2.helpers
|
||||
{
|
||||
public class DataLineChart
|
||||
{
|
||||
public string LineName { get; set; } = string.Empty;
|
||||
|
||||
public (string, double)[] LineData { get; set; }
|
||||
|
||||
public DataLineChart(string nameSeries, (string, double)[] lineData)
|
||||
{
|
||||
LineName = nameSeries;
|
||||
LineData = lineData;
|
||||
}
|
||||
}
|
||||
}
|
26
COP_1/cop_2/helpers/SimpleLineChart.cs
Normal file
26
COP_1/cop_2/helpers/SimpleLineChart.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using COP_1.cop_2.helpers.enums;
|
||||
|
||||
namespace COP_1.cop_2.helpers
|
||||
{
|
||||
public class SimpleLineChart
|
||||
{
|
||||
public string FilePath = string.Empty;
|
||||
|
||||
public string FileHeader = string.Empty;
|
||||
|
||||
public string LineChartName = string.Empty;
|
||||
|
||||
public EnumAreaLegend AreaLegend;
|
||||
|
||||
public List<DataLineChart> DataList = new();
|
||||
|
||||
public SimpleLineChart(string filePath, string fileHeader, string lineChartName, EnumAreaLegend areaLegend, List<DataLineChart> dataList)
|
||||
{
|
||||
FilePath = filePath;
|
||||
FileHeader = fileHeader;
|
||||
LineChartName = lineChartName;
|
||||
AreaLegend = areaLegend;
|
||||
DataList = dataList;
|
||||
}
|
||||
}
|
||||
}
|
16
COP_1/cop_2/helpers/WordBigTextInfo.cs
Normal file
16
COP_1/cop_2/helpers/WordBigTextInfo.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace COP_1.cop_2.helpers
|
||||
{
|
||||
public class WordBigTextInfo
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string[] Paragraphs { get; set; } = Array.Empty<string>();
|
||||
|
||||
public WordBigTextInfo(string filePath, string title, string[] paragraphs)
|
||||
{
|
||||
FilePath = filePath;
|
||||
Title = title;
|
||||
Paragraphs = paragraphs;
|
||||
}
|
||||
}
|
||||
}
|
24
COP_1/cop_2/helpers/WordTableInfo.cs
Normal file
24
COP_1/cop_2/helpers/WordTableInfo.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace COP_1.cop_2.helpers
|
||||
{
|
||||
public class WordTableInfo<T>
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public List<ColumnParams> ColumnParameters { get; set; } = new();
|
||||
|
||||
public List<T> Items { get; set; } = new();
|
||||
|
||||
public List<int[]> MergedColumns { get; set; } = new();
|
||||
|
||||
public WordTableInfo(string filePath, string title, List<ColumnParams> columnParameters, List<T> data, List<int[]> mergedColumns)
|
||||
{
|
||||
FilePath = filePath;
|
||||
Title = title;
|
||||
ColumnParameters = columnParameters;
|
||||
Items = data;
|
||||
MergedColumns = mergedColumns;
|
||||
}
|
||||
}
|
||||
}
|
17
COP_1/cop_2/helpers/enums/EnumAreaLegend.cs
Normal file
17
COP_1/cop_2/helpers/enums/EnumAreaLegend.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace COP_1.cop_2.helpers.enums
|
||||
{
|
||||
public enum EnumAreaLegend
|
||||
{
|
||||
None,
|
||||
|
||||
Left,
|
||||
|
||||
Top,
|
||||
|
||||
Right,
|
||||
|
||||
Bottom,
|
||||
|
||||
TopRight
|
||||
}
|
||||
}
|
141
COP_1Test/Form2.Designer.cs
generated
Normal file
141
COP_1Test/Form2.Designer.cs
generated
Normal file
@ -0,0 +1,141 @@
|
||||
namespace COP_1Test
|
||||
{
|
||||
partial class Form2
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
groupBox2 = new GroupBox();
|
||||
button2 = new Button();
|
||||
groupBox3 = new GroupBox();
|
||||
button3 = new Button();
|
||||
groupBox1 = new GroupBox();
|
||||
button1 = new Button();
|
||||
wordText = new COP_1.cop_2.WordBigText(components);
|
||||
wordDiagram = new COP_1.cop_2.WordDiagram(components);
|
||||
wordTable = new COP_1.cop_2.WordTable(components);
|
||||
groupBox2.SuspendLayout();
|
||||
groupBox3.SuspendLayout();
|
||||
groupBox1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(button2);
|
||||
groupBox2.Dock = DockStyle.Top;
|
||||
groupBox2.Location = new Point(0, 154);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(294, 80);
|
||||
groupBox2.TabIndex = 4;
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "Таблица";
|
||||
//
|
||||
// button2
|
||||
//
|
||||
button2.Dock = DockStyle.Fill;
|
||||
button2.Location = new Point(3, 23);
|
||||
button2.Name = "button2";
|
||||
button2.Size = new Size(288, 54);
|
||||
button2.TabIndex = 0;
|
||||
button2.Text = "Создать";
|
||||
button2.UseVisualStyleBackColor = true;
|
||||
button2.Click += buttonTable_Click;
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
groupBox3.Controls.Add(button3);
|
||||
groupBox3.Dock = DockStyle.Top;
|
||||
groupBox3.Location = new Point(0, 80);
|
||||
groupBox3.Name = "groupBox3";
|
||||
groupBox3.Size = new Size(294, 74);
|
||||
groupBox3.TabIndex = 3;
|
||||
groupBox3.TabStop = false;
|
||||
groupBox3.Text = "Линейная диаграмма";
|
||||
//
|
||||
// button3
|
||||
//
|
||||
button3.Dock = DockStyle.Fill;
|
||||
button3.Location = new Point(3, 23);
|
||||
button3.Name = "button3";
|
||||
button3.Size = new Size(288, 48);
|
||||
button3.TabIndex = 0;
|
||||
button3.Text = "Создать";
|
||||
button3.UseVisualStyleBackColor = true;
|
||||
button3.Click += buttonDiagram_Click;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(button1);
|
||||
groupBox1.Dock = DockStyle.Top;
|
||||
groupBox1.Location = new Point(0, 0);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(294, 80);
|
||||
groupBox1.TabIndex = 2;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Большой текст";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Dock = DockStyle.Fill;
|
||||
button1.Location = new Point(3, 23);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(288, 54);
|
||||
button1.TabIndex = 0;
|
||||
button1.Text = "Создать";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += buttonBigText_Click;
|
||||
//
|
||||
// Form2
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(294, 239);
|
||||
Controls.Add(groupBox2);
|
||||
Controls.Add(groupBox3);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "Form2";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "COP_2";
|
||||
groupBox2.ResumeLayout(false);
|
||||
groupBox3.ResumeLayout(false);
|
||||
groupBox1.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox2;
|
||||
private Button button2;
|
||||
private GroupBox groupBox3;
|
||||
private Button button3;
|
||||
private GroupBox groupBox1;
|
||||
private Button button1;
|
||||
private COP_1.cop_2.WordBigText wordText;
|
||||
private COP_1.cop_2.WordDiagram wordDiagram;
|
||||
private COP_1.cop_2.WordTable wordTable;
|
||||
}
|
||||
}
|
133
COP_1Test/Form2.cs
Normal file
133
COP_1Test/Form2.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using COP_1.cop_2.helpers.enums;
|
||||
using COP_1.cop_2.helpers;
|
||||
using COP_1.cop_2;
|
||||
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;
|
||||
using COP_1;
|
||||
|
||||
namespace COP_1Test
|
||||
{
|
||||
public partial class Form2 : Form
|
||||
{
|
||||
string[] testArray = { "«Да, здесь, в этом лесу был этот дуб, с которым мы были согласны», подумал князь Андрей. " +
|
||||
"«Да где он», подумал опять князь Андрей, глядя на левую сторону дороги и сам того не зная, не узнавая его, любовался тем дубом, которого он искал. " +
|
||||
"Старый дуб, весь преображенный, раскинувшись шатром сочной, темной зелени, млел, чуть колыхаясь в лучах вечернего солнца. Ни корявых пальцев, ни болячек, " +
|
||||
"ни старого недоверия и горя, – ничего не было видно. Сквозь жесткую, столетнюю кору пробились без сучков сочные, молодые листья, так что верить нельзя было, что " +
|
||||
"этот старик произвел их. «Да, это тот самый дуб», подумал князь Андрей, и на него вдруг нашло беспричинное, весеннее чувство радости и обновления. " +
|
||||
"Все лучшие минуты его жизни вдруг в одно и то же время вспомнились ему. И Аустерлиц с высоким небом, и мертвое, укоризненное лицо жены, и Пьер на пароме, " +
|
||||
"и девочка, взволнованная красотою ночи, и эта ночь, и луна, – и все это вдруг вспомнилось ему." + Environment.NewLine,
|
||||
"«Нет, жизнь не кончена в 31 год, вдруг окончательно, беспеременно " +
|
||||
"решил князь Андрей. Мало того, что я знаю все то, что есть во мне, надо, чтобы и все знали это: и Пьер, и эта девочка, которая хотела улететь в небо, надо, чтобы " +
|
||||
"все знали меня, чтобы не для одного меня шла моя жизнь, чтоб не жили они так независимо от моей жизни, чтоб на всех она отражалась и чтобы все они жили со мною вместе!»"};
|
||||
public Form2()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void buttonBigText_Click(object sender, EventArgs e)
|
||||
{
|
||||
//фильтрация файлов для диалогового окна
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
WordBigTextInfo largeText = new(dialog.FileName, "Встреча Болконского с дубом pt.2", testArray);
|
||||
wordText.CreateWordText(largeText);
|
||||
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<int[]> mergedColumns = new()
|
||||
{
|
||||
new int[] { 2, 3 }
|
||||
};
|
||||
|
||||
var columns = new List<ColumnParams>
|
||||
{
|
||||
new() { FirstRowHeader = "Название", SecondRowHeader = "", PropertyName = "Title", Width = 1.3 },
|
||||
new() { FirstRowHeader = "Исполнитель", SecondRowHeader = "",PropertyName = "Performer", Width = 1.3 },
|
||||
new() { FirstRowHeader = "Общая информация", SecondRowHeader = "Жанр", PropertyName = "Genre", Width = 1.3 },
|
||||
new() { FirstRowHeader = "Общая информация", SecondRowHeader = "Год", PropertyName = "Year", Width = 1.3 },
|
||||
};
|
||||
|
||||
var albums = new List<Album>
|
||||
{
|
||||
new() {Title = "Battle For The Sun", Performer = "Placebo", Genre = "Alternative", Year = "2009"},
|
||||
new() {Title = "The Bastards", Performer = "Palaye Royale", Genre = "Glam Rock", Year = "2020"},
|
||||
new() {Title = "All Hope Is Gone", Performer = "Slipknot", Genre = "Nu-Metal", Year = "2008"},
|
||||
new() {Title = "Three Imaginary Boys", Performer = "The Cure", Genre = "Gothic Rock", Year = "1979"},
|
||||
new() {Title = "Black Holes and Revelations", Performer = "Muse", Genre = "Alternative", Year = "2006" }
|
||||
};
|
||||
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
WordTableInfo<Album> info = new(dialog.FileName, "Задание 2", columns, albums, mergedColumns);
|
||||
wordTable.CreateTable(info);
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDiagram_Click(object sender, EventArgs e)
|
||||
{
|
||||
//фильтрация файлов для диалогового окна
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] cathegories = { "Январь", "Февраль", "Март", "April", "May" };
|
||||
(string, double)[] alb1 = { ("January", 600), ("February", 500), ("March", 300) };
|
||||
(string, double)[] alb2 = { ("January", 300), ("February", 500), ("March", 700) };
|
||||
(string, double)[] alb3 = { ("January", 200), ("February", 300), ("March", 100) };
|
||||
|
||||
SimpleLineChart diagram = new(dialog.FileName, "Третье задание", "График популярности альбомов", EnumAreaLegend.Right, new List<DataLineChart> {
|
||||
new DataLineChart("Meds", alb1), new DataLineChart("Iowa", alb2), new DataLineChart("Regional At Best", alb3),
|
||||
});
|
||||
|
||||
wordDiagram.AddDiagram(diagram);
|
||||
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
129
COP_1Test/Form2.resx
Normal file
129
COP_1Test/Form2.resx
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="wordText.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="wordDiagram.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>132, 17</value>
|
||||
</metadata>
|
||||
<metadata name="wordTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>280, 17</value>
|
||||
</metadata>
|
||||
</root>
|
17
COP_1Test/Program.cs
Normal file
17
COP_1Test/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace COP_1Test
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form2());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user