예제 #1
0
        private void btnProcessTransfer_Click(object sender, EventArgs e)
        {
            BLLMngr bllMngr = new BLLMngr();
            string type = "Transfer";

            // Creating debtor and creditor models and adding two transactions to DB
            TransactionModel debtor = new TransactionModel(DebtorID, Amount, type, Description);
            bllMngr.CreateTransaction(debtor);
            int debID = bllMngr.TransactionID; // Taking Id from debtor transaction

            TransactionModel creditor = new TransactionModel(CreditorID, Amount, type, Description);
            bllMngr.CreateTransaction(creditor);
            int credID = bllMngr.TransactionID; // Taking ID from creditor transaction

            TransferModel transfer = new TransferModel(debID, credID, CreditorSortCode, CreditorAccountNumber);

            CreditorBalance += Amount;
            DebtorBalance -= Amount;

            // Creating models so that balance may be updated in UpdateAccountBalance() below
            AccountModel credAcc = new AccountModel(CreditorID, CreditorBalance);
            AccountModel debAcc = new AccountModel(DebtorID, DebtorBalance);

            bllMngr.CreateTransfer(credID, debID, transfer);
            bllMngr.UpdateAccountBalance(debAcc);
            bllMngr.UpdateAccountBalance(credAcc);

            MessageBox.Show("Transfer Complete");

            this.Close();
        }
예제 #2
0
        private void btnProcessTransaction_Click(object sender, EventArgs e)
        {
            // TRANSACTION DETAILS //
            string type = cboType.Text;
            string description = txtDescription.Text;
            string amountEuro = txtAmountEuro.Text.Trim();

            // Takes Euro and Cent values, Adds them and stores cent value as int in Database
            string amountString = amountEuro + amountCent;
            int amount;
            int.TryParse(amountString, out amount);
            //method used to update the balance in users account
            int currentBalance = CurrentBalance(balance, amount);

            AccountModel account = new AccountModel(accountID, currentBalance);
            TransactionModel transaction = new TransactionModel(accountID, amount, type, description);

            BLLMngr bllMngr = new BLLMngr();

            if(cboType.SelectedIndex == 2)
            {
                // Making a record of transaction and Updating Balance
                bllMngr.CreateTransaction(transaction);
                bllMngr.UpdateAccountBalance(account);
                MessageBox.Show("Deposit Complete");
            }
            else if(cboType.SelectedIndex == 1)
            {
                if (bllMngr.ValidateWithdrawal(balance, overdraftLimit, amount))
                {
                    bllMngr.CreateTransaction(transaction);
                    bllMngr.UpdateAccountBalance(account);
                    MessageBox.Show("Withdrawal Complete");
                }
                else
                {
                    MessageBox.Show("Insufficient Funds");
                }
            }
            else if(cboType.SelectedIndex == 0)
            {
                using(ProcessTransfer procTransfer = new ProcessTransfer())
                {
                    this.Hide();
                    // common variables
                    procTransfer.Amount = amount;
                    procTransfer.Description = txtDescription.Text;

                    // debtor (cutomer who will send the money)
                    procTransfer.DebtorAccountNumber = int.Parse(txtAccountNumber.Text);
                    procTransfer.DebtorName = txtName.Text;
                    procTransfer.DebtorID = accountID;
                    procTransfer.DebtorSortCode = 101010;
                    procTransfer.DebtorBalance = balance;

                    //creditor (account to which money will be sent)
                    procTransfer.CreditorAccountNumber = int.Parse(txtRecipientAccNo.Text);
                    procTransfer.CreditorSortCode = int.Parse(txtRecipientSortCode.Text);
                    procTransfer.CreditorID = bllMngr.GetAccountID(int.Parse(txtRecipientAccNo.Text));
                    procTransfer.CreditorBalance = bllMngr.GetAccountBalance(int.Parse(txtRecipientAccNo.Text));

                    //put values from previous form in here//
                    procTransfer.ShowDialog();
                }
                this.Close();
            }

            this.Close();
        }