2024-09-21 17:41:05 +04:00
|
|
|
|
using FormLibrary;
|
|
|
|
|
using FormLibrary.Exceptions;
|
|
|
|
|
using FormLibrary.HelperClasses;
|
|
|
|
|
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 System.Windows.Forms.VisualStyles;
|
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
|
2024-10-04 10:33:17 +04:00
|
|
|
|
using OxyPlot.Legends;
|
2024-09-21 17:41:05 +04:00
|
|
|
|
|
|
|
|
|
namespace Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class MainForm : Form
|
|
|
|
|
{
|
|
|
|
|
private int? savedValue;
|
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
customListBox1.SelectedItemChanged += CustomListBox1_SelectedItemChanged;
|
|
|
|
|
integerInputControl1.ValueChanged += IntegerInputControl1_ValueChanged;
|
|
|
|
|
integerInputControl1.CheckBoxChanged += IntegerInputControl_CheckBoxChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CustomListBox1_SelectedItemChanged(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (sender is CustomListBox customListBox)
|
|
|
|
|
{
|
|
|
|
|
string selectedItem = customListBox.SelectedItem;
|
|
|
|
|
MessageBox.Show($"Выбранный элемент: {selectedItem}", "Выбор элемента", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonLoad_Click(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
List<string> items = new List<string>();
|
|
|
|
|
for (int i = 0; i <= 5; i++)
|
|
|
|
|
{
|
|
|
|
|
items.Add("Item " + i.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customListBox1.PopulateListBox(items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonClear_Click(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
customListBox1.ClearListBox();
|
|
|
|
|
}
|
|
|
|
|
private void buttonInput_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
savedValue = integerInputControl1.Value;
|
|
|
|
|
MessageBox.Show("Значение успешно сохранено.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (EmptyValueException ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidValueTypeException ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonOutput_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (savedValue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"Сохраненное значение: {savedValue}", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Сохраненное значение: null", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void IntegerInputControl1_ValueChanged(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
textBox1.Text = "Textbox changed";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IntegerInputControl_CheckBoxChanged(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
textBox1.Text = "Checkbox changed";
|
|
|
|
|
}
|
|
|
|
|
private void ButtonFillTable_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var columns = new List<(string HeaderText, string DataPropertyName, float FillWeight)>
|
|
|
|
|
{
|
|
|
|
|
("Группа", "Group", 30),
|
|
|
|
|
("ФИО", "FullName", 50),
|
|
|
|
|
("Курс", "Course", 20)
|
|
|
|
|
};
|
|
|
|
|
valueTableControl1.ConfigureColumns(columns);
|
|
|
|
|
|
|
|
|
|
var students = new List<Student>
|
|
|
|
|
{
|
2024-10-04 10:33:17 +04:00
|
|
|
|
new Student { Group = "Пибд-31", FullName = "Алексеев Иван Сергеевич", Course = 3 },
|
|
|
|
|
new Student { Group = "Пибд-31", FullName = "Анисин Руслан Сергеевич", Course = 3 },
|
|
|
|
|
new Student { Group = "Пибд-31", FullName = "Афанасьев Степан Сергеевич", Course = 3 }
|
2024-09-21 17:41:05 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
valueTableControl1.FillData(students);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonClearTable_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
valueTableControl1.ClearRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonShowData_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var selectedStudent = valueTableControl1.GetSelectedObject<Student>();
|
|
|
|
|
MessageBox.Show($"Группа: {selectedStudent.Group}, ФИО: {selectedStudent.FullName}, Курс: {selectedStudent.Course}",
|
|
|
|
|
"Выбранный студент",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-04 10:33:17 +04:00
|
|
|
|
private void GeneratePdfButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var pdfData = new PdfDocumentData(
|
|
|
|
|
"C:\\Users\\Admin\\Downloads\\Отчёт.pdf",
|
|
|
|
|
"Название документа",
|
|
|
|
|
new List<string[,]>
|
|
|
|
|
{
|
|
|
|
|
new string[,]
|
|
|
|
|
{
|
|
|
|
|
{ "Ячейка 1", "Ячейка 2", "Ячейка 3" },
|
|
|
|
|
{ "Ячейка 4", "Ячейка 5", "Ячейка 6" }
|
|
|
|
|
},
|
|
|
|
|
new string[,]
|
|
|
|
|
{
|
|
|
|
|
{ "Ячейка 1", "Ячейка 2" },
|
|
|
|
|
{ "Ячейка 1", "Ячейка 2" }
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var documentGenerator = new PDFTable();
|
|
|
|
|
documentGenerator.GeneratePdf(pdfData);
|
|
|
|
|
|
|
|
|
|
MessageBox.Show("PDF-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"Произошла ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void btnGeneratePDF_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var settings = new PDFTableSettings<Student>
|
|
|
|
|
{
|
|
|
|
|
FilePath = "C:\\Users\\Admin\\Downloads\\Отчет2.pdf",
|
|
|
|
|
DocumentTitle = "Отчет по студентам",
|
|
|
|
|
HeaderRowHeight = 1.0f,
|
|
|
|
|
DataRowHeight = 1.0f,
|
|
|
|
|
DataList = new List<Student>
|
|
|
|
|
{
|
|
|
|
|
new Student { Number = 1, Group = "Пибд-31", FullName = "Алексеев Иван", Course = 3 },
|
|
|
|
|
new Student { Number = 2, Group = "Пибд-31", FullName = "Анисин Руслан", Course = 3 },
|
|
|
|
|
new Student { Number = 3, Group = "Пибд-31", FullName = "Афанасьев Степан", Course = 3 }
|
|
|
|
|
},
|
|
|
|
|
Columns = new List<(string, float, string, int)>
|
|
|
|
|
{
|
|
|
|
|
("№", 1.0f, nameof(Student.Number), 0),
|
|
|
|
|
("Группа", 4.0f, nameof(Student.Group), 1),
|
|
|
|
|
("ФИО", 6.0f, nameof(Student.FullName), 2),
|
|
|
|
|
("Курс", 2.0f, nameof(Student.Course), 3)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
pdfTableCustom1.GeneratePDFWithHead(settings);
|
|
|
|
|
MessageBox.Show("PDF-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"Ошибка: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void btnGenerateHistogrammPdf_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var histogramGenerator = new ComponentHistogramToPdf();
|
|
|
|
|
|
|
|
|
|
var chartData = new List<ChartData>
|
|
|
|
|
{
|
|
|
|
|
new ChartData { SeriesName = "Серияd 1", Data = new Dictionary<string, double> { { "Категорияz 1", 2 }, { "Категорияx 2", 10 } } },
|
|
|
|
|
new ChartData { SeriesName = "Серияs 2", Data = new Dictionary<string, double> { { "Категорияa 1", 3 }, { "Категорияs 2", 5 } } },
|
|
|
|
|
new ChartData { SeriesName = "Серияs 3", Data = new Dictionary<string, double> { { "Категорияa 1", 3 }, { "Категорияs 2", 8 } } }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string filePath = "C:\\Users\\Admin\\Downloads\\Гистограмма.pdf";
|
|
|
|
|
|
|
|
|
|
histogramGenerator.CreateHistogramPdf(filePath, "Название документа", "Заголовок гистограммы", LegendPosition.BottomCenter, chartData);
|
|
|
|
|
|
|
|
|
|
MessageBox.Show("PDF успешно сгенерирован!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"Ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-21 17:41:05 +04:00
|
|
|
|
}
|
|
|
|
|
}
|