task 1 complete task2 task2 change test data initialization task3 task2 fix fixes add percents minor fixes
279 lines
6.1 KiB
C#
279 lines
6.1 KiB
C#
using ComponentLibrary1.pdf_diagram;
|
||
using ComponentLibrary1.pdf_image;
|
||
using ComponentLibrary1.pdf_table;
|
||
|
||
namespace TestApp1
|
||
{
|
||
public partial class Form1 : Form
|
||
{
|
||
private List<byte[]> selectedImages = new List<byte[]>();
|
||
public Form1()
|
||
{
|
||
InitializeComponent();
|
||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||
checkList.ChangeEvent += DoChange;
|
||
limitedText.ChangeEvent += DoChange2;
|
||
List<string> categories = new List<string>
|
||
{
|
||
"Department",
|
||
"JobTitle",
|
||
"FullName"
|
||
};
|
||
treeList.SetCategories(categories);
|
||
}
|
||
|
||
#region test1
|
||
private void input_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
checkList.Input(textBox1.Text);
|
||
textBox1.Text = string.Empty;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void clear_Click(object sender, EventArgs e)
|
||
{
|
||
checkList.Clear();
|
||
}
|
||
|
||
private void set_Click(object sender, EventArgs e)
|
||
{
|
||
checkList.SelectedItem = textBox1.Text;
|
||
}
|
||
|
||
private void get_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text = checkList.SelectedItem;
|
||
}
|
||
private void DoChange(object? sender, EventArgs e)
|
||
{
|
||
changeBox.Checked = true;
|
||
}
|
||
#endregion
|
||
|
||
#region test2
|
||
private void write_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
limitedText.TextField = textBox2.Text;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void read_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
textBox2.Text = limitedText.TextField;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void inputMin_Click(object sender, EventArgs e)
|
||
{
|
||
limitedText.Min = (int)numericMin.Value;
|
||
}
|
||
|
||
private void inputMax_Click(object sender, EventArgs e)
|
||
{
|
||
limitedText.Max = (int)numericMax.Value;
|
||
}
|
||
|
||
private void DoChange2(object? sender, EventArgs e)
|
||
{
|
||
changeBox2.Checked = true;
|
||
}
|
||
#endregion
|
||
|
||
#region test3
|
||
private void add_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(textBoxDepartment.Text) ||
|
||
string.IsNullOrEmpty(textBoxJobTitle.Text) ||
|
||
string.IsNullOrEmpty(textBoxFullName.Text))
|
||
{
|
||
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
}
|
||
treeList.AddTreeListObject(new Employee(textBoxDepartment.Text, textBoxJobTitle.Text, textBoxFullName.Text));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void clearTreeList_Click(object sender, EventArgs e)
|
||
{
|
||
treeList.Clear();
|
||
}
|
||
|
||
private void getObject_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
Employee? employee = treeList.GetSelectedObject<Employee>();
|
||
if (employee == null)
|
||
{
|
||
return;
|
||
}
|
||
textBoxDepartment.Text = employee.Department;
|
||
textBoxJobTitle.Text = employee.JobTitle;
|
||
textBoxFullName.Text = employee.FullName;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region test4
|
||
private void chooseImage_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
using OpenFileDialog openFileDialog = new OpenFileDialog
|
||
{
|
||
Multiselect = true,
|
||
Filter = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|*.jpg;*.jpeg;*.png;*.bmp"
|
||
};
|
||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
selectedImages.Clear();
|
||
listBoxImages.Items.Clear();
|
||
foreach (string filePath in openFileDialog.FileNames)
|
||
{
|
||
selectedImages.Add(File.ReadAllBytes(filePath));
|
||
listBoxImages.Items.Add(Path.GetFileName(filePath));
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void createPdfImages_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (selectedImages.Count == 0)
|
||
{
|
||
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
var info = new PdfImageInfo
|
||
{
|
||
FileName = "C://Users//user//PdfWithImage.pdf",
|
||
Title = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||
Images = selectedImages
|
||
};
|
||
pdfImage.CreatePdf(info);
|
||
MessageBox.Show("PDF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region test5
|
||
private void createTable_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
List<TreeNode> headers = new List<TreeNode>
|
||
{
|
||
new TreeNode
|
||
{
|
||
Text = "<22><><EFBFBD>",
|
||
Tag = "FullName",
|
||
},
|
||
new TreeNode("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", new TreeNode[]
|
||
{
|
||
new TreeNode
|
||
{
|
||
Text = "<22><><EFBFBD><EFBFBD><EFBFBD>",
|
||
Tag = "Department"
|
||
},
|
||
new TreeNode
|
||
{
|
||
Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||
Tag = "JobTitle"
|
||
}
|
||
})
|
||
};
|
||
List<Employee> data = new List<Employee>
|
||
{
|
||
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD>"),
|
||
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD>", "<22><><EFBFBD><EFBFBD>")
|
||
};
|
||
var info = new PdfTableInfo<Employee>
|
||
{
|
||
FileName = "C://Users//user//PdfWithTable.pdf",
|
||
Title = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||
Headers = headers,
|
||
Data = data
|
||
};
|
||
pdfTable.CreatePdf(info);
|
||
MessageBox.Show("PDF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region test6
|
||
private void createDiagram_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
pdfDiagram.CreateDiagram(new PdfDiagramInfo
|
||
{
|
||
FileName = "C://Users//user//PdfWithPieDiagram.pdf",
|
||
Title = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||
ChartTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2024",
|
||
LegendLocation = ComponentLibrary1.office_package.HelperEnums.PdfDiagramLegendLocation.Bottom,
|
||
Series = new ComponentLibrary1.office_package.HelperModels.PdfDiagramSeries
|
||
{
|
||
SeriesName = "DesctopOperatingSystemAugust2024",
|
||
Data = new Dictionary<string, double>
|
||
{
|
||
{ "Windows", 71.5 },
|
||
{ "OS X", 15.5 },
|
||
{ "Linux", 4.5 },
|
||
{ "Others", 8.5 },
|
||
}
|
||
}
|
||
});
|
||
MessageBox.Show("PDF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}");
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|