}//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
}//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