示例#1
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();
        }