Exemple #1
0
        private void Deleteaccount_btn_Click(object sender, EventArgs e)
        {
            // get textbox value
            string account_name = account_textbox.ForeColor == Color.Black ? account_textbox.Text : "";
            int    account_id   = CURRENT_USER_ACCOUNTS[account_name];

            // verify if account exists before trying to delete
            var exists = DB_API.ExistsMoneyAccount(account_id);

            if (!exists)
            {
                ErrorMessenger.Error("Account does not exist!");
                return;
            }

            // delete money account
            bool sure = ErrorMessenger.OKCancel("Deleting a Money Account will permanently" +
                                                "delete all its transaction, categories," +
                                                "loans, goals and stock. Are you sure you want to delete?");

            if (sure)
            {
                DB_API.DeleteMoneyAccount(account_id);
                CURRENT_USER_ACCOUNTS.Remove(account_name);
            }
            else
            {
                return;
            }

            // repopulate accounts_listbox
            Populate_moneyAccounts_listBox(CURRENT_USER);
        }