我想为我的crud按钮创建一个自定义控件。用户控件将具有以下代码。
private void btnDelete_Click(object sender, EventArgs e)
{ if (MessageBox.Show("Are you sure to Delete?", "Please Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
DeleteClick(sender, e); // this will read the code from GUI delete button
if (DeleteResult.Success)
{
MessageBox.Show("This record is deleted successfully.");
}
else
{
MessageBox.Show("This record is deleted failed.");
}
}
}
我的GUI
private void adminUserController_DeleteClick(object sender, EventArgs e)
{
Repository.Delete(user);
}
问题:
1)将DeleteResult布尔结果从GUI传递给用户控件的最佳方法是什么?如何为删除按钮创建一个可以被UI挂钩的事件?
2)如果我将错误记录器代码放在用户控制按钮上,您认为好吗?
答案 0 :(得分:1)
通过调用新方法(foo)替换adminUserController_DeleteClick中的调用
private DeleteResult foo(TypeOfUser user)
{
return Repository.Delete(user);
}
并调用foo而不是adminUserController_DeleteClick
foo将返回所需的结果