Create custom .NET control button for CRUD
I'm going to create a Custom Control button that will do CRUD tasks for me. Let me clarify:
I need something that will save time on code to write in each UI for CRUD tasks. I'm here because I want to make sure that the approach I'm taking has to be tested before I find the clock and strain.
A custom (maybe custom) control button that will accept the delegate. This delegate will have a Custom EventArg that will take a reference to the bussiness class and the enum CRUD (Create, Read, Update, Delete). Each business class will implement an interface that will provide four functions (CRUD functions). Now, once you've dragged this control onto the form, what you need to do is create a delegate that needs a business class reference and a CRUD enumeration to perform one of the CRUD functions.
I'm not sure if the approach I have taken is correct. But it looks like it will make my life much easier and the code is manageable. Please help me what you think it will heal me or curse me :)
PS: I would be grateful if an explanation is provided in an example. Thanks.
I would split CRUD into 4 separate commands. So, one for Create, one for Read ... and then I would implement the button.Click button on the form that uses the button. In case I would execute the correct CRUD command.
Example:
public interface ICommand
{
void Execute ();
}
public class UpdateCommand : ICommand
{
public UpdateCommand ()
{
// Maybe some business logic has to be passed in the ctor.
}
public void Execute ()
{
// Do the update stuff here
}
}
// somewhere in the Form:
public void Button_Update_Click(object sender, EventArgs e)
{
UpdateCommand command = new UpdateCommand();
command.Execute()
}
Perhaps this link will help you understand the command pattern.
It helps you to easily separate functionality and test it easily with TDD.
a source to share