VeecoTech
VeecoTech

Reputation: 2143

User control button

i would like to create a custom control for my crud buttons. The user controls will have the following code.

 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.");
        }
    }

}

My GUI

private void adminUserController_DeleteClick(object sender, EventArgs e)
{
    Repository.Delete(user);
}

Question:
1) What is the best way to pass the DeleteResult boolean result from GUI to User control? How do i create an event for the delete button which can be hooked by the UI? 2) Do u think is good if i put my error logger code at the user control button?

Upvotes: 0

Views: 577

Answers (1)

DarkSquirrel42
DarkSquirrel42

Reputation: 10267

replace the call in your adminUserController_DeleteClick with a call to a new method (foo)

private DeleteResult foo(TypeOfUser user)
{
   return Repository.Delete(user);
}

and call foo instead of adminUserController_DeleteClick

foo will return the desired result

Upvotes: 1

Related Questions