Пример #1
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") + ".");
        }
Пример #2
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.");
            }
        }