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