Say I have 2 buttons witch supposed to perform the same operation but on different objects.
Currently I'm passing all the needed references to the method like this:
private void sub1_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(
substanse1, sub1_add_to_db_btn, sub2_add_to_db_btn, sub1_found_in_db_list,
sub2_found_in_db_list, false, sub1_listBox, sub2_listBox);
}
private void sub2_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(
substanse2, sub2_add_to_db_btn, sub1_add_to_db_btn, sub2_found_in_db_list,
sub1_found_in_db_list, false, sub2_listBox, sub1_listBox);
}
I was wondering if there is some other, more efficient way to do that. Thanks.
EDIT:
This is how some of my code looks like and it making me CRAZY!!!
private void sub1_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse1, sub1_add_to_db_btn, sub2_add_to_db_btn,
sub1_found_in_db_list, sub2_found_in_db_list, false, sub1_listBox, sub2_listBox);
}
private void sub2_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse2, sub2_add_to_db_btn, sub1_add_to_db_btn,
sub2_found_in_db_list, sub1_found_in_db_list, false, sub2_listBox, sub1_listBox);
}
private void sub1_edit_name_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse1, sub1_add_to_db_btn, sub2_add_to_db_btn,
sub1_found_in_db_list, sub2_found_in_db_list, true, sub1_listBox, sub2_listBox);
}
private void sub2_edit_name_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse2, sub2_add_to_db_btn, sub1_add_to_db_btn,
sub2_found_in_db_list, sub1_found_in_db_list, true, sub2_listBox, sub1_listBox);
}
private void sub1_delete_from_db_btn_Click(object sender, EventArgs e)
{
Delete_Substance_From_DB(sub1_listBox,
sub2_listBox,sub2_list_is_from_file,sub1_delete_from_db_btn,
sub2_delete_from_db_btn);
}
private void sub2_delete_from_db_btn_Click(object sender, EventArgs e)
{
Delete_Substance_From_DB(sub2_listBox,
sub1_listBox,sub1_list_is_from_file,sub2_delete_from_db_btn,
sub1_delete_from_db_btn);
}
For example: If I want to delete a substance, I need to delete it from both of the lists and remove it from other lists, change the selection to the next substance etc...