244 lines
9.9 KiB
C#
244 lines
9.9 KiB
C#
using COP;
|
||
using COP.Enums;
|
||
using COP.Info;
|
||
using DocumentFormat.OpenXml.EMMA;
|
||
using System.ComponentModel;
|
||
using static COP.ExcelComponent;
|
||
|
||
namespace TestComponents
|
||
{
|
||
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)
|
||
{
|
||
List<Employee1> employees = new()
|
||
{
|
||
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" },
|
||
};
|
||
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 Employee1
|
||
{
|
||
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\\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);
|
||
}
|
||
}
|
||
public class Sportsmen
|
||
{
|
||
public string name;
|
||
public string sport;
|
||
public string city;
|
||
public string country;
|
||
public string Region { get { return city; } set { city = value; } }
|
||
public string awards;
|
||
public Sportsmen(string name, string sport, string city, string country, string awards)
|
||
{
|
||
this.name = name;
|
||
this.sport = sport;
|
||
this.city = city;
|
||
this.country = country;
|
||
this.awards = awards;
|
||
}
|
||
public Sportsmen() { }
|
||
public override string ToString()
|
||
{
|
||
return country + " " + city + " " + name + " " + sport + " " + awards;
|
||
}
|
||
}
|
||
|
||
string[] names = { "Vova M", "Sasha A", "Dima D", "Danila L" };
|
||
string[] sports = { "Run", "Swim", "Cycle", "Race", "Box" };
|
||
string[] cities = { "Moskow", "Samara", "Piter", "Kazan", "Kyrsk" };
|
||
string[] countries = { "Russia", "Spain", "China", "India", "Brazil" };
|
||
string[] rewards = { "#1", "#2", "KMS", "Olymp", "MS" };
|
||
List<Employee> sportsmens = new();
|
||
|
||
private void buttonSaveTable_Click(object sender, EventArgs e)
|
||
{
|
||
ExcelTable table = new();
|
||
string path = @"C:\\Users\\User\\Documents\\testtable.xlsx";
|
||
string title = "title";
|
||
var dataList = new List<object>
|
||
{
|
||
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" },
|
||
};
|
||
|
||
var info = new ExcelTableInfo(path, "Sample Document", new List<object>(), new Dictionary<string, (List<string>, List<int>)>());
|
||
|
||
info.addDictionary("Table1", "Field1", 20);
|
||
info.addDictionary("Table1", "Field2", 15);
|
||
info.addDictionary("Table2", "Field1", 25);
|
||
info.addDictionary("Table2", "Field2", 18);
|
||
info.addDictionary("Table2", "Field3", 22);
|
||
|
||
info.addDictionaryAlone("Table3", 30);
|
||
|
||
info.Data.Add(new Employee1 { Department = "Dept1", Position = "Position1", Name = "Employee1" });
|
||
info.Data.Add(new Employee1 { Department = "Dept2", Position = "Position2", Name = "Employee2" });
|
||
info.Data.Add(new Employee1 { Department = "Dept1", Position = "Position1", Name = "Employee3" });
|
||
|
||
dataList.Clear();
|
||
try
|
||
{
|
||
table.GenerateDocument(info);
|
||
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка",
|
||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
/*ExcelTable table = new();
|
||
|
||
var mergeInfo = new List<MergeInfo>
|
||
{
|
||
new MergeInfo { Value = "", StartRow = 0, EndRow = 0, StartCol = 0, EndCol = 1 },
|
||
new MergeInfo { Value = "", StartRow = 1, EndRow = 1, StartCol = 0, EndCol = 1 },
|
||
new MergeInfo { Value = "Личные данные", StartRow = 2, EndRow = 4, StartCol = 0, EndCol = 0 },
|
||
new MergeInfo { Value = "Работа", StartRow = 5, EndRow = 6, StartCol = 0, EndCol = 0 }
|
||
};
|
||
var headerTitles = new List<string> { "ID", "Status", "Name", "Surname", "Age", "Department", "Position" };
|
||
var data = new List<object>
|
||
{
|
||
new Employees { Id = 1, Status = "Active", Name = "John", Surname = "Doe", Age = "30", Department = "IT", Position = "Manager" },
|
||
new Employees { Id = 2, Status = "Active", Name = "Jane", Surname = "Smith", Age = "35", Department = "Design", Position = "Senior" },
|
||
};
|
||
ExcelTableInfo info = new("C:\\Users\\User\\Documents\\testtable.xlsx", "My Document", mergeInfo, headerTitles, data);
|
||
try
|
||
{
|
||
table.GenerateDocument(info);
|
||
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка",
|
||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}*/
|
||
}
|
||
|
||
public class Employee
|
||
{
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
} |