public SessionWithdrawPage(NavigationService navigationService) { InitializeComponent(); WithdrawAmountTextBox.Focus(); ATMSession.RestartSessionTimer(); this.navigationService = navigationService; MainWindow mainWindow = MainWindow.Instance; mainWindow.Title = "ATMSim - Withdraw"; // Get balance and show it on text block DBHelper dBHelper = new DBHelper(); double balance = dBHelper.GetBalance(ATMSession.AccountNo); if (balance >= 0) { CurrentBalanceTextBlock.Text = string.Concat("Rs. ", balance); } else { WpfMessageBox.Show("INTERNAL ERROR: Balance retireving failed", "ERROR", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error); ATMSimCommand cmd = new ATMSimCommand(CommandId.Cancel, null); Delegates.SetCancelBalancePage(CancelPage); ATMSimStateManager.AddToQueue(cmd); } // end get balance }
private void WithdrawAction(object param) { App.Current.Dispatcher.Invoke(() => { if (param == null) { ATMSession.RestartSessionTimer(); if (WithdrawAmountTextBox.Text == "") { var result = WpfMessageBox.Show("Warning", "Please enter an amount to withdraw", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); WithdrawAmountTextBox.Focus(); } } else { double amount = Double.Parse(WithdrawAmountTextBox.Text); Withdraw(amount); } } else { double amount = Double.Parse(param.ToString()); Withdraw(amount); } }); }
private void ClearButton_Click(object sender, RoutedEventArgs e) { ATMSession.RestartSessionTimer(); if (!WithdrawAmountTextBox.Text.Equals("")) { WithdrawAmountTextBox.Text = WithdrawAmountTextBox.Text.Substring(0, WithdrawAmountTextBox.Text.Length - 1); WithdrawAmountTextBox.Focus(); WithdrawAmountTextBox.Select(WithdrawAmountTextBox.Text.Length, 0); } }
private void Withdraw(double amount) { if (amount < ATMSession.MIN_WITHDRAWAL_AMOUNT) { var result = WpfMessageBox.Show("Warning", "Minimum withdrawal amount is 100.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); WithdrawAmountTextBox.SelectAll(); WithdrawAmountTextBox.Focus(); } } else if (amount % ATMSession.MULTIPLICATION_AMOUNT != 0) { var result = WpfMessageBox.Show("Warning", "Enter amount in multiplications of " + ATMSession.MULTIPLICATION_AMOUNT, MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); WithdrawAmountTextBox.SelectAll(); WithdrawAmountTextBox.Focus(); } } else { var dResult = WpfMessageBox.Show("Receipt", "Do you want to print receipt?", MessageBoxButton.YesNo, WpfMessageBox.MessageBoxImage.Question); if (dResult.Equals(MessageBoxResult.Yes)) { ATMSession.RestartSessionTimer(); _canPrintReceipt = true; } else { ATMSession.RestartSessionTimer(); _canPrintReceipt = false; } StartWithdrawing(amount); } }
/// <summary> /// Start withdrawing /// </summary> private void StartWithdrawing(double amount) { ProgressPage progressPage = new ProgressPage(); navigationService.Navigate(progressPage); var progressTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(2000) }; progressTimer.Start(); progressTimer.Tick += (_sender, args) => { DBHelper dBHelper = new DBHelper(); User user = dBHelper.GetUser(ATMSession.AccountNo); transaction = new Transaction(user.User_Id, ATMSession.AccountNo, DateTime.Now, amount); ReturnResult transactionResult = dBHelper.Withdraw(transaction); if (transactionResult == ReturnResult.Success) { ATMSession.RestartSessionTimer(); if (_canPrintReceipt) { CreateReceiptPDF(); } TransactionSuccessMsg(); } else if (transactionResult == ReturnResult.IsEmpty) { var result = WpfMessageBox.Show("Warning", "Your account balance is Rs. 0.00", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); WithdrawAmountTextBox.SelectAll(); WithdrawAmountTextBox.Focus(); } } else if (transactionResult == ReturnResult.AmountIsGreater) { var result = WpfMessageBox.Show("Warning", "Entered amount is greater than your account balance.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); WithdrawAmountTextBox.SelectAll(); WithdrawAmountTextBox.Focus(); } } else { var result = WpfMessageBox.Show("Error", "Withdrwal Error. Please contact your bank.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); WithdrawAmountTextBox.SelectAll(); WithdrawAmountTextBox.Focus(); } } navigationService.GoBack(); progressTimer.Stop(); progressTimer = null; }; }