Example #1
0
        //Functions only applicable to the admin class


        // View other members accounts
        internal void ShowMember()
        {
            string Type = "View Balance of";

            Console.CursorVisible = false;
            string Selection = "";

            Console.Clear();
            if (Users.Count == 1 && Users[0] == "Error")
            {
                Inter.Logger(false, Type, "-", 0, DateTime.Now, 0);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n\t\tUnable to procceed. Transaction failed.\n");
                Console.ResetColor();
                Console.Write("\nPlease try again later, press any key to continue...");
                Console.ReadKey();
                return;
            }
            ;
            Users.RemoveAll(x => x == Inter.UserName);
            string messa = "Please select the name of the user you would like to check";

            while (Selection.Length == 0)
            {
                Selection = BuildMenu(Users, messa);
            }
            Tuple <DateTime, decimal> result = new Tuple <DateTime, decimal>(DateTime.Now, -1);

            result = Inter.GetBalance(Selection, true);
            Console.Clear();
            if (result.Item2 == -1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("\n\t\tUnable to retrieve account balance. Transaction Failed.\n");
                Console.ResetColor();
                Console.Write("\nPress any key to continue...");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("\nAccount balance ");
                Console.ResetColor();
                Console.Write($"for user: {Selection} on {DateTime.Now.ToString(Culture)} is {result.Item2.ToString("c", Culture)}\n\nPress any key to continue...");
            }
            Console.ReadKey();
        }
Example #2
0
        // Withdraw from accounts

        internal void Withdraw()
        {
            string Type = "Withdraw from";

            Index = 0;
            string  with;
            decimal withdraw;
            decimal amount;
            string  Selection = "";

            Console.Clear();
            Console.CursorVisible = false;
            Users.RemoveAll(x => x == Inter.UserName);
            if (Users.Count == 1 && Users[0] == "Error")
            {
                Inter.Logger(false, Type, "-", 0, DateTime.Now, 0);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n\n\t\tUnable to perform this request. Transaction failed.");
                Console.ResetColor();
                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey();
                return;
            }
            ;
            string messa = "Please select the name of the user you would like to withdraw from:";

            while (Selection.Length == 0)
            {
                Selection = BuildMenu(Users, messa);
            }
            amount = Inter.GetBalance(Selection, false).Item2;
            if (amount == -1)
            {
                Inter.Logger(false, Type, "-", 0, DateTime.Now, 0);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n\n\t\tUnable to perform this request. Transaction failed.");
                Console.ResetColor();
                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey();
                return;
            }
            Console.TreatControlCAsInput = false;
            Console.WriteLine($"\nYou have selected: {Selection}");
            Console.Write($"\nThe available founds at your disposal are {amount}\n");
            Console.CursorVisible = true;
            Console.Write("\nNow enter the amount you would like to withdraw: ");
            with = Console.ReadLine();
            bool chec = Decimal.TryParse(with, out withdraw);
            int  n    = 0;

            while (!chec || (withdraw > amount) || (withdraw <= 0))
            {
                if (!chec)
                {
                    n++;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("\nWarning: ");
                    Console.ResetColor();
                    Console.Write("You did not enter a number.\n");
                    if (n == 3)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Three erroneous imputs. ");
                        Console.ResetColor();
                        Console.Write("Returning to main menu.\nPress any key to continue...");
                        Console.ReadKey();
                        Console.CursorVisible = false;
                        return;
                    }
                    else
                    {
                        Console.Write("You can stop this transaction by pressing ");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("q");
                        Console.ResetColor();
                        Console.Write(" or press any key to try again.\n");
                    }
                    Console.CursorVisible = false;
                    ConsoleKeyInfo key;
                    key = Console.ReadKey(true);
                    if (key.KeyChar == 'Q' || key.KeyChar == 'q')
                    {
                        return;
                    }
                    Console.CursorVisible = true;
                    Console.Write("\nYou chose to try again.\nPlease enter the amount you would like to withdraw: ");
                    with = Console.ReadLine();
                    chec = Decimal.TryParse(with, out withdraw);
                }
                if (withdraw > amount)
                {
                    n++;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("\nWarning: ");
                    Console.ResetColor();
                    Console.Write("You do not have sufficient founds to complete this transaction.\n");
                    if (n == 3)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Three erroneous imputs. ");
                        Console.ResetColor();
                        Console.Write("Returning to main menu.\nPress any key to continue...");
                        Console.ReadKey();
                        Console.CursorVisible = false;
                        return;
                    }
                    else
                    {
                        Console.Write("You can stop this transaction by pressing ");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("q");
                        Console.ResetColor();
                        Console.Write(" or press any key to try again.\n");
                    }
                    Console.CursorVisible = false;
                    ConsoleKeyInfo key;
                    key = Console.ReadKey(true);
                    if (key.KeyChar == 'Q' || key.KeyChar == 'q')
                    {
                        return;
                    }
                    Console.CursorVisible = true;
                    Console.Write($"\nYou chose to try again.\nPlease try again using a different amount which must be less than {amount}: ");
                    with = Console.ReadLine();
                    chec = Decimal.TryParse(with, out withdraw);
                }
                if (withdraw <= 0)
                {
                    n++;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("\nWarning: ");
                    Console.ResetColor();
                    Console.Write("You may not use zero or a negative number. \n");
                    if (n == 3)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Three erroneous imputs. ");
                        Console.ResetColor();
                        Console.Write("Returning to main menu.\nPress any key to continue...");
                        Console.ReadKey();
                        Console.CursorVisible = false;
                        return;
                    }
                    else
                    {
                        Console.Write("You can stop this transaction by pressing ");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("q");
                        Console.ResetColor();
                        Console.Write(" or press any key to try again.\n");
                    }
                    Console.CursorVisible = false;
                    ConsoleKeyInfo key;
                    key = Console.ReadKey(true);
                    if (key.KeyChar == 'Q' || key.KeyChar == 'q')
                    {
                        return;
                    }
                    Console.CursorVisible = true;
                    Console.Write($"\nYou chose to try again.\nPlease try again using a different amount \nwhich must be less than {amount.ToString("c", Culture)}: ");
                    with = Console.ReadLine();
                    chec = Decimal.TryParse(with, out withdraw);
                }
            }
            Tuple <bool, decimal, decimal, DateTime> success = Inter.Withdraw(Selection, withdraw);

            if (success.Item1)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("\n\t\tTransaction completed successfuly");
                Console.ResetColor();
                Console.Write(" on {0}.\n\t\t   Your current balance is {1} ", success.Item4.ToString(Culture), success.Item3.ToString(Culture));
                Console.Write("\n\nPress any key to continue...");
            }
            else
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("\n\t\tTransaction Failed");
                Console.ResetColor();
                Console.Write(" on {0}. \n\nPress any key to continue...", success.Item4.ToString(Culture));
            }
            Console.CursorVisible = false;
            Console.ReadKey();
        }