Esempio n. 1
0
        private void WithdrawHandler()
        {
            int[]  quickMoneySet = { 10, 20, 50, 100, 200, 500 };
            double balance       = User.GetBalance();

            int n;

            if (int.TryParse(input, out n))
            {
                if (n == 7)
                {
                    User.SetBalanceInput("");
                    WindowSwitcher.OpenAdvWithdrawWindow();
                    return;
                }
                int amount = quickMoneySet[n - 1];
                if (balance < amount)
                {
                    return;
                }
                User.SetBalanceInput(quickMoneySet[n - 1] + "");
            }

            if (User.GetBalanceInput().Length != 0)
            {
                WindowSwitcher.OpenReceiptWindow();
            }
        }
Esempio n. 2
0
        public void LetterCancel()
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                Window w = WindowSwitcher.GetActiveWindow();

                if (WindowInBlacklist(w, abort_blacklist))
                {
                    return;
                }

                WindowSwitcher.OpenClosing();
                WindowSwitcher.Closing.Show();
                User.inputBlocked = true;
                User.ClearUser();

                Thread thread = new Thread(() =>
                {
                    Thread.Sleep(2000);

                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        WindowSwitcher.ResetUserState();
                        User.inputBlocked = false;
                    }));
                });
                thread.Start();
            }));
        }
Esempio n. 3
0
        //TODO: (Damian) Zo veel mogelijk copy-pasta verwijderen (aka. de input.Equals in eigen methode)

        private void ChoiceHandler()
        {
            if (input.Equals("1"))
            {
                WindowSwitcher.OpenBalanceWindow();
            }

            else if (input.Equals("2"))
            {
                WindowSwitcher.OpenWithdrawWindow();
            }

            else if (input.Equals("3"))
            {
                if (!BillHandler.isWithdrawable(70))
                {
                    return;
                }
                else
                {
                    User.SetBalanceInput("70");
                    User.SetReceipt(false);
                    WindowSwitcher.OpenConfirm();
                }
            }
        }
        //s.Replace(Environment.NewLine, "");

        private void TagHandler(string tag)
        {
            User.SetTag(tag);
            WindowSwitcher.OpenPinWindow();

            //PinWindow pw = new PinWindow();
            //pw.Show();
        }
Esempio n. 5
0
        private String WebHandle(String syntax, Boolean silent)
        {
            string html       = string.Empty;
            String url_prefix = "https://api.bank.thomasvt.xyz/oldapi?";
            //String url_prefix = "http://localhost:9010/oldapi?";

            String url = @url_prefix + syntax;

            if (!silent)
            {
                Console.WriteLine(User.GetTag());
            }

            //GetKey()
            url = url.Replace("{user}", User.GetTag()).Replace("{pin}", GetEncryptedPin()).Replace("{key}", GetKey());

            Console.WriteLine("Request to: " + url);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.AutomaticDecompression = DecompressionMethods.GZip;

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            html = reader.ReadToEnd();
                        }
            } catch (Exception e)
            {
                html = ErrorJson(e);
            }
            if (!silent)
            {
                Console.WriteLine("Response: " + html);
            }

            if (html.Contains("BAD KEY"))
            {
                if (tries > 10)
                {
                    User.SetError("Veilige verbinding met SOFA niet gelukt");
                    WindowSwitcher.OpenErrorOccurredWindow();
                    return(html);
                }
                tries++;
                Thread.Sleep(100);
                Console.WriteLine("ERROR WITH KEY - TRY: " + tries);
                return(WebHandle(syntax, silent));
            }
            tries = 0;
            return(html);
        }
Esempio n. 6
0
 private void FinalAction()
 {
     if (User.GetTag().Length == 0)
     {
         WindowSwitcher.ResetUserState();
         User.ClearUser();
     }
     else
     {
         WindowSwitcher.UserToChoice();
     }
 }
Esempio n. 7
0
        private void ReceiptHandler()
        {
            if (input.Equals("1"))
            {
                User.SetReceipt(true);
            }
            else if (input.Equals("2"))
            {
                User.SetReceipt(false);
            }

            if (input.Equals("1") || input.Equals("2"))
            {
                WindowSwitcher.OpenConfirm();
            }
        }
