Пример #1
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);
     }
 }
Пример #2
0
        private void TransactionSuccessMsg()
        {
            DBHelper dBHelper        = new DBHelper();
            double   balance         = dBHelper.GetBalance(ATMSession.AccountNo);
            string   transSuccessMsg = "Transaction is successfull \n" +
                                       "\nAccount No: " + ATMSession.AccountNo +
                                       "\nWithdrawal amount: Rs. " + transaction.Amount +
                                       "\nTimestamp: " + DateTime.Now.ToString() +
                                       "\nAvailable balance: Rs. " + balance +
                                       "\n\nDo you need to do another transaction?";
            var result = WpfMessageBox.Show("Information", transSuccessMsg, MessageBoxButton.YesNo, WpfMessageBox.MessageBoxImage.Information);

            if (result.Equals(MessageBoxResult.Yes))
            {
                // change state to cancel
                ATMSimCommand cmd = new ATMSimCommand(CommandId.Cancel, null);
                Delegates.SetCancelTransferPage(CancelPage);
                ATMSimStateManager.AddToQueue(cmd);
            }
            if (result.Equals(MessageBoxResult.No))
            {
                ATMSimCommand cmd = new ATMSimCommand(CommandId.SignOut, null);
                Delegates.SetSignOutOp(SignOutOp);
                ATMSimStateManager.AddToQueue(cmd);
            }
        }
Пример #3
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
        }
Пример #4
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);
     }
 }
Пример #5
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);
                    }
                }
            });
        }
        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 Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender == btnOk)
            {
                _result = MessageBoxResult.OK;
            }
            else if (sender == btnYes)
            {
                _result = MessageBoxResult.Yes;
            }
            else if (sender == btnNo)
            {
                _result = MessageBoxResult.No;
            }
            else if (sender == btnCancel)
            {
                _result = MessageBoxResult.Cancel;
            }
            else
            {
                _result = MessageBoxResult.None;
            }

            if (_messageBox != null)
            {
                _messageBox.Close();
            }
            _messageBox = null;
        }
 public static MessageBoxResult Show(string caption, string text, MessageBoxButton button, MessageBoxImage image)
 {
     _messageBox = new WpfMessageBox {
         txtMsg = { Text = text }, MessageTitle = { Text = caption }
     };
     SetVisibilityOfButtons(button);
     SetImageOfMessageBox(image);
     _messageBox.ShowDialog();
     return(_result);
 }
Пример #9
0
        /// <summary>
        /// Sign out from the current ATM session
        /// </summary>
        public static void SignOut()
        {
            count = 0;
            SessionTimer.Stop();
            var result = WpfMessageBox.Show("Information", "Please take out your card", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning);

            if (result.Equals(MessageBoxResult.OK))
            {
                EndSesion();
            }
        }
Пример #10
0
        /// <summary>
        /// Timeout operation
        /// </summary>
        public static void TimeOutOperation()
        {
            count = 0;
            SessionTimer.Stop();

            string message = "Your session ended due to exceeding the timeout. Please take out your card.";
            var    result  = WpfMessageBox.Show("Warning", message, MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning);

            if (result.Equals(MessageBoxResult.OK))
            {
                EndSesion();
            }
        }
 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);
     }
 }
Пример #12
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();
                        }
                    }
                }
            });
        }
Пример #13
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;
                }
            };
        }