窗口初始化
点击查看代码
//编辑员工实例
private Employee employee = null;
public FrmEidt(Employee emp =null)
{
InitializeComponent();
this.Text = "修改窗口";
this.btnSave.Click -= btnAddEmployee_Click;
this.btnSave.Click += btnEditEmployee_Click;
if (emp != null )
{
this.employee = new Employee();
this.txtCode.Text = emp.EmployeeCode;
this.txtName.Text = emp.EmployeeName;
this.employee.Id = emp.Id;
}
this.txtCode.Focus();
}
编辑员工业务
点击查看代码
/// <summary>
/// 编辑员工业务
/// </summary>
/// <returns></returns>
private bool EditEmployee()
{
//封装Employee
//Employee employee = new Employee()
//{
// EmployeeCode = this.txtCode.Text.Trim(),
// EmployeeName = this.txtName.Text.Trim(),
//};
this.employee.EmployeeCode = this.txtCode.Text.Trim();
this.employee.EmployeeName = this.txtName.Text.Trim();
try
{
return (1==employeeDao.UpdateEmployee(employee));
}
catch (Exception)
{
return false;
throw;
}
}
绑定员工点击事件
点击查看代码
/// <summary>
/// 编辑员工事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnEditEmployee_Click(object sender, EventArgs e)
{
if (EditEmployee() == false) { return; }
this.DialogResult = DialogResult.OK;
}