コード例 #1
0
        private void btnDeposit_Click_1(object sender, EventArgs e)
        {
            AccountBLLManager accountBLL = new AccountBLLManager();
            Account updateBalance = new Account();

            int oldBalance, deposit;
            //Passing amount to deposit into validation to ensure correct format
            if (Validation.IsCurrencyFormat(txtAmountToDeposit.Text))
            {
                //Assigning values and passing to MakeDeposit method in the BLL
                oldBalance = accountBLL.FormatCurrency(txtFromBalance.Text);
                deposit = accountBLL.FormatCurrency(txtAmountToDeposit.Text);
                updateBalance.Balance = accountBLL.MakeDeposit(oldBalance, deposit);

                updateBalance.AccountNumber = int.Parse(txtFromAccountNumber.Text);

                try
                {
                    //If balance is successfully updated, enter record into TransactionTable by passing
                    //following values into method RecordTransaction in the BLL
                    if (accountBLL.UpdateAccountBalance(updateBalance))
                    {
                        try
                        {

                            Transaction newTransaction = new Transaction();
                            TransactionBLLManager transactionBLL = new TransactionBLLManager();

                            newTransaction.TransactionType = txtTransactionType.Text;
                            newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToDeposit.Text);
                            newTransaction.TransactionDate = DateTime.Now;
                            newTransaction.TransactionReference = txtReference.Text;
                            newTransaction.AccountNumber = int.Parse(txtAccountNumber.Text);
                            newTransaction.TransactionDescription = txtDescription.Text;

                            if (transactionBLL.RecordTransaction(newTransaction))
                                MessageBox.Show("Deposit Success", "SUCCESS!");
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        this.Close();
                    }
                    else
                        MessageBox.Show("Deposit Failure", "ERROR!");
                }

                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
                MessageBox.Show("Please enter currency format: 0.00");
        }
コード例 #2
0
        private void btnWithdraw_Click(object sender, EventArgs e)
        {
            AccountBLLManager accountBLL = new AccountBLLManager();
            Account updateBalance = new Account();

            int oldBalance, withdraw, newBalance;
            //Check for validation errors
            if (Validation.IsCurrencyFormat(txtAmountToWithdraw.Text))
            {
                //Passing values into FormatCurrency method to change format
                oldBalance = accountBLL.FormatCurrency(txtFromBalance.Text);
                withdraw = accountBLL.FormatCurrency(txtAmountToWithdraw.Text);

                //Checking if account has sufficient funds to withdraw
                if (accountBLL.HasSufficientFunds(oldBalance, withdraw, Convert.ToInt32(accountBLL.FormatCurrency(txtOverdraftLimit.Text))))
                {
                    newBalance = oldBalance - withdraw;
                    updateBalance.AccountNumber = int.Parse(txtFromAccountNumber.Text);
                    updateBalance.Balance = newBalance;

                    //If true then pass values into UpdateAccountBalance in the BLL
                    if (accountBLL.UpdateAccountBalance(updateBalance))
                    {
                        try
                        {
                            //And record the transaction in the TransactionTable
                            Transaction newTransaction = new Transaction();
                            TransactionBLLManager transactionBLL = new TransactionBLLManager();

                            newTransaction.TransactionType = txtWithdrawTransactionType.Text;
                            newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToWithdraw.Text);
                            newTransaction.TransactionDate = DateTime.Now;
                            newTransaction.TransactionReference = txtWithdrawReference.Text;
                            newTransaction.AccountNumber = int.Parse(txtWithdrawAccountNumber.Text);
                            newTransaction.TransactionDescription = txtWithdrawDescription.Text;

                            if (transactionBLL.RecordTransactionWithdraw(newTransaction))
                                MessageBox.Show("Withdrawl Success", "SUCCESS!");
                            else
                                MessageBox.Show("Error In Withdrawl", "ERROR!");
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        this.Close();
                    }
                    else
                        MessageBox.Show("Error in withdrawl", "ERROR!");
                }
                else
                    MessageBox.Show("Insufficient Funds", "ERROR!");
            }
        }