Esempio n. 8
0
        public void LetterBack()
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                Window w = WindowSwitcher.GetActiveWindow();

                if (WindowInBlacklist(w, back_blacklist))
                {
                    return;
                }

                if (w != null)
                {
                    w.Close();
                }
            }));
        }
Esempio n. 9
0
        private void ConfirmHandler()
        {
            if (!User.GetWaitingForCard())
            {
                return;
            }

            if (User.GetBalanceInput() == null)
            {
                return;
            }
            if (User.GetBalanceInput().Length == 0)
            {
                return;
            }

            WindowSwitcher.OpenPleaseWaitWindow();
            double  amount   = Double.Parse(User.GetBalanceInput());
            JObject response = new WebHandler().WithdrawMoney(amount);

            if (response.GetValue("response") == null)
            {
                if (response.GetValue("error") != null)
                {
                    String error = response.GetValue("error").ToString();
                    User.SetError(error);
                    WindowSwitcher.OpenErrorOccurredWindow();
                    return;
                }
            }
            JObject x = (JObject)response.GetValue("transaction");

            if ((Boolean)x.GetValue("success"))
            {
                WindowSwitcher.OpenThanksGoodbyeWindow();
                if (User.GetReceipt())
                {
                    new PrintHandler().Print();
                }
                //PlayThanks();
            }
            Console.WriteLine(response.ToString());
        }
Esempio n. 10
0
        void PinWindowHandler()
        {
            int checkAlsGetal;

            if (int.TryParse(input, out checkAlsGetal))
            {
                if (User.GetPin().Length != 4)
                {
                    User.SetPin(User.GetPin() + input);
                }
            }

            if (input.Equals("*"))
            {
                if (User.GetPin().Length != 0)
                {
                    User.SetPin(User.GetPin().Substring(0, User.GetPin().Length - 1));
                }
            }

            UpdatePinProgress();

            if (input.Equals("#"))
            {
                if (User.GetPin().Length != 4)
                {
                    return;
                }

                JObject json = new WebHandler().GetBalance();


                if (json.GetValue("error") != null)
                {
                    UpdatePinProgress(Colors.Red);

                    User.SetPin("");

                    String error = ((String )json.GetValue("error")).ToLower();


                    if (error.Equals("pin incorrect"))
                    {
                        int triesremaining = 3 - ((int)json.GetValue("tries"));

                        WindowSwitcher.PinWindow.ERROR.Content = ("Nog X poging(en) over").Replace("X", triesremaining + "");
                    }

                    if (error.Equals("card blocked"))
                    {
                        WindowSwitcher.PinWindow.ERROR.Content = "Uw pas is geblokeerd, neem aub contact op";

                        Thread thread = new Thread(() =>
                        {
                            Thread.Sleep(5000);
                            WindowSwitcher.OpenThanksGoodbyeWindow();
                        });
                        //thread.SetApartmentState(ApartmentState.STA);
                        thread.Start();
                    }


                    WindowSwitcher.PinWindow.ERROR.Visibility = Visibility.Visible;
                }
                else
                {
                    Thread thread = new Thread(() =>
                    {
                        UpdatePinProgress(Colors.Green);
                        Thread.Sleep(5000);
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            WindowSwitcher.PinWindow.ERROR.Visibility = Visibility.Hidden;
                            WindowSwitcher.OpenChoice();
                            WindowSwitcher.Choice.Show();
                        }));
                    });
                    //thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                }
            }
        }
Esempio n. 11
0
        private void TagHandler(string tag)
        {
            if (User.GetTag().Length != 0)
            {
                if (User.GetTag().Equals(tag))
                {
                    InputHandler("TAG CHECK OK");
                }
                Console.WriteLine("SAME TAG PRESENTED");

                Application.Current.Dispatcher.Invoke(new Action(() => {
                    if (WindowSwitcher.GetActiveWindow().Title.Equals("MainWindow"))
                    {
                        User.SetTag("");
                    }
                }));
                return;
            }

            User.SetTag(tag);
            Console.WriteLine("TAG: " + tag);

            JObject json = new WebHandler().GetCardValid();

            if (json.GetValue("error") != null)
            {
                Console.WriteLine("Connection error!");
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    new NoNetwork().Show();
                }));

                return;
            }


            Boolean cardExists = (Boolean)json.GetValue("exists");

            if (!cardExists)
            {
                User.SetError("Deze kaart komt niet voor in onze database");
                WindowSwitcher.OpenErrorOccurredWindow();
                User.SetTag("");
                return;
            }

            WindowSwitcher.OpenPinWindow();

            int tries = (int)json.GetValue("tries");

            if (tries == 3)
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    WindowSwitcher.PinWindow.ERROR.Content    = "Uw pas is geblokeerd, neem zo snel mogelijk contact op";
                    WindowSwitcher.PinWindow.ERROR.Visibility = Visibility.Visible;
                    User.inputBlocked = true;
                }));


                Thread thread = new Thread(() =>
                {
                    Thread.Sleep(5000);
                    WindowSwitcher.OpenThanksGoodbyeWindow();
                });
                //thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }

            else if (tries != 0)
            {
                UpdateTries(3 - tries);
            }
        }
