Beispiel #1
0
        }//end of NoEdit

        //click to initiate a withdraw
        private void btnWithdraw_Click(object sender, EventArgs e)
        {
            // get account type
            string accType = "";

            if (rdoCurrentAcc.Checked)
            {
                accType = "current";
            }
            else if (rdoSavingsAcc.Checked)
            {
                accType = "saving";
            }

            // for old balance
            string ob = txtCurrentBal.Text;

            ob = ob.Replace("€", "");
            ob = ob.Replace(".", "");
            ob = ob.Replace(",", "");//this is needed if the sum is larger
            string newBbb = ob;

            int oldBalance;

            oldBalance = int.Parse(ob);//Convert.ToInt32(ob);

            // get overdraft amount
            string od = txtOverdraft.Text;

            od = od.Replace("€", "");
            od = od.Replace(".", "");
            od = od.Replace(",", "");

            int ovaDraft;

            ovaDraft = Convert.ToInt32(od);
            // negative OverDraft to compare new balance with
            int negOvaDraft = -ovaDraft;

            // for withdraw amount
            string wd             = txtWithdraw.Text;
            int    withdrawAmount = MoneyTransformer.TransformMoney(wd);

            // setting the new balance
            int newBalance;

            newBalance = oldBalance - withdrawAmount;

            // bool set to true for transaction to complete
            bool completeTrans = false;

            if (newBalance >= 0)
            {
                completeTrans = true;
            }
            else if (newBalance >= negOvaDraft)
            {
                completeTrans = true;
            }
            if (completeTrans)
            {
                int accNum = int.Parse(txtAccountNum.Text);

                BLLTransactionManager bllTransMngr = new BLLTransactionManager();
                bllTransMngr.WithdrawMonies(accNum, newBalance, accType);

                //Start of code to deal with transaction
                int transID             = 0;
                TransactionRecord trans = new TransactionRecord();
                trans.TransactionType    = TransactionType;
                trans.TransactionAmmount = withdrawAmount;
                trans.AccountNumber      = accNum;
                trans.Date    = DateTime.Now;
                trans.Balance = newBalance;

                bllTransMngr.CreateTransaction(trans, out transID);

                // end of transaction

                // reseting the Withdraw field to blank
                txtWithdraw.Text = "";

                // to display the new balance out to the user, ensuring "0.00"
                string displayBal = newBalance.ToString();

                if (displayBal.Count() >= 2)
                {
                    int c = displayBal.Count();
                    displayBal = displayBal.Insert((c - 2), ".");
                }
                else if (displayBal.Count() == 1)
                {
                    displayBal = "0.0" + displayBal;
                }

                // displaying the new balance to the user, before exiting the screen
                MessageBox.Show("Withdraw Complete, New Balance = €" + displayBal);

                // reseting the Current Balance
                txtCurrentBal.Text = "€" + displayBal;
            }
            else
            {
                MessageBox.Show("Insufficent funds!", "Please try again");
            }
        }//end of Withdraw money
