Example #1
0
        public void Credit(int accountNumber, decimal amount)
        {
            m_AccountsDataSet.Clear();
            m_Adapter.Fill(m_AccountsDataSet, "BankAccounts");

            AccountsDataSet.BankAccountsDataTable accounts = m_AccountsDataSet.BankAccounts;
            AccountsDataSet.BankAccountsRow       account  = accounts.FindByNumber(accountNumber);
            account.Balance += amount;
            m_Adapter.Update(accounts);
        }
Example #2
0
        public void Debit(int accountNumber, decimal amount)
        {
            m_AccountsDataSet.Clear();
            m_Adapter.Fill(m_AccountsDataSet, "BankAccounts");

            AccountsDataSet.BankAccountsDataTable accounts = m_AccountsDataSet.BankAccounts;
            AccountsDataSet.BankAccountsRow       account  = accounts.FindByNumber(accountNumber);
            if (account.Balance >= amount)
            {
                account.Balance -= amount;
            }
            else
            {
                //Aborts the transaction as well
                throw new InvalidOperationException("Debit amount is greater than balance in account #" + accountNumber);
            }
            m_Adapter.Update(accounts);
        }