private void Transactions_Load(object sender, EventArgs e)
 {
     //Setting the data source of the data grid to displaya transactions
     transactionBLL = new TransactionBLLManager();
     DataSet ds = transactionBLL.GetDetailsForViewGrid(AccountNumber);
     dgvDisplay.DataSource = ds.Tables[0];
 }
 public PrintTransactions(int accountNumber)
 {
     InitializeComponent();
     AccountNumber = accountNumber;
     transactionBLL = new TransactionBLLManager();
     DataSet ds = transactionBLL.GetDetailsForViewGrid(AccountNumber);
     dgvTransactions.DataSource = ds.Tables[0];
     lblAccNum.Text = AccountNumber.ToString();
 }
        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");
        }
        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!");
            }
        }
        private void btnTransfer_Click(object sender, EventArgs e)
        {
            AccountBLLManager accountBLL = new AccountBLLManager();
            Account fromAccount = new Account();
            Account toAccount = new Account();

            fromAccount.AccountNumber = int.Parse(txtFromAccountNumber.Text);
            toAccount.AccountNumber = int.Parse(txtToAccountNumber.Text);

            int amount;
            int updateSourceAccBalance;

            //If transfer is an external account, ignore searched account balance and just record transaction
            //and update senders account balance. No updating of external account balance.
            if (cbExternalYes.Checked)
            {
                if (accountBLL.ExternalTransfer(fromAccount, toAccount))
                {
                    try
                    {
                        Transaction newTransaction = new Transaction();
                        TransactionBLLManager transactionBLL = new TransactionBLLManager();

                        newTransaction.TransactionType = txtTransferTransactionType.Text;
                        newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToTransfer.Text);
                        newTransaction.TransactionDate = DateTime.Now;
                        newTransaction.TransactionReference = txtTransferReference.Text;
                        newTransaction.AccountNumber = int.Parse(txtFromAccountNumber.Text);
                        newTransaction.DestinationAccountNumber = int.Parse(txtToAccountNumber.Text);
                        newTransaction.TransactionDescription = txtTransferDescription.Text;

                        if (transactionBLL.RecordTransactionTransfer(newTransaction))

                            MessageBox.Show("Transfer Success", "SUCCESS!");
                        else
                            MessageBox.Show("Error in DB, contact Admin", "ERROR!");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    this.Close();
                }
            }
            //If transfer is internal, validate fields, update sender and reciever account balance and record
            //transaction in TransactionTable
            else if (!cbExternalYes.Checked)
            {
                if (Validation.IsCurrencyFormat(txtFromBalance.Text) && Validation.IsCurrencyFormat(txtAmountToTransfer.Text) && Validation.IsCurrencyFormat(txtAmountToTransfer.Text))
                {
                    amount = accountBLL.FormatCurrency(txtAmountToTransfer.Text);

                    if (accountBLL.TransferFrom(accountBLL.FormatCurrency(txtFromBalance.Text), amount, out updateSourceAccBalance))
                    {
                        toAccount.Balance = accountBLL.TransferTo(accountBLL.FormatCurrency(txtToBalance.Text), amount);
                        fromAccount.Balance = updateSourceAccBalance;

                        try
                        {

                            if (accountBLL.Transfer(fromAccount, toAccount))
                            {
                                try
                                {
                                    Transaction newTransaction = new Transaction();
                                    TransactionBLLManager transactionBLL = new TransactionBLLManager();

                                    newTransaction.TransactionType = txtTransferTransactionType.Text;
                                    newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToTransfer.Text);
                                    newTransaction.TransactionDate = DateTime.Now;
                                    newTransaction.TransactionReference = txtTransferReference.Text;
                                    newTransaction.AccountNumber = int.Parse(txtFromAccountNumber.Text);
                                    newTransaction.DestinationAccountNumber = int.Parse(txtToAccountNumber.Text);
                                    newTransaction.TransactionDescription = txtTransferDescription.Text;

                                    if (transactionBLL.RecordTransactionTransfer(newTransaction))
                                        MessageBox.Show("Transfer Success", "SUCCESS!");
                                    else
                                        MessageBox.Show("Error in DB, contact Admin", "ERROR!");
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                                this.Close();
                            }

                            else
                                MessageBox.Show("Error in transfer", "ERROR!");

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
                else
                    MessageBox.Show("Insufficient Funds", "ERROR!");
            }
            else
                MessageBox.Show("Please enter currency in 0.00 format");
        }