175 lines
6.1 KiB
C#
Raw Normal View History

2024-09-05 15:05:04 +04:00
using COP;
2024-09-19 15:21:49 +04:00
using COP.Enums;
using COP.Info;
using static COP.ExcelComponent;
2024-09-05 09:32:21 +04:00
namespace TestsComponents
{
2024-09-05 15:05:04 +04:00
public partial class FormTestComponents : Form
{
public FormTestComponents()
{
InitializeComponent();
Fill();
}
public void Fill()
{
userCheckedListBox.append(new() { "items1", "dsdsf", "items3", "fgdg", "iit" });
}
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.Text = userCheckedListBox.SelectedValue;
}
private void ButtonShowDate_Click(object sender, EventArgs e)
{
try
{
textBoxShowDate.Clear();
textBoxShowDate.Text = userDateTimePicker.SelectedValue.ToString();
}
catch (Exception ex)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
}
private void UserDateTimePicker_ValueChanged(object sender, EventArgs e)
{
MessageBox.Show("Value changed");
DateTime? selectedDate = userDateTimePicker.SelectedValue;
}
private void ButtonRangeSet_Click(object sender, EventArgs e)
{
userDateTimePicker.MaxValue = new DateTime(2024, 9, 20);
userDateTimePicker.MinValue = new DateTime(2024,8,10);
}
private void UserTreeView_Load(object sender, EventArgs e)
{
List<Employee> employees = new List<Employee>
{
new Employee { Department = "<22><><EFBFBD><EFBFBD><EFBFBD>1", Position = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1", Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1" },
new Employee { Department = "<22><><EFBFBD><EFBFBD><EFBFBD>2", Position = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2", Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2" },
new Employee { Department = "<22><><EFBFBD><EFBFBD><EFBFBD>1", Position = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1", Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3" },
new Employee { Department = "<22><><EFBFBD><EFBFBD><EFBFBD>2", Position = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3", Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4" },
};
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);
}
}
public class Employee
{
public string? Department { get; set; }
public string? Position { get; set; }
public string? Name { get; set; }
}
2024-09-19 15:21:49 +04:00
private void buttonSaveToExcel_Click(object sender, EventArgs e)
{
ExcelComponent excel = new();
List<ImageInfo> images = new()
{
new ImageInfo() { FilePath = "C:\\Users\\ogoro\\Documents\\image1.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\ogoro\\Documents\\image2.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\ogoro\\Documents\\image3.jpg" }
};
ExcelImageInfo info = new("C:\\Users\\ogoro\\Documents\\test.xlsx", "My Document", images);
try
{
excel.GenerateExcelWithImages(info);
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSaveTable_Click(object sender, EventArgs e)
{
ExcelTable table = new();
var data = new List<Employee2>
{
new Employee2 { Id = 1, Status = "Active", Name = "<22><><EFBFBD><EFBFBD>", Surname = "<22><><EFBFBD><EFBFBD><EFBFBD>", Age = "20", Department = "IT", Position = "Senior" },
new Employee2 { Id = 2, Status = "Active", Name = "<22><><EFBFBD><EFBFBD><EFBFBD>", Surname = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", Age = "19", Department = "Design", Position = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" },
};
Dictionary<string, (List<(string, string)>, List<int>)> headers = new()
{
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (new List<(string, string)> { ("Id", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>") }, new List<int> { 30 }) },
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (new List<(string, string)> { ("Name", "<22><><EFBFBD>"), ("Surname", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), ("Age", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>") }, new List<int> { 25, 25, 25 }) },
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (new List<(string, string)> { ("Status", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>") }, new List<int> { 30 }) },
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (new List<(string, string)> { ("Department", "<22><><EFBFBD><EFBFBD><EFBFBD>"), ("Position", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>") }, new List<int> { 25, 25 }) }
};
ExcelTableInfo<Employee2> info = new("C:\\Users\\ogoro\\Documents\\testtable.xlsx", "My Document", data, headers);
try
{
table.GenerateDocument(info);
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public class Employee2
{
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\\ogoro\\Documents\\testchart.xlsx", "My Document", "My Chart", legend, data);
try
{
chart.GenerateDocument(info);
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
2024-09-05 09:32:21 +04:00
}