PIbd-32_Artamonova_T.V._COP_2/TestComponents/FormTestComponents.cs

180 lines
7.2 KiB
C#
Raw Permalink Normal View History

2023-10-13 21:09:48 +04:00
using COP;
using COP.Enums;
using COP.Info;
using DocumentFormat.OpenXml.EMMA;
using System.ComponentModel;
2023-10-24 01:43:07 +04:00
using System.Linq.Expressions;
2023-10-13 21:09:48 +04:00
using static COP.ExcelComponent;
namespace TestComponents
2023-10-12 18:40:10 +04:00
{
public partial class FormTestComponents : Form
{
public FormTestComponents()
{
InitializeComponent();
Fill();
}
private void Fill()
{
List<string> items = new() { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
userCheckedListBox.FillList(items);
}
private void UserCheckedListBox_SelectedValueChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected value changed");
}
private void ButtonClear_Click(object sender, EventArgs e)
{
userCheckedListBox.ClearList();
}
private void ButtonShowItems_Click(object sender, EventArgs e)
{
textBoxItems.Clear();
textBoxItems.Text = userCheckedListBox.SelectedValue;
}
private void ButtonShowDate_Click(object sender, EventArgs e)
{
try
{
textBoxShowDate.Clear();
textBoxShowDate.Text = userDateTimePicker.SelectedValue.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void UserDateTimePicker_ValueChanged(object sender, EventArgs e)
{
MessageBox.Show("Value changed");
DateTime? selectedDate = userDateTimePicker.SelectedValue;
}
private void UserTreeView_Load(object sender, EventArgs e)
{
2023-10-13 21:09:48 +04:00
List<Employee1> employees = new()
2023-10-12 18:40:10 +04:00
{
2023-10-13 21:09:48 +04:00
new Employee1 { Department = "Отдел1", Position = олжность1", Name = "Сотрудник1" },
new Employee1 { Department = "Отдел2", Position = олжность2", Name = "Сотрудник2" },
new Employee1 { Department = "Отдел1", Position = олжность1", Name = "Сотрудник3" },
new Employee1 { Department = "Отдел2", Position = олжность3", Name = "Сотрудник4" },
2023-10-12 18:40:10 +04:00
};
var Hierarchy = new List<string> { "Department", "Position", "Name" };
foreach (var prop in employees[0].GetType().GetProperties())
{
userTreeView.Hierarchy.Add(prop.Name);
}
try
{
userTreeView.PopulateTree(employees);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
2023-10-13 21:09:48 +04:00
public class Employee1
2023-10-12 18:40:10 +04:00
{
public string? Department { get; set; }
public string? Position { get; set; }
public string? Name { get; set; }
}
2023-10-13 21:09:48 +04:00
private void buttonSaveToExcel_Click(object sender, EventArgs e)
{
ExcelComponent excel = new();
List<ImageInfo> images = new()
{
new ImageInfo() { FilePath = "C:\\Users\\User\\Documents\\image1.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\User\\Documents\\image2.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\User\\Documents\\image3.jpg" }
};
ExcelImageInfo info = new("C:\\Users\\User\\Documents\\test.xlsx", "My Document", images);
try
{
excel.GenerateExcelWithImages(info);
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
2023-10-24 01:43:07 +04:00
}
2023-10-13 21:09:48 +04:00
private void buttonSaveTable_Click(object sender, EventArgs e)
2023-10-24 01:43:07 +04:00
{
2023-10-13 21:09:48 +04:00
ExcelTable table = new();
2023-10-24 01:43:07 +04:00
var data = new List<Employee>
2023-10-13 21:09:48 +04:00
{
new Employee { Id = 1, Status = "Active", Name = "John", Surname = "Doe", Age = "30", Department = "IT", Position = "Manager" },
new Employee { Id = 2, Status = "Active", Name = "Jane", Surname = "Smith", Age = "35", Department = "Design", Position = "Senior" },
};
2023-10-24 01:43:07 +04:00
Dictionary<string, ((List<string>, List<string>), List<int>)> headers = new()
2023-10-13 21:09:48 +04:00
{
2023-10-24 01:43:07 +04:00
{ "Идентификатор", ((new List<string> { "Id" }, new List<string> {"Идентификатор"} ), new List<int> { 30 } )},
{ "Личные данные", ((new List <string> { "Name", "Surname", "Age" }, new List<string> { "Имя", "Фамилия", "Возраст" }), new List<int> { 25, 25, 25 }) },
{ "Статус", ((new List<string> { "Status" }, new List<string> { "Статус"}), new List<int> { 30 } )},
{ "Работа", ((new List < string > { "Department", "Position" } , new List < string > { "Отдел", "Должность" }), new List<int> { 25, 25 } )}
2023-10-13 21:09:48 +04:00
};
2023-10-24 01:43:07 +04:00
ExcelTableInfo<Employee> info = new("C:\\Users\\User\\Documents\\testtable.xlsx", "My Document", data, headers);
2023-10-13 21:09:48 +04:00
try
{
table.GenerateDocument(info);
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
2023-10-24 01:43:07 +04:00
}
2023-10-13 21:09:48 +04:00
}
public class Employee
2023-10-24 01:43:07 +04:00
{
2023-10-13 21:09:48 +04:00
public int? Id { get; set; }
public string? Status { get; set; } = string.Empty;
public string? Name { get; set; } = string.Empty;
public string? Surname { get; set; } = string.Empty;
public string? Age { get; set; } = string.Empty;
public string? Department { get; set; } = string.Empty;
public string? Position { get; set; } = string.Empty;
}
private void buttonSaveChart_Click(object sender, EventArgs e)
{
PieChart chart = new();
LegendPosition legend = new();
var data = new List<DataItem>()
{
new DataItem() { Name = "Data 1", Value = 10 },
new DataItem() { Name = "Data 2", Value = 20 },
new DataItem() { Name = "Data 3", Value = 30 },
new DataItem() { Name = "Data 4", Value = 40 }
};
ExcelChartInfo info = new("C:\\Users\\User\\Documents\\testchart.xlsx", "My Document", "My Chart", legend, data);
try
{
chart.GenerateDocument(info);
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
2023-10-12 18:40:10 +04:00
}
}