private void Adduser_btn_Click(object sender, EventArgs e) { // get textbox value string new_user = user_textbox.ForeColor == Color.Black ? user_textbox.Text : ""; string account_name = account_textbox.ForeColor == Color.Black ? account_textbox.Text : ""; int account_id = CURRENT_USER_ACCOUNTS[account_name]; // verify if account field is filled if ("".Equals(account_name)) { ErrorMessenger.EmptyField("Acount name"); return; } // verify if account exists var exists = DB_API.ExistsMoneyAccount(account_id); if (!exists) { ErrorMessenger.Error("Account does not exist!"); return; } // verify that a user is selected if (new_user.Equals("")) { ErrorMessenger.Error("User must be selected to attribute account to!"); return; } // verify if user exists exists = DB_API.ExistsUser(new_user); if (!exists) { ErrorMessenger.Error("User does not exist!"); return; } // verify if user already is associated with account var rdr = DB_API.SelectMoneyAccountUsers(account_id); while (rdr.Read()) { if (rdr[DB_API.MoneyAccountEnt.user_email.ToString()].Equals(new_user)) { ErrorMessenger.Error("User already participates in account"); return; } } // insert new account into 'users_money_accounts table DB_API.MoneyAccountAddUser(account_id, new_user); Populate_associatedUsers_listBox(account_id); }