Exemplo n.º 1
0
        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);
                    }
                }
            });
        }
Exemplo n.º 2
0
        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 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);
                }
            });
        }
Exemplo n.º 4
0
 private void CreateReceiptPDF()
 {
     try
     {
         DBHelper   dBHelper = new DBHelper();
         double     balance  = dBHelper.GetBalance(ATMSession.AccountNo);
         string     pdfName  = "RECEIPT" + ".pdf";
         FileStream fs       = new FileStream(pdfName, FileMode.Create, FileAccess.Write, FileShare.None);
         Rectangle  rec      = new Rectangle(300, 400);
         Document   doc      = new Document(rec);
         PdfWriter  writer   = PdfWriter.GetInstance(doc, fs);
         doc.Open();
         doc.Add(new Paragraph("---------------------------------------------------------"));
         doc.Add(new Paragraph("ATM SIM - RECEIPT "));
         doc.Add(new Paragraph("---------------------------------------------------------"));
         doc.Add(new Paragraph("A/C :      " + ATMSession.AccountNo));
         doc.Add(new Paragraph("\nTIMESTAMP :     " + DateTime.Now.ToString()));
         doc.Add(new Paragraph("AVAIL BAL :     Rs. " + balance));
         doc.Add(new Paragraph("\n\n\n---------------------------------------------------------"));
         doc.Add(new Paragraph("THANKS FOR USING OUR ATM."));
         doc.Add(new Paragraph("CONTACT CALL CENTRE 94 77 8601499"));
         doc.Add(new Paragraph("---------------------------------------------------------"));
         doc.Close();
         ATMSession.RestartSessionTimer();
         var result = WpfMessageBox.Show("Question", "Receipt is printed as a PDF.\nDo you want to open it?", MessageBoxButton.YesNo, WpfMessageBox.MessageBoxImage.Question);
         if (result.Equals(MessageBoxResult.Yes))
         {
             System.Diagnostics.Process.Start(@"RECEIPT.pdf");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("ERROR: " + ex.Message);
     }
 }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
 private void Transfer(string transferToAcc, double amount)
 {
     if (amount < ATMSession.MIN_TRANSFER_AMOUNT)
     {
         var result = WpfMessageBox.Show("Warning", "Minimum transfer amount is" + ATMSession.MIN_TRANSFER_AMOUNT, MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning);
         if (result.Equals(MessageBoxResult.OK))
         {
             ATMSession.RestartSessionTimer();
             TransferAmountTextBox.SelectAll();
             TransferAmountTextBox.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;
         }
         ATMSession.RestartSessionTimer();
         StartTransfering(transferToAcc, amount);
     }
 }
Exemplo n.º 7
0
 private void TimeOutOp(object param)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         if (param == null)
         {
             ATMSession.TimeOutOperation();
         }
     });
 }
Exemplo n.º 8
0
 private void SignOutOp(object param)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         if (param == null)
         {
             ATMSession.SignOut();
         }
     });
 }
 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);
     }
 }
Exemplo n.º 10
0
 private void PrintReceipt(object param)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         if (param == null)
         {
             ATMSession.RestartSessionTimer();
             ShowProgressWindow();
         }
     });
 }
Exemplo n.º 11
0
 private void CancelPage(object param)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         if (param == null)
         {
             MainWindow.Instance.DateTimeTimer.Stop();
             ATMSession.CancelCurrentOperation(navigationService);
         }
     });
 }
 private void ShowTransferPage(object param)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         if (param == null)
         {
             ATMSession.RestartSessionTimer();
             SessionTransferPage transferPage = new SessionTransferPage(_navigationService);
             _navigationService.Navigate(transferPage);
         }
     });
 }
 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);
     }
 }
