/// <summary> /// Method to deal with link process click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lnkProcess_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { ServiceReference1.TransactionManagerClient transactionManager = new ServiceReference1.TransactionManagerClient(); decimal valueInput; if (!decimal.TryParse(txtAmount.Text, out valueInput)) { MessageBox.Show("Amount cannot contain letters or special characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { long accNumber = this.constructorData.bankAccount.AccountNumber; double amount = double.Parse(txtAmount.Text); BankAccount bankAccount = db.BankAccounts.Where(x => x.AccountNumber == accNumber).SingleOrDefault(); int acctId = bankAccount.BankAccountId; if (cbTransType.SelectedValue.ToString() == "Deposit") { double?returnValue = transactionManager.Deposit(acctId, amount, "Deposit"); confirmTransaction(returnValue, "Deposit"); } else { if (amount > this.constructorData.bankAccount.Balance) { MessageBox.Show("Not sufficient balance."); } else { //When billpayment is selected, call billpayment mehtod of the web service. if (cbTransType.SelectedValue.ToString() == "Bill Payment") { double?returnValue = transactionManager.BillPayment(acctId, amount, "Bill Payment to " + cboAccountPayee.Text); confirmTransaction(returnValue, "Bill Payment"); } //When transfer is selected, call transfer mehtod of the web service. if (cbTransType.SelectedValue.ToString() == "Transfer") { double?returnValue = transactionManager.Transfer(acctId, int.Parse(cboAccountPayee.SelectedValue.ToString()), amount, "Transfer"); confirmTransaction(returnValue, "Transfer"); } if (cbTransType.SelectedValue.ToString() == "Withdrawal") { double?returnValue = transactionManager.Withdrawal(acctId, amount, "Withdrawal"); confirmTransaction(returnValue, "Withdrawal"); } } } } }
/// <summary> /// Process transaction /// </summary> /// <param name="transactionRecords">represent a collection of transaction records fro0m xml fileoo</param> private void processTransactions(IEnumerable <XElement> transactionRecords) { ServiceReference1.TransactionManagerClient transactionManager = new ServiceReference1.TransactionManagerClient(); double?balance = null; foreach (XElement xele in transactionRecords) { int xAccountNo = int.Parse(xele.Element("account_no").Value); //BankAccount bankAccount = (from result in db.BankAccounts // where result.AccountNumber == xAccountNo // select result).SingleOrDefault(); BankAccount bankAccount = db.BankAccounts.Where(x => x.AccountNumber == xAccountNo).SingleOrDefault(); int xAccountId = bankAccount.BankAccountId; string xNotes = xele.Element("notes").Value; if (int.Parse(xele.Element("type").Value) == 2) { double xAmount = double.Parse(xele.Element("amount").Value); balance = transactionManager.Withdrawal(xAccountId, xAmount, xNotes); if (balance != null) { logData += "Transaction Completed Successfully: Withdrawal " + xAmount.ToString("C") + " from account " + xAccountNo.ToString() + "\r\n"; } else { logData += "Transaction Withdrawal Unsuccessful: " + "\r\n"; } } else if (int.Parse(xele.Element("type").Value) == 6) { balance = transactionManager.CalculateInterest(xAccountId, xNotes); logData += "Calculate Interest successfully: " + "\r\n"; } } }