COP_labs/Test App/FormWord.cs

136 lines
5.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DocumentFormat.OpenXml.Drawing.Charts;
using Labs;
using Labs.HelperClasses.WordBigText;
using Labs.HelperClasses.WordLineChart;
using Labs.HelperClasses.WordTable;
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.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace Test_App
{
public partial class FormWord : Form
{
private string[] bigText = { "Проведите местных радиоведущих По и Манро через шесть похожих на короткометражки эпизодов сверъестественной странности и обжигающего сюжета", "Вы окажетесь в эпицентре лондонского ограбления и выберете своё приключение в интерактивном кинофильме с меняющейся историей, ведущей к одной из семи концовок.", "Вы решаете судьбу Ника, актера-неудачника, который борется за судьбоносный денежный приз" };
#region ДАННЫЕ ДЛЯ ТАБЛИЦЫ
//Объединённые ячейки
List<CellMergeInfo> mergedCells = new List<CellMergeInfo>
{
new CellMergeInfo(1, 3),
new CellMergeInfo(5, 6)
};
//Сами данные
List<TestClass2> tableData = new List<TestClass2>
{
new TestClass2(1, "Ян", "Чернышев", 49, true, "Департамент 1", "Руководитель"),
new TestClass2(2, "Евгений", "Замятин", 71, false, "Департамент 2", "Писатель"),
new TestClass2(3, "Клеменс", "Кёринг", 37, false, "Департамент 3", "Актёр озвучки")
};
//Настройки столбцов
List<ColumnProperties> colProps = new List<ColumnProperties>{
new ColumnProperties("Id", 10, "Id"),
new ColumnProperties("FirstName", 25, "Личные данные", "Имя"),
new ColumnProperties("LastName", 35, "Личные данные", "Фамилия"),
new ColumnProperties("Age", 10, "Личные данные", "Возраст"),
new ColumnProperties("HasCar", 10, "Машина"),
new ColumnProperties("Department", 20, "Работа", "Подразделение"),
new ColumnProperties("Post", 20, "Работа", "Должность")
};
#endregion
#region ДАННЫЕ ДЛЯ ДИАГРАММЫ
//2, 16, 30 сентября
double[] data1 = { 132, 550, 550 }; //Late Shift
double[] data2 = { 295, 295, 590 }; //Ten Dates
double[] data3 = { 74, 287, 287 }; //She Sees Red
#endregion
public FormWord()
{
InitializeComponent();
}
private void buttonBigText_Click(object sender, EventArgs e)
{
var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
WordBigTextConfig config = new(dialog.FileName, "Описание игр из steam", bigText);
wordBigText.CreateWord(config);
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)
{
var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
WordTableConfig<TestClass2> config = new(dialog.FileName, "Таблица ворд", colProps, mergedCells, tableData);
wordTable.CreateWordTable(config);
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonLineChart_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
WordLineChartConfig chart = new WordLineChartConfig(dialog.FileName, "Цена FMV игр в Steam", "Данные за сентябрь", LegendLocation.Bottom, new List<LineChartSeria> {
new LineChartSeria("Late Shift", data1),
new LineChartSeria("Ten Dates", data2),
new LineChartSeria("She Sees Red", data3)
},
new string[] { "2.09.24", "16.09.24", "30.09.24" });
wordLineChart.CreateLineChart(chart);
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}