示例#1
0
        /* CheckTransactionHistory()
         *   Fetches account transaction records for user to view
         *
         *   Returns: Status string with results of attempted view
         */
        static string CheckTransactionHistory(string user, string pass)
        {
            string[] history = { };

            if (!DBAct.TransactionHistory(user, pass, ref history))
            {
                return("Error: Could not retrieve history");
            }

            return(ViewTransactions(user, history));
        }
示例#2
0
        /* CheckBalance()
         *   Checks the account balance for the user.
         *
         *   Returns: Status string with the user's balance, or an error
         */
        static string CheckBalance(string user, string pass)
        {
            decimal balance = -999999999;

            if (!DBAct.GetBalance(user, pass, ref balance))
            {
                return("Error: Could not retrieve balance.");
            }

            return("Your balance is $" + balance.ToString("0.00") + ".");
        }
示例#3
0
        /*** User actions ***/

        /* CreateAccount()
         *   Gets username, password, and password verification from user to create a
         *   new account.
         *
         *   Returns: Status string with results of attempted account creation
         */
        static string CreateAccount()
        {
            string pass, passVerify, username, status = "Creating new account.";

            while (true)
            {
                ScreenRefresh(null, status);
                Console.WriteLine("Please enter desired username (or type \"cancel\" to return):");
                username = Console.ReadLine();

                if (username == "")
                {
                    status = "Error: Cannot create account with blank username.";
                    continue;
                }
                if (username.ToLower() == "cancel" || username.ToLower() == "\"cancel\"")
                {
                    return("Account creation cancelled.");
                }
                if (DBAct.DoesUserExist(username))
                {
                    status = "Error: Account name \"" + username + "\" taken.";
                    continue;
                }

                Console.WriteLine("Please enter password (will stay hidden):");
                pass = GetPasswordInput();
                Console.WriteLine("Please verify password:"******"New account \"" + username + "\" created.");
                    }
                    else
                    {
                        return("Error creating account.");
                    }
                }
                else
                {
                    status = "Password mismatch. New account not created.";
                }
            }
        }
示例#4
0
        /* Withdrawal()
         *   Gets amount from user, checks that money is available, confirms amount with
         *   user, and withdraws the specified amount from the account.
         *
         *   Returns: Status string with results of the attempted withdrawal
         */
        static string Withdrawal(string user, string pass)
        {
            string  amountInput;
            decimal amountNum, balance = 0;

            DBAct.GetBalance(user, pass, ref balance);

            ScreenRefresh(user, "Making withdrawal.");
            Console.WriteLine("Please enter amount to withdraw (ex: 3500.00 or 3500), or \"Q\" to return.");
            Console.WriteLine("Current balance: {0:0.00}", balance);
            amountInput = Console.ReadLine();

            if (amountInput.ToLower() == "q")
            {
                return("Withdrawal cancelled.");
            }
            if (!IsMoneyAmountFormatted(amountInput))
            {
                return("Error: Incorrectly formatted amount.");
            }
            amountNum = Convert.ToDecimal("-" + amountInput);             //Withdrawals are negative when stored

            if (balance + amountNum < 0)
            {
                return("Error: Insufficient funds.");
            }

            ScreenRefresh(user, "Confirming withdrawal.");             // Don't show the negative to the user, it's confusing
            Console.WriteLine("Confirm withdrawal amount of $" + (-amountNum).ToString("0.00") + "?");
            if (!ConfirmYesNo())
            {
                return("Withdrawal cancelled.");
            }

            if (DBAct.AddTransaction(user, pass, amountNum))
            {
                return("$" + (-amountNum).ToString("0.00") + " withdrawn.");
            }
            else
            {
                return("Error: Withdrawal failed.");
            }
        }
示例#5
0
        /* Login()
         *   Gets username and password from user, then logs in (if authenticated)
         *
         *   Returns: Status string with results of login attempt
         */
        static string Login()
        {
            string user, pass;

            ScreenRefresh(null, "Logging in. Please provide username and password.");

            Console.WriteLine("Username:"******"Password:"******"Error: Could not authenticate credentials");
            }
        }
示例#6
0
        /* Deposit()
         *   Gets amount from user, confirms amount with user, and deposits the specified
         *   amount to the account.
         *
         *   Returns: Status string with results of the attempted withdrawal
         */
        static string Deposit(string user, string pass)
        {
            string  amountInput;
            decimal amountNum;

            ScreenRefresh(user, "Making deposit.");
            Console.WriteLine("Please enter amount to deposit (ex: 3500.00 or 3500), or \"Q\" to return.");
            amountInput = Console.ReadLine();

            if (amountInput.ToLower() == "q")
            {
                return("Deposit cancelled.");
            }
            if (!IsMoneyAmountFormatted(amountInput))
            {
                return("Error: Incorrectly formatted amount.");
            }
            amountNum = Convert.ToDecimal(amountInput);

            ScreenRefresh(user, "Confirming deposit.");
            Console.WriteLine("Confirm deposit amount of $" + (amountNum).ToString("0.00") + "?");

            if (!ConfirmYesNo())
            {
                return("Deposit cancelled.");
            }

            if (DBAct.AddTransaction(user, pass, amountNum))
            {
                return("$" + amountNum.ToString("0.00") + " deposited.");
            }
            else
            {
                return("Error: Deposit failed.");
            }
        }