PIbd-31_MasenkinMS_COP_22/Components/WinForms/FormNonVisualComponents.cs
2024-09-06 04:27:34 +04:00

125 lines
4.9 KiB
C#
Raw 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 Components.NonVisualComponents;
using Components.NonVisualComponents.HelperModels;
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 WinForms
{
/// <summary>
/// Форма для не визуальных компонентов
/// </summary>
public partial class FormNonVisualComponents : Form
{
/// <summary>
/// Конструктор
/// </summary>
public FormNonVisualComponents()
{
InitializeComponent();
}
/// <summary>
/// Создать документ с текстом
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateTextDocument_Click(object sender, EventArgs e)
{
string filepath = "C:\\Users\\masen\\OneDrive\\Рабочий стол\\BigTextDocumentExcel.xls";
string title = "Документ с большим текстом";
string[] rows =
{
"Съешь еще",
"этих мягких",
"французских булок",
"да выпей чаю"
};
bigTextComponent1.CreateDocument(filepath, title, rows);
}
/// <summary>
/// Создать документ с таблицей
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateTableDocument_Click(object sender, EventArgs e)
{
string filepath = "C:\\Users\\masen\\OneDrive\\Рабочий стол\\TableDocumentExcel.xls";
string title = "Документ с таблицей";
List<MergeCells> mergeCells = new List<MergeCells>()
{
new MergeCells("Личные данные", new int[] { 2, 3, 4 }),
new MergeCells("Работа", new int[] { 7, 8 })
};
List<int> columnsWidth = new List<int>()
{
20, 20, 30, 30, 30, 30, 30, 50, 50, 30
};
List<string> columns = new List<string>()
{
"Id", "Status", "Name", "Surname", "Age", "Kids", "Car", "Department", "Post", "Prize"
};
List<string> headers = new List<string>()
{
"Идент.", "Статус", "Имя", "Фамилия", "Возраст", "Дети", "Машина", "Подразделение", "Должность", "Премия"
};
List<Employee> data = new List<Employee>()
{
new Employee(1, "нет", "Иван", "Иванов", 34, "нет", "есть", "Департамент 1", "Инженер", 2000.1),
new Employee(2, "нет", "Петр", "Петров", 44, "есть", "есть", "Департамент 1", "Инженер", 2000.1),
new Employee(3, "да", "Сергей", "Сепгеев", 55, "нет", "есть", "Департамент 1", "Руководитель", 5000.5),
new Employee(4, "нет", "Ольга", "Иванва", 34, "есть", "нет", "Бухгалтерия", "Бухгалтер", 2000.1),
new Employee(5, "да", "Татьяна", "Петрова", 44, "нет", "нет", "Бухгалтерия", "Старший бухгалтер", 7000.6)
};
tableComponent1.CreateDocument(filepath, title,
mergeCells, columnsWidth,
columns, headers,
data);
}
/// <summary>
/// Создать документ с диаграммой
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateDiagramDocument_Click(object sender, EventArgs e)
{
LineChartConfig config = new LineChartConfig();
config.Filepath = "C:\\Users\\masen\\OneDrive\\Рабочий стол\\DiagramDocumentExcel.xls";
config.Header = "Документ с диаграммой";
config.ChartTitle = "Моя диаграмма";
string[] charts = { "График 1", "График 2" };
var data = new Dictionary<string, List<int>>();
for (int i = 0; i < 2; i++)
{
var row = new List<int>();
for (var j = 0; j < 5; j++)
{
row.Add(5 * i + j + 1);
}
data.Add(charts[i], row);
}
config.Values = data;
config.LegendPosition = LegendPosition.Bottom;
diagramComponent1.CreateDocument(config);
}
}
}