窗口初始化
点击查看代码
public FrmEidt()
{
InitializeComponent();
this.Text = "添加窗口";
this.txtCode.Focus();
this.btnSave.Click -= btnEditEmployee_Click;
this.btnSave.Click += btnAddEmployee_Click;
}
添加员工业务
点击查看代码
/// <summary>
/// 添加员工业务
/// </summary>
/// <returns></returns>
private bool AddEmployee()
{
//封装Employee
Employee employee = new Employee()
{
Id = Guid.NewGuid(),
EmployeeCode = this.txtCode.Text.Trim(),
EmployeeName = this.txtName.Text.Trim(),
CreateTime = DateTime.Now
};
try
{
//调用方法
return (1 == employeeDao.AddEmployee(employee));
}
catch (Exception)
{
return false;
throw;
}
}
绑定按钮点击事件
点击查看代码
/// <summary>
/// 增加员工事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddEmployee_Click(object sender, EventArgs e)
{
if (AddEmployee()==false) { return; }
this.DialogResult = DialogResult.OK;
}