Beispiel #2
0
        }//end of NoEdit

        //button click to deposit money
        private void btnDeposit_Click(object sender, EventArgs e)
        {
            // getting the account type
            string accType = "";

            if (rdoCurrentAcc.Checked)
            {
                accType = "current";
            }
            else if (rdoSavingsAcc.Checked)
            {
                accType = "saving";
            }

            // to get the old balance
            string ob = txtCurrentBal.Text;

            // removing the Euro Sign
            ob = ob.Replace("€", "");
            // by removing the period, the value equates to the integer value
            ob = ob.Replace(".", "");
            ob = ob.Replace(",", "");

            int oldBalance;

            oldBalance = Convert.ToInt32(ob);

            // converting the deposit amount from a string to int
            string da            = txtDeposit.Text;
            int    depositAmount = MoneyTransformer.TransformMoney(da);

            int newBalance;

            newBalance = oldBalance + depositAmount;

            int accNum = int.Parse(txtAccountNum.Text);

            BLLTransactionManager bllTransMngr = new BLLTransactionManager();

            // sending the Desposit Money through the layers
            bllTransMngr.DepositMonies(accNum, newBalance, accType);

            // Start of code to deal with transaction
            int transID             = 0;
            TransactionRecord trans = new TransactionRecord();

            trans.TransactionType    = TransactionType;
            trans.TransactionAmmount = depositAmount;
            trans.AccountNumber      = accNum;
            trans.Date    = DateTime.Now;
            trans.Balance = newBalance;

            bllTransMngr.CreateTransaction(trans, out transID);
            // end of transaction

            // reseting the Deposit field to blank
            txtDeposit.Text = String.Empty;

            // to display the new balance out to the user, ensuring "0.00"
            string displayBal = newBalance.ToString();
            int    c          = displayBal.Count();

            displayBal = displayBal.Insert((c - 2), ".");

            // displaying the new balance to the user, before exiting the screen
            MessageBox.Show("Deposit Complete, New Balance = €" + displayBal);

            // reseting the Current Balance
            txtCurrentBal.Text = "€" + displayBal;
        }//end of deposit button click