Esempio n. 12
0
        private void AdvWithdrawHandler()
        {
            String userInput = User.GetBalanceInput();

            if (input.Equals("*"))
            {
                if (User.GetBalanceInput().Length != 0)
                {
                    User.SetBalanceInput(User.GetBalanceInput().Substring(0, User.GetBalanceInput().Length - 1));
                }
            }

            else if (input.Equals("#"))
            {
                double money      = User.GetBalance();
                int    inputMoney = int.Parse(userInput);

                if (!isWithdrawable(inputMoney))
                {
                    Console.WriteLine("eror komt voor");
                    WindowSwitcher.AdvWithdrawWindow.ERROR.Content    = "Dit bedrag is niet in biljetten beschikbaar in deze bankautomaat.";
                    WindowSwitcher.AdvWithdrawWindow.ERROR.Visibility = Visibility.Visible;
                    User.inputBlocked = true;
                    Thread thread = new Thread(() =>
                    {
                        Thread.Sleep(5000);
                        User.inputBlocked = false;

                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            WindowSwitcher.OpenWithdrawWindow();
                            User.SetBalanceInput("");
                            WindowSwitcher.AdvWithdrawWindow.InputLabel.Content = "";
                            WindowSwitcher.AdvWithdrawWindow.ERROR.Visibility   = Visibility.Hidden;
                        }));
                    });
                    thread.Start();
                    return;
                }


                if (inputMoney > money)
                {
                    Console.WriteLine("Balance too low!");
                    WindowSwitcher.AdvWithdrawWindow.ERROR.Content    = "Uw saldo is te laag om dit bedrag te pinnen";
                    WindowSwitcher.AdvWithdrawWindow.ERROR.Visibility = Visibility.Visible;
                    User.inputBlocked = true;

                    Thread thread = new Thread(() =>
                    {
                        Thread.Sleep(5000);
                        User.inputBlocked = false;

                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            User.SetBalanceInput("");
                            WindowSwitcher.AdvWithdrawWindow.InputLabel.Content = "";
                            WindowSwitcher.AdvWithdrawWindow.ERROR.Visibility   = Visibility.Hidden;
                        }));
                    });
                    thread.Start();
                }
                else //There is enough money to proceed the transaction
                {
                    if (IsMultipleOfTen(inputMoney))
                    {
                        WindowSwitcher.OpenReceiptWindow();
                    }

                    else
                    {
                        WindowSwitcher.AdvWithdrawWindow.ERROR.Content    = "Dit is een ongeldig bedrag, voer een veelvoud van 10 in";
                        WindowSwitcher.AdvWithdrawWindow.ERROR.Visibility = Visibility.Visible;
                        User.inputBlocked = true;

                        Thread thread = new Thread(() =>
                        {
                            Thread.Sleep(5000);
                            User.inputBlocked = false;

                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                User.SetBalanceInput("");
                                WindowSwitcher.AdvWithdrawWindow.InputLabel.Content = "";
                                WindowSwitcher.AdvWithdrawWindow.ERROR.Visibility   = Visibility.Hidden;
                            }));
                        });
                        thread.Start();
                    }
                }
            }

            int checkAlsGetal;

            if (int.TryParse(input, out checkAlsGetal))
            {
                User.SetBalanceInput(User.GetBalanceInput() + input);
            }

            WindowSwitcher.AdvWithdrawWindow.InputLabel.Content = User.GetBalanceInput();
        }
 private void FinalAction()
 {
     WindowSwitcher.ResetUserState();
     User.ClearUser();
 }