public SessionTransferPage(NavigationService navigationService) { InitializeComponent(); TransferAccountTextBox.Focus(); ATMSession.RestartSessionTimer(); this._navigationService = navigationService; MainWindow mainWindow = MainWindow.Instance; mainWindow.Title = "ATMSim -Transfer"; // Get balance and show it on text block DBHelper dBHelper = new DBHelper(); double balance = dBHelper.GetBalance(ATMSession.AccountNo); if (balance >= 0) { BalanceTextBlock.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 TransferAction(object param) { App.Current.Dispatcher.Invoke(() => { if (param == null) { ATMSession.RestartSessionTimer(); if (TransferAccountTextBox.Text == "") { var result = WpfMessageBox.Show("Warning", "Please enter an account to transfer", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAccountTextBox.Focus(); } } else if (TransferAmountTextBox.Text == "") { var result = WpfMessageBox.Show("Warning", "Please enter an amount to transfer", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAmountTextBox.Focus(); } } else { double amount = Double.Parse(TransferAmountTextBox.Text); string transferToAcc = TransferAccountTextBox.Text; Transfer(transferToAcc, amount); } } }); }
private void ClearButton_Click(object sender, RoutedEventArgs e) { ATMSession.RestartSessionTimer(); if (_focusedTextBox.Equals("account")) { ATMSession.RestartSessionTimer(); if (!TransferAccountTextBox.Text.Equals("")) { TransferAccountTextBox.Text = TransferAccountTextBox.Text.Substring(0, TransferAccountTextBox.Text.Length - 1); TransferAccountTextBox.Focus(); TransferAccountTextBox.Select(TransferAccountTextBox.Text.Length, 0); } } if (_focusedTextBox.Equals("amount")) { ATMSession.RestartSessionTimer(); if (!TransferAmountTextBox.Text.Equals("")) { TransferAmountTextBox.Text = TransferAmountTextBox.Text.Substring(0, TransferAmountTextBox.Text.Length - 1); TransferAmountTextBox.Focus(); TransferAmountTextBox.Select(TransferAmountTextBox.Text.Length, 0); } } }
private void StartTransfering(string transferToAcc, 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(); bool transferToAccIsValid = dBHelper.CheckAccountNo(transferToAcc); if (transferToAccIsValid) { User user = dBHelper.GetUser(ATMSession.AccountNo); transaction = new Transaction(user.User_Id, ATMSession.AccountNo, DateTime.Now, amount, transferToAcc); ReturnResult transactionResult = dBHelper.Transfer(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(); TransferAmountTextBox.SelectAll(); TransferAmountTextBox.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(); TransferAmountTextBox.SelectAll(); TransferAmountTextBox.Focus(); } } else { var result = WpfMessageBox.Show("Error", "Transfer Error. Please contact your bank.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAmountTextBox.SelectAll(); TransferAmountTextBox.Focus(); } } _navigationService.GoBack(); progressTimer.Stop(); progressTimer = null; } else { var result = WpfMessageBox.Show("Error", "Transfer to account is not a valid account.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAccountTextBox.SelectAll(); TransferAccountTextBox.Focus(); } _navigationService.GoBack(); progressTimer.Stop(); progressTimer = null; } }; }