175 lines
6.1 KiB
C#
175 lines
6.1 KiB
C#
using COP;
|
|
|
|
|
|
using COP.Enums;
|
|
using COP.Info;
|
|
using static COP.ExcelComponent;
|
|
|
|
|
|
namespace TestsComponents
|
|
{
|
|
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("Îøèáêà");
|
|
}
|
|
}
|
|
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 = "Îòäåë1", Position = "Äîëæíîñòü1", Name = "Ñîòðóäíèê1" },
|
|
new Employee { Department = "Îòäåë2", Position = "Äîëæíîñòü2", Name = "Ñîòðóäíèê2" },
|
|
new Employee { Department = "Îòäåë1", Position = "Äîëæíîñòü1", Name = "Ñîòðóäíèê3" },
|
|
new Employee { Department = "Îòäåë2", Position = "Äîëæíîñòü3", Name = "Ñîòðóäíèê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; }
|
|
}
|
|
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("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Îøèáêà",
|
|
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 = "Îëåã", Surname = "Ñàëèí", Age = "20", Department = "IT", Position = "Senior" },
|
|
new Employee2 { Id = 2, Status = "Active", Name = "Àðòóð", Surname = "Íàñûðîâ", Age = "19", Department = "Design", Position = "Ñòàæ¸ð" },
|
|
};
|
|
Dictionary<string, (List<(string, string)>, List<int>)> headers = new()
|
|
{
|
|
{ "Èäåíòèôèêàòîð", (new List<(string, string)> { ("Id", "Èäåíòèôèêàòîð") }, new List<int> { 30 }) },
|
|
{ "Ëè÷íûå äàííûå", (new List<(string, string)> { ("Name", "Èìÿ"), ("Surname", "Ôàìèëèÿ"), ("Age", "Âîçðàñò") }, new List<int> { 25, 25, 25 }) },
|
|
{ "Ñòàòóñ", (new List<(string, string)> { ("Status", "Ñòàòóñ") }, new List<int> { 30 }) },
|
|
{ "Ðàáîòà", (new List<(string, string)> { ("Department", "Îòäåë"), ("Position", "Äîëæíîñòü") }, 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("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Îøèáêà",
|
|
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("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Îøèáêà",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|