protected void btnWithdraw_Click(object sender, EventArgs e) { List <Customer> customers = Session["customers"] as List <Customer>; if (customers == null) { Page.Response.Redirect("CustomerManagement.aspx"); } if (Page.IsValid) { if (customers == null) { Page.Response.Redirect("CustomerManagement.aspx"); } int index = drpCustomer.SelectedIndex - 1; Customer customer = customers[index]; Account account = null; if (rdbAccountType.SelectedValue == "checking") { account = customer.Checking; //RangeValidator1.MaximumValue = customer.Checking.Balance.ToString(); } else { account = customer.Saving; //RangeValidator1.MaximumValue = customer.Saving.Balance.ToString(); } Transaction transaction = new Transaction(double.Parse(txtAmount.Text), TransactionType.WITHDRAW); TransactionResult result = account.Withdraw(transaction); if (result == TransactionResult.SUCCESS) { lblCheckingAccountBalance.Text = customer.Checking.Balance.ToString("C2"); lblSavingAccountBalance.Text = customer.Saving.Balance.ToString("C2"); lblConfirmation.Text = "The transaction completed and the account balance has been updated."; //txtAmount.Text = String.Empty; } else if (result == TransactionResult.INSUFFICIENT_FUND) { //RangeValidator1.IsValid = false; //txtAmount.Text = String.Empty; lblConfirmation.Text = String.Empty; CompareValidator2.IsValid = false; } else { lblConfirmation.Text = "The transaction failed: " + result.ToString(); //txtAmount.Text = String.Empty; } } }
protected void BtnDeposit_Click(object sender, EventArgs e) { //1.create a selected_customer session initialize the first deposit amount Customer selected_customer = Session["selected_customer"] as Customer; if (selected_customer == null) { return; } double amount = double.Parse(txtDepositAmount.Text);//initial deposit Transaction transaction = new Transaction(amount, Enums.TransactionType.DEPOSIT); TransactionResult result = TransactionResult.EXCEED_MAX_WITHDRAW_AMOUNT; //2.depoisit to checking or saving account if (rblDepositTo.SelectedValue == "checking") { result = selected_customer.Checking.Deposit(transaction); } else if (rblDepositTo.SelectedValue == "saving") { result = selected_customer.Saving.Deposit(transaction); } Session["selected_customer"] = selected_customer;//add to session // 3.display accounts balances lblChecking.Text = string.Format("${0}", selected_customer.Checking.Balance); // checking account balance to string lblSaving.Text = string.Format("${0}", selected_customer.Saving.Balance); //saving account balance to string lblResult.Text = result.ToString(); txtDepositAmount.Text = ""; //4. create customers session to hold all customers customers = (List <Customer>)Session["customers"]; if (customers == null) { customers = new List <Customer>(); } for (int i = 0; i < customers.Count; i++) // loop through the customers list { if (selected_customer.Id == customers[i].Id) // check if the customer is the selected_customer { // save the new values to the customers list customers[i] = selected_customer; break; } } Session["customers"] = customers; }
protected void btnTransfer_Click(object sender, EventArgs e) { List <Customer> customers = Session["customers"] as List <Customer>; if (customers == null) { Page.Response.Redirect("CustomerManagement.aspx"); } if (Page.IsValid) { if (customers == null) { Page.Response.Redirect("CustomerManagement.aspx"); } int index = drpCustomer.SelectedIndex - 1; Customer customer = customers[index]; Account account1 = null; Account account2 = null; if (rdbAccountType.SelectedValue == "checking") { account1 = customer.Checking; account2 = customer.Saving; } else { account1 = customer.Saving; account2 = customer.Checking; } Transaction withdrawTran = new Transaction(double.Parse(txtAmount.Text), TransactionType.TRANSFER_OUT); TransactionResult result = account1.Withdraw(withdrawTran); if (result == TransactionResult.SUCCESS) { Transaction depositTran = new Transaction(double.Parse(txtAmount.Text), TransactionType.TRANSFER_IN); account2.Deposit(depositTran); lblCheckingAccountBalance.Text = customer.Checking.Balance.ToString("C2"); lblSavingAccountBalance.Text = customer.Saving.Balance.ToString("C2"); lblConfirmation.Text = "The transaction completed and the account balance has been updated."; txtAmount.Text = String.Empty; } else { lblConfirmation.Text = "The transaction failed: " + result.ToString(); txtAmount.Text = String.Empty; } } }
protected void ButtonWithdraw_Click(object sender, EventArgs e) { List <Customer> customers = Session["customers"] as List <Customer>; try { int selectedCustomerIndex = DropDownListCustomerName.SelectedIndex - 1; if (RadioButtonListAccountType.SelectedIndex > -1) { if (double.Parse(TextBoxWithdrawAmount.Text) > 0) { switch (RadioButtonListAccountType.SelectedItem.Value) { case "fromCheckingAccount": Transaction transaction1 = new Transaction(double.Parse(TextBoxWithdrawAmount.Text), TransactionType.WITHDRAW); TransactionResult result1 = customers[selectedCustomerIndex].Checking.withdraw(transaction1); if (result1.ToString() == "SUCCESS") { // LabelMessage.Text = result1.ToString(); LabelResultMessage.Text = "The Transaction completed and the account balance has been updated"; } else if (result1.ToString() == "INSUFFICIENT_FUND") { LabelMessage.Text = result1.ToString(); LabelResultMessage.Text = "The Transaction failed"; } else if (result1.ToString() == "EXCEED_MAX_WITHDRAW_AMOUNT") { LabelMessage.Text = result1.ToString(); LabelResultMessage.Text = "The Transaction failed"; } break; case "fromSavingAccount": Transaction transaction2 = new Transaction(double.Parse(TextBoxWithdrawAmount.Text), TransactionType.WITHDRAW); TransactionResult result2 = customers[selectedCustomerIndex].Saving.withdraw(transaction2); if (result2.ToString() == "SUCCESS") { LabelMessage.Text = ""; LabelResultMessage.Text = "The Transaction completed and the account balance has been updated"; CompareValidatorWithdrawAmount.Text = ""; } else if (result2.ToString() == "INSUFFICIENT_FUND") { LabelMessage.Text = result2.ToString(); LabelResultMessage.Text = "The Transaction failed"; CompareValidatorWithdrawAmount.Text = ""; } else if (result2.ToString() == "EXCEED_MAX_WITHDRAW_AMOUNT") { LabelMessage.Text = result2.ToString(); LabelResultMessage.Text = "The Transaction failed"; CompareValidatorWithdrawAmount.Text = ""; } break; } } else { LabelMessage.Text = "At least 1 dollar and no more than the account balance!"; } } LabelCheckingBalance.Text = customers[selectedCustomerIndex].Checking.Balance.ToString("C2"); LabelSavingBalance.Text = customers[selectedCustomerIndex].Saving.Balance.ToString("C2"); } catch (Exception ex) { LabelIndexError.Text = ex.Message; } }
protected void ButtonTransfer_Click(object sender, EventArgs e) { try { List <Customer> customers = Session["customers"] as List <Customer>; int selectedCustomerIndex = DropDownListCustomerName.SelectedIndex - 1; if (RadioButtonListAccountType.SelectedIndex > -1) { if (double.Parse(TextBoxTransferAmount.Text) > 0) { double amount = double.Parse(TextBoxTransferAmount.Text); switch (RadioButtonListAccountType.SelectedItem.Value) { case "fromCheckingToSaving": Transaction transferOut = new Transaction(amount, TransactionType.TRANSFER_OUT); Transaction transferIn = new Transaction(amount, TransactionType.TRANSFER_IN); TransactionResult transferOutresult = customers[selectedCustomerIndex].Checking.withdraw(transferOut); LabelMessage.Text = transferOutresult.ToString(); if (transferOutresult == TransactionResult.SUCCESS) { customers[selectedCustomerIndex].Saving.deposit(transferIn); LabelMessage.Text = "The Transaction completed and the account balance has been updated"; } else if (transferOutresult == TransactionResult.INSUFFICIENT_FUND) { LabelMessage.Text = "The Transaction failed, INSUFFICIENT_FUND"; } else if (transferOutresult == TransactionResult.EXCEED_MAX_WITHDRAW_AMOUNT) { LabelMessage.Text = "The Transaction failed, EXCEED_MAX_WITHDRAW_AMOUNT"; } break; case "fromSavingToChecking": Transaction transferout = new Transaction(double.Parse(TextBoxTransferAmount.Text), TransactionType.TRANSFER_OUT); Transaction transferin = new Transaction(double.Parse(TextBoxTransferAmount.Text), TransactionType.TRANSFER_IN); TransactionResult transferOutResult = customers[selectedCustomerIndex].Saving.withdraw(transferout); LabelMessage.Text = transferOutResult.ToString(); if (transferOutResult == TransactionResult.SUCCESS) { customers[selectedCustomerIndex].Checking.deposit(transferin); LabelMessage.Text = "The Transaction completed and the account balance has been updated"; } else if (transferOutResult == TransactionResult.INSUFFICIENT_FUND) { LabelMessage.Text = "The Transaction failed, INSUFFICIENT_FUND"; } else if (transferOutResult == TransactionResult.EXCEED_MAX_WITHDRAW_AMOUNT) { LabelMessage.Text = "The Transaction failed, EXCEED_MAX_WITHDRAW_AMOUNT"; } break; } } else { LabelMessage.Text = "At least 1 dollar and no more than the account balance!"; } } LabelCheckingBalance.Text = customers[selectedCustomerIndex].Checking.Balance.ToString("C2"); LabelSavingBalance.Text = customers[selectedCustomerIndex].Saving.Balance.ToString("C2"); } catch (Exception ex) { LabelIndexErrorMessage.Text = ex.Message; } }
public void OnTransactionDone(TransactionResult _result) { log.save("Asanpardatkh Done. " + _result.ToString()); }