Component-oriented-programming/TestApp1/Form1.cs

137 lines
2.7 KiB
C#
Raw Permalink Normal View History

namespace TestApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
checkList.ChangeEvent += DoChange;
limitedText.ChangeEvent += DoChange2;
List<string> categories = new List<string>();
categories.Add("Department");
categories.Add("JobTitle");
categories.Add("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
}
}