Exemplo n.º 14
0
        // try to authenticate
        private void Authenticate(object param)
        {
            App.Current.Dispatcher.Invoke(() =>
            {
                if (param == null)
                {
                    if (AccountNoTextBox.IsVisible)
                    {
                        if (!_accNo.Equals("") && !_password.Equals(""))
                        {
                            DBHelper dBHelper = new DBHelper();
                            if (dBHelper.CheckAccountNo(_accNo))
                            {
                                if (PinTryOuts <= _maxPinTryouts)
                                {
                                    if (dBHelper.VerifyPin(_accNo, _password))
                                    {
                                        ATMSimCommand cmd = new ATMSimCommand(CommandId.AuthenticationSuccess, null);
                                        Delegates.SetShowSessionPage(ShowSessionPage);
                                        ATMSimStateManager.AddToQueue(cmd);
                                        MainWindow.Instance.IsEnabled = true;
                                    }
                                    else
                                    {
                                        var messageBoxResult = WpfMessageBox.Show("Error", "PIN verification failed", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error);
                                        if (messageBoxResult != MessageBoxResult.OK)
                                        {
                                            return;
                                        }
                                        PinPasswordBox.SelectAll();
                                        PinPasswordBox.Focus();

                                        ATMSimCommand cmd;
                                        if (PinTryOuts < _maxPinTryouts)
                                        {
                                            cmd = new ATMSimCommand(CommandId.AuthenticationFailure, this);
                                            ATMSimStateManager.AddToQueue(cmd);
                                        }
                                        else if (PinTryOuts == _maxPinTryouts)
                                        {
                                            cmd = new ATMSimCommand(CommandId.PinVerificationFailure, this);
                                            ATMSimStateManager.AddToQueue(cmd);
                                            MainWindow.Instance.IsEnabled = true;
                                            this.Close();
                                        }

                                        PinTryOuts++;
                                    }
                                }
                            }
                            else
                            {
                                var messageBoxResult = WpfMessageBox.Show("Error", "Invalid account number.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error);
                                if (messageBoxResult != MessageBoxResult.OK)
                                {
                                    return;
                                }
                                PinPasswordBox.Password = "";
                                AccountNoTextBox.SelectAll();
                                AccountNoTextBox.Focus();
                                ATMSimCommand cmd = new ATMSimCommand(CommandId.AuthenticationFailure, this);
                                ATMSimStateManager.AddToQueue(cmd);
                            }
                        }
                        else
                        {
                            var messageBoxResult = WpfMessageBox.Show("Warning", "Please fill all fields", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning);
                            ATMSimCommand cmd    = new ATMSimCommand(CommandId.AuthenticationFailure, this);
                            ATMSimStateManager.AddToQueue(cmd);
                            AccountNoTextBox.Focus();
                        }
                    }
                    else
                    {
                        if (!PinPasswordBox.Password.Equals(""))
                        {
                            if (PinTryOuts <= _maxPinTryouts)
                            {
                                if (PinPasswordBox.Password.Equals("1234"))
                                {
                                    this.DialogResult    = true;
                                    ATMSession.AccountNo = AccountNoTextBox.Text;
                                    this.Close();
                                }
                                else
                                {
                                    var messageBoxResult = WpfMessageBox.Show("Error", "PIN verification failed", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error);
                                    if (messageBoxResult != MessageBoxResult.OK)
                                    {
                                        return;
                                    }
                                    if (PinTryOuts == _maxPinTryouts)
                                    {
                                        this.Close();
                                        ATMSession.SignOut();
                                    }
                                    PinTryOuts++;
                                    PinPasswordBox.Focus();
                                }
                            }
                            else
                            {
                                this.Close();
                            }
                        }
                        else
                        {
                            var messageBoxResult = WpfMessageBox.Show("Warning", "Please enter your PIN", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning);
                            PinPasswordBox.Focus();
                        }
                    }
                }
            });
        }
 private void WithdrawAmountTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     ATMSession.RestartSessionTimer();
 }
Exemplo n.º 16
0
 private void BackToMainButton_Click(object sender, RoutedEventArgs e)
 {
     ATMSession.CancelCurrentOperation(_navigationService);
 }
Exemplo n.º 17
0
 private void TransferAmountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
 {
     ATMSession.RestartSessionTimer();
     e.Handled = !ValidationController.AreAllValidNumericChars(e.Text);
     base.OnPreviewTextInput(e);
 }
Exemplo n.º 18
0
 private void SignOutButton_Click(object sender, RoutedEventArgs e)
 {
     ATMSession.SignOut();
 }
Exemplo n.º 19
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;
                }
            };
        }