Beispiel #3
0
        }//end of event handler

        //transfer button click event to transfer money from one account to aother
        private void btnTransfer_Click(object sender, EventArgs e)
        {
            //Note that we are creatinf a transaction here in order to make sure that if something goes
            //wrong in a middle of transfering money our database stays in consistent state.
            using (TransactionScope transaction = new TransactionScope())
            {
                try
                {
                    BLLTransactionManager manager = new BLLTransactionManager();

                    //Dealing with getting monney from one acc first
                    int transferAmmount = MoneyTransformer.TransformMoney(txtAmmount.Text);

                    int debitedAccNewBal = SourceAccount.CurrentBalance - transferAmmount;

                    // new balance for credited account
                    int creditedAccNewBal = DestinationAccount.CurrentBalance + transferAmmount;

                    bool transferPossible = false;

                    // setting the possibility of transaction to true
                    if (SourceAccount.CurrentBalance >= transferAmmount)
                    {
                        transferPossible = true;
                    }
                    else
                    {
                        MessageBox.Show("Not Enough funds");
                    }


                    if (transferPossible)
                    {
                        //testing to make sure saving account doesnt transfer to external
                        if (SourceAccount.AccountType.Equals("saving"))
                        {
                            if (!ExternalTransfer)
                            {
                                manager.WithdrawMonies(SourceAccount.AccountNo, debitedAccNewBal, SourceAccount.AccountType);


                                //This code can be uncommented in order to show that database doesnt change if there was an error or exceprion somewhere
                                //Exception ex = new Exception();
                                //if (ex != null)
                                //{
                                //    MessageBox.Show("Opps SOMETHING WENT WRONG HERE !!!");
                                //}
                                //throw ex;

                                manager.DepositMonies(DestinationAccount.AccountNo, creditedAccNewBal, DestinationAccount.AccountType);

                                int debitTransNo  = 0;
                                int creditTransNo = 0;

                                //setting and creating transaction for debit
                                TransactionRecord debitTrans = new TransactionRecord();
                                debitTrans.AccountNumber      = SourceAccount.AccountNo;
                                debitTrans.TransactionType    = TransactionType.debit;
                                debitTrans.Date               = DateTime.Now;
                                debitTrans.TransactionAmmount = transferAmmount;
                                debitTrans.Balance            = debitedAccNewBal;
                                //creating a transaction for debited account
                                manager.CreateTransaction(debitTrans, out debitTransNo);


                                //setting and creating transaction for credit
                                TransactionRecord creditTrans = new TransactionRecord();
                                creditTrans.AccountNumber      = DestinationAccount.AccountNo;
                                creditTrans.TransactionType    = TransactionType.credit;
                                creditTrans.Date               = DateTime.Now;
                                creditTrans.TransactionAmmount = transferAmmount;
                                creditTrans.Balance            = creditedAccNewBal;
                                //creating a transaction for credit account
                                manager.CreateTransaction(creditTrans, out creditTransNo);


                                //Create Transfer Record object first
                                TransferRecord record = new TransferRecord();
                                record.RecepientName  = txtRecepientName.Text;
                                record.DebitedAccount = int.Parse(txtAccountNumber.Text);
                                //NOTE here I am setting the record transaction number to the number created for debited account
                                record.TransactionNumber   = debitTransNo;
                                record.DestinationSortCode = txtDestinationSortCode.Text;
                                record.DestinationAccNo    = int.Parse(txtAccOutNumber.Text);
                                record.TransferAmmount     = transferAmmount;
                                record.TransferDate        = DateTime.Now;
                                record.TransferDescription = rtfDescription.Text;


                                bool success = false;
                                //creating new transfer record
                                success = manager.CreateTransfer(record);
                                transaction.Complete();
                                transaction.Dispose();

                                if (success)
                                {
                                    MessageBox.Show("Transfer Successfull");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Cant transfer to an external account from saving account\nOnly internal transfers are allowed");
                            }
                        }
                        else
                        {
                            manager.WithdrawMonies(SourceAccount.AccountNo, debitedAccNewBal, SourceAccount.AccountType);


                            //This code can be uncommented in order to show that database doesnt change if there was an error or exceprion somewhere
                            //Exception ex = new Exception();
                            //if (ex != null)
                            //{
                            //    MessageBox.Show("Opps SOMETHING WENT WRONG HERE !!!");
                            //}
                            //throw ex;

                            manager.DepositMonies(DestinationAccount.AccountNo, creditedAccNewBal, DestinationAccount.AccountType);

                            int debitTransNo  = 0;
                            int creditTransNo = 0;

                            //setting and creating transaction for debit
                            TransactionRecord debitTrans = new TransactionRecord();
                            debitTrans.AccountNumber      = SourceAccount.AccountNo;
                            debitTrans.TransactionType    = TransactionType.debit;
                            debitTrans.Date               = DateTime.Now;
                            debitTrans.TransactionAmmount = transferAmmount;
                            debitTrans.Balance            = debitedAccNewBal;
                            //creating a transaction for debited account
                            manager.CreateTransaction(debitTrans, out debitTransNo);


                            //setting and creating transaction for credit
                            TransactionRecord creditTrans = new TransactionRecord();
                            creditTrans.AccountNumber      = DestinationAccount.AccountNo;
                            creditTrans.TransactionType    = TransactionType.credit;
                            creditTrans.Date               = DateTime.Now;
                            creditTrans.TransactionAmmount = transferAmmount;
                            creditTrans.Balance            = creditedAccNewBal;
                            //creating a transaction for credit account
                            manager.CreateTransaction(creditTrans, out creditTransNo);


                            //Create Transfer Record object first
                            TransferRecord record = new TransferRecord();
                            record.RecepientName  = txtRecepientName.Text;
                            record.DebitedAccount = int.Parse(txtAccountNumber.Text);
                            //NOTE here I am setting the record transaction number to the number created for debited account
                            record.TransactionNumber   = debitTransNo;
                            record.DestinationSortCode = txtDestinationSortCode.Text;
                            record.DestinationAccNo    = int.Parse(txtAccOutNumber.Text);
                            record.TransferAmmount     = transferAmmount;
                            record.TransferDate        = DateTime.Now;
                            record.TransferDescription = rtfDescription.Text;


                            bool success = false;
                            //creating new transfer record
                            success = manager.CreateTransfer(record);
                            transaction.Complete();
                            transaction.Dispose();

                            if (success)
                            {
                                MessageBox.Show("Transfer Successfull");
                            }
                        }
                    }
                }
                catch (TransactionException ex)
                {
                    transaction.Dispose();
                    MessageBox.Show("OOpppps somethinge went WRONG there");
                    throw ex;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No money were transfered");
                }
            }
        }//End of TransferClick