Beispiel #1
0
        public bool normalCash()
        {
            Clear();
            decimal requestedAmount = 0;

inputRequestedAmount:
            try
            {
                Write("\nEnter the withdrawal amount: ");
                ATMInterface.changeTextColor(Color.Green);
                requestedAmount = decimal.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputRequestedAmount;
            }
            CustomerBLL bll         = new CustomerBLL();
            Transaction transaction = bll.withDraw(requestedAmount, customer.accountNo);

            ATMInterface.changeTextColor(Color.Gray);
            if (transaction != null)
            {
                WriteLine("\nCash Successfully Withdrawn!");
                printRecepit(transaction, customer.accountNo);
                delay();
                return(true);
            }
            errorMessage("\nCashDrawn unsuccesfull!");
            delay();
            return(true);
        }
Beispiel #2
0
        public bool cashTransfer()
        {
            CustomerBLL bll             = new CustomerBLL();
            int         transferTo      = -2;
            decimal     requestedAmount = 0;
            Transaction transaction     = null;

inputRequestedAmount:
            try
            {
                ATMInterface.changeTextColor(Color.Gray);
                Write("\nEnter amount in multiples of 500: ");
                ATMInterface.changeTextColor(Color.Green);
                requestedAmount = decimal.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                Account account = bll.getAccount(customer.accountNo);
                if (requestedAmount < 0 || requestedAmount % 500 != 0 || requestedAmount > account.Balance)
                {
                    throw new Exception($"Amount should not be neagitive and Sould " +
                                        $"be multipiles of 500 and should be less than you current account balance i.e {account.Balance}");
                }
                Write("\nEnter the account number to which you want to transfer: ");
                ATMInterface.changeTextColor(Color.Green);
                transferTo = int.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                if (transferTo == customer.accountNo)
                {
                    throw new Exception("You cannot transfer to yourself");
                }
                Person personTo = bll.getPerson(transferTo);
                if (personTo == null)
                {
                    throw new Exception("Account did not found");
                }
                Write($"\nYou wish to deposit Rs {requestedAmount} in account held by {personTo.Name};" +
                      $" If this information is correct please re - enter the   account number: ");
                ATMInterface.changeTextColor(Color.Green);
                transferTo = int.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                if (transferTo == personTo.accountNo)
                {
                    transaction = bll.transferAmount(requestedAmount, customer.accountNo, personTo.accountNo);
                    if (transaction != null)
                    {
                        WriteLine("Transaction confirmed.");
                        printRecepit(transaction, account.ID);
                        delay();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputRequestedAmount;
            }
            errorMessage("Transaction unsuccessfull!");
            delay();
            return(true);
        }
Beispiel #3
0
        public char GetInput(char from, char to)
        {
            bool control = true;

            char menu = '-';

            while (control)
            {
                try {
                    ATMInterface.changeTextColor(Color.Green);
                    ConsoleKeyInfo key = ReadKey();
                    ATMInterface.changeTextColor(Color.Gray);
                    menu = key.KeyChar;
                    if (!validateInput(key.KeyChar, from, to))
                    {
                        throw new Exception("\nInput Selection is not in range");
                    }
                    control = false;
                }
                catch (Exception ex)
                {
                    errorMessage(ex.Message);
                    control = true;
                    continue;
                }
            }
            ATMInterface.changeTextColor(Color.Gray);
            return(menu);
        }
Beispiel #4
0
        public bool displayBalance()
        {
            Clear();
            ATMInterface.changeTextColor(Color.Gray);
            CustomerBLL bll = new CustomerBLL();

            bll.displayReciept(null, customer.accountNo);
            delay();
            return(true);
        }
Beispiel #5
0
        public override bool menu(int userType)
        {
            Clear();
            CustomerBLL bll = new CustomerBLL();

            this.customer = bll.getPerson(-2, userType);
            ATMInterface.changeTextColor(Color.Gray);
            WriteLine("\nWelcome in Customer menu");
            WriteLine("1----Withdraw Cash\n2----Cash Transfer\n3----Deposit Cash" +
                      "\n4----Display Balance\n5----Exit");
            return(selectMenu(GetInput('1', '5')));
        }
Beispiel #6
0
        private void printRecepit(Transaction transaction, int accountNo)
        {
            CustomerBLL bll = new CustomerBLL();

            Write("Do you wish to print a receipt (Y/N)?");
            ATMInterface.changeTextColor(Color.Green);
            ConsoleKeyInfo key = ReadKey();

            ATMInterface.changeTextColor(Color.Gray);
            if (key.KeyChar.ToString().ToLower() == "y")
            {
                bll.displayReciept(transaction, accountNo);
            }
        }
Beispiel #7
0
        public bool withDraw()
        {
            Clear();
            customerDelegator wd = null;

            ATMInterface.changeTextColor(Color.Gray);
            WriteLine("\na) Fast Cash\nb) Normal Cash");
            wd = GetInput('a', 'b') switch
            {
                'a' => fastCash,
                'b' => normalCash,
                _ => Exit
            };
            return(wd.Invoke());
        }
        public bool deleteAccount()
        {
            Clear();
            AdminBLL bll = new AdminBLL();
            int      accountNo;

inputAccountAgain:
            try
            {
                Write("\nEnter the account number to which you want to delete: ");
                ATMInterface.changeTextColor(Color.Green);
                accountNo = int.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                Person person = (Person)bll.getPerson(accountNo)?[0];
                if (person == null || accountNo == -1)
                {
                    errorMessage("Account did not found!");
                    delay();
                    return(true);
                }
                Write($"\nYou wish to delete the account held by {person.Name}; \nIf " +
                      $"this information is correct please re - enter the account number:");
                ATMInterface.changeTextColor(Color.Green);
                accountNo = int.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                if (accountNo == person.accountNo)
                {
                    bll.deleteAccount(accountNo, person.id);
                    WriteLine("Account Deleted Successfully");
                    delay();
                }
                else
                {
                    errorMessage("Cannot be deleted");
                    delay();
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputAccountAgain;
            }
            return(true);
        }
Beispiel #9
0
        public bool fastCash()
        {
            Clear();
            ATMInterface.changeTextColor(Color.Gray);
            WriteLine("\n1----500\n2----1000\n3----2000\n4----5000" +
                      "\n5----10000\n6----15000\n7----20000");
            Write("Select one of the denominations of money: ");
            decimal selectedCash = 0;

inputAmountAgain:
            try
            {
                selectedCash = decimal.Parse("" + GetInput('1', '5'));
            }catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputAmountAgain;
            }
            Write($"\nAre you sure you want to withdraw Rs. {selectedCash*500} (Y / N) ?: ");
            ATMInterface.changeTextColor(Color.Green);
            ConsoleKeyInfo key = ReadKey();

            ATMInterface.changeTextColor(Color.Gray);
            if (key.KeyChar.ToString().ToLower() == "y")
            {
                CustomerBLL bll         = new CustomerBLL();
                Transaction transaction = bll.withDraw(selectedCash * 500, customer.accountNo);
                if (transaction != null)
                {
                    WriteLine("\nCash Successfully Withdrawn!");
                    printRecepit(transaction, customer.accountNo);
                    delay();
                    return(true);
                }
            }
            errorMessage("\nWithdraw Failed");
            delay();
            return(true);
        }
Beispiel #10
0
        public bool depositCash()
        {
            Clear();
            decimal requestedAmount = 0;

inputRequestedAmount:
            try
            {
                ATMInterface.changeTextColor(Color.Gray);
                Write("\nEnter the cash amount to Desposited : ");
                ATMInterface.changeTextColor(Color.Green);
                requestedAmount = decimal.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                if (requestedAmount < 0)
                {
                    throw new Exception("Enter Amount should not neagtive");
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputRequestedAmount;
            }
            CustomerBLL bll         = new CustomerBLL();
            Transaction transaction = bll.depositCash(requestedAmount, this.customer.accountNo);

            if (transaction != null)
            {
                WriteLine("Cash Deposited Successfully");
                printRecepit(transaction, customer.accountNo);
                delay();
                return(true);
            }
            errorMessage("Cash Deposited unsuccessful");
            delay();
            return(true);
        }
Beispiel #11
0
        private bool transactionsByDate()
        {
            DateTime startDate, endDate;

            Clear();
inputStartDateAgain:
            try
            {
                Write("\nEnter the Starting Date[DD/MM/YYYY]: ");
                ATMInterface.changeTextColor(Color.Green);
                string   date  = ReadLine();
                string[] dates = date.Split("/");
                if (dates.Length != 3)
                {
                    throw new Exception("Date is incorrect format [DD/MM/YYYY]");
                }

                int day   = int.Parse(dates[0]);
                int month = int.Parse(dates[1]);
                int year  = int.Parse(dates[2]);
                startDate = new DateTime(year, month, day);
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputStartDateAgain;
            }
            ATMInterface.changeTextColor(Color.Gray);
inputEndDateAgain:
            try
            {
                Write("\nEnter the Ending Date[DD/MM/YYYY]: ");
                ATMInterface.changeTextColor(Color.Green);
                string   date  = ReadLine();
                string[] dates = date.Split("/");
                if (dates.Length != 3)
                {
                    throw new Exception("Date is incorrect format [DD/MM/YYYY]");
                }

                int day   = int.Parse(dates[0]);
                int month = int.Parse(dates[1]);
                int year  = int.Parse(dates[2]);
                endDate = new DateTime(year, month, day);
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputEndDateAgain;
            }
            ATMInterface.changeTextColor(Color.Gray);
            AdminBLL bll = new AdminBLL();

            (ArrayList persons, ArrayList transactions) = bll.transactionByDates(startDate, endDate);
            if (transactions.Count != 0)
            {
                WriteLine("=================Search Results=================");
                WriteLine($"{"Transactions Type",-25}{"User ID",-15}{"Holders Name",-20}{"Amount",-15}{"Date",-20}");
                for (int i = 0; i < transactions.Count; i++)
                {
                    Transaction transaction = (Transaction)transactions[i];
                    Person      person      = (Person)persons[i];
                    WriteLine($"{transaction.Id,-25}{person.id,-15}{person.Name,-20}{transaction.Amount,-15}{transaction.Date,-20}");
                }
            }
            else
            {
                errorMessage("Transaction did not match your criteria");
            }
            delay();
            return(true);
        }
Beispiel #12
0
        private bool accountsByAmmount()
        {
            decimal minBalance = 0, maxBalance = 0;

            Clear();
inputMinBalanceAgain:
            try
            {
                Write("\nEnter the minimum amount: ");
                ATMInterface.changeTextColor(Color.Green);
                minBalance = decimal.Parse(ReadLine());

                if (minBalance < 0)
                {
                    throw new Exception("Minimum Balance should Not be less than zero");
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputMinBalanceAgain;
            }
            ATMInterface.changeTextColor(Color.Gray);
inputMaxBalanceAgain:
            try
            {
                Write("Enter the maximum amount: ");
                ATMInterface.changeTextColor(Color.Green);
                maxBalance = decimal.Parse(ReadLine());
                if (minBalance < 0)
                {
                    throw new Exception("Maximum Balance should Not be less than zero");
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputMaxBalanceAgain;
            }
            ATMInterface.changeTextColor(Color.Gray);
            AdminBLL bll = new AdminBLL();

            (ArrayList persons, ArrayList accounts) = bll.accountsByAmount(minBalance, maxBalance);
            if (accounts.Count != 0)
            {
                WriteLine("=================Search Results=================");
                WriteLine($"{"Account ID",-15}{"User ID",-10}{"Holders Name",-20}{"Type",-15}{"Balance",-15}{"Status",-15}");
                for (int i = 0; i < accounts.Count; i++)
                {
                    Account account = (Account)accounts[i];
                    Person  person  = (Person)persons[i];
                    WriteLine($"{account.ID,-15}{person.id,-10}{person.Name,-20}{account.Type,-15}{account.Balance,-15}{account.Status,-15}");
                }
            }
            else
            {
                errorMessage("Acccount did not match your criteria");
            }
            delay();
            return(true);
        }
Beispiel #13
0
        public bool createAccount()
        {
            Clear();
            decimal balance = 0;
            int     accountType = 0, accountStatus = 0;
            string  pinCode = String.Empty;

            Write("Login: "******"Pin Code: ");
                ATMInterface.changeTextColor(Color.Green);
                pinCode = ReadLine();
                if (pinCode.Length != 5 || !Regex.Match(pinCode, @"\d\d\d\d\d").Success)
                {
                    throw new Exception("Pincode is incorrect");
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputPinCode;
            }
            ATMInterface.changeTextColor(Color.Gray);
            Write("Holders Name: ");
            ATMInterface.changeTextColor(Color.Green);
            string holderName = ReadLine();

            ATMInterface.changeTextColor(Color.Gray);
inputTypeAgain:
            try {
                Write("Type(Savings, Current): ");
                ATMInterface.changeTextColor(Color.Green);
                string type = ReadLine();
                ATMInterface.changeTextColor(Color.Gray);
                if (type.ToLower() != "savings" && type.ToLower() != "current")
                {
                    throw new Exception("savings/current");
                }
                else
                {
                    accountType = type.ToLower() switch
                    {
                        "savings" => 0,
                        "current" => 1
                    };
                }
            }
            catch (Exception e)
            {
                errorMessage(e.Message);
                goto inputTypeAgain;
            }
inputBalanceAgain:
            try {
                Write("Starting Balance: ");
                ATMInterface.changeTextColor(Color.Green);
                balance = decimal.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                if (balance < 0)
                {
                    throw new Exception("Starting Balance should Not be less than zero");
                }
            }
            catch (Exception ex) {
                errorMessage(ex.Message);
                goto inputBalanceAgain;
            }
inputStatusAgain:
            try {
                Write("Status(Active/Inactive): ");
                ATMInterface.changeTextColor(Color.Green);
                string status = ReadLine();
                ATMInterface.changeTextColor(Color.Gray);
                if (status.ToLower() != "active" && status.ToLower() != "inactive")
                {
                    throw new Exception("Active/Inactive");
                }
                else
                {
                    accountStatus = status.ToLower() switch
                    {
                        "active" => 0,
                        "inactive" => 1
                    };
                }
            }
            catch (Exception ex) {
                errorMessage(ex.Message);
                goto inputStatusAgain;
            }
            AdminBLL bll       = new AdminBLL();
            int      accountNo = bll.createAccount((new Person(holderName, 0)), (new Credentials(login, pinCode)), (new Account(balance, accountType, accountStatus)));

            WriteLine($"Account created Suuessfully - the account number assigned is: {accountNo}");
            delay();
            return(true);
        }
Beispiel #14
0
        public bool SearchAccount()
        {
            Clear();


            int     accountID = -2, userID = -2, accountType = -2, accountStatus = -2;
            decimal balance = 0;

            WriteLine("\nSEARCH MENU: ");
inputAccountID:
            try
            {
                Write("Account ID: ");
                ATMInterface.changeTextColor(Color.Green);
                string accountid = ReadLine();
                if (accountid != String.Empty)
                {
                    accountID = int.Parse(accountid);
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputAccountID;
            }
            ATMInterface.changeTextColor(Color.Gray);
inputUserID:
            try
            {
                Write("User ID: ");
                ATMInterface.changeTextColor(Color.Green);
                string userid = ReadLine();
                if (userid != String.Empty)
                {
                    userID = int.Parse(userid);
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputUserID;
            }
            ATMInterface.changeTextColor(Color.Gray);
            Write("Holder Name: ");
            ATMInterface.changeTextColor(Color.Green);
            String holderName = ReadLine();

            ATMInterface.changeTextColor(Color.Gray);
inputTypeAgain:
            try
            {
                Write("Type(Savings, Current): ");
                ATMInterface.changeTextColor(Color.Green);
                string type = ReadLine();
                if (type.ToLower() != "savings" && type.ToLower() != "current" && type.ToLower() != String.Empty)
                {
                    throw new Exception("savings/current");
                }
                else
                {
                    accountType = type.ToLower() switch
                    {
                        "savings" => 0,
                        "current" => 1,
                        _ => - 2
                    };
                }
            }
            catch (Exception e)
            {
                errorMessage(e.Message);
                goto inputTypeAgain;
            }
            ATMInterface.changeTextColor(Color.Gray);

inputBalanceAgain:
            try
            {
                Write("Starting Balance: ");
                ATMInterface.changeTextColor(Color.Green);
                string bal = ReadLine();
                if (bal != String.Empty)
                {
                    balance = decimal.Parse(bal);
                }
                //if (balance < 0)
                //    throw new Exception("Starting Balance should Not be less than zero");
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputBalanceAgain;
            }
            ATMInterface.changeTextColor(Color.Gray);
inputStatusAgain:
            try
            {
                Write("Status(Active/Inactive): ");
                ATMInterface.changeTextColor(Color.Green);
                string status = ReadLine();
                if (status.ToLower() != "active" && status.ToLower() != "inactive" && status.ToLower() != String.Empty)
                {
                    throw new Exception("Active/Inactive");
                }
                else
                {
                    accountStatus = status.ToLower() switch
                    {
                        "active" => 0,
                        "inactive" => 1,
                        _ => - 2
                    };
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputStatusAgain;
            }
            ATMInterface.changeTextColor(Color.Gray);
            AdminBLL bll = new AdminBLL();

            (ArrayList persons, ArrayList accounts) = bll.searchAccount(accountID, userID, holderName, accountType, accountStatus, balance);
            if (accounts.Count == 0)
            {
                errorMessage("Account did not match");
                return(true);
            }
            WriteLine("=================Search Results=================");
            WriteLine($"{"Account ID",-15}{"User ID",-10}{"Holders Name",-20}{"Type",-15}{"Balance",-15}{"Status",-15}");
            for (int i = 0; i < accounts.Count; i++)
            {
                Account account = (Account)accounts[i];
                Person  person  = (Person)persons[i];
                WriteLine($"{account.ID,-15}{person.id,-10}{person.Name,-20}{account.Type,-15}{account.Balance,-15}{account.Status,-15}");
            }
            delay();
            return(true);
        }
Beispiel #15
0
        public bool updateAccount()
        {
            Clear();
            AdminBLL    bll = new AdminBLL();
            int         accountNo;
            Account     account;
            Person      person;
            Credentials credentials;

inputAccountAgain:
            try
            {
                Write("\nEnter the Account Number: ");
                ATMInterface.changeTextColor(Color.Green);
                accountNo = int.Parse(ReadLine());
                ATMInterface.changeTextColor(Color.Gray);
                account     = (Account)bll.getAccount(accountNo)?[0];
                person      = (Person)bll.getPerson(accountNo)?[0];
                credentials = bll.getCredentials(person.id);
                if (account == null || accountNo == -1)
                {
                    errorMessage("Account did not Found");
                    delay();
                    return(true);;
                }
                WriteLine($"\nAccount # {account.ID}\nType: {account.Type}\nHolder {person.Name}\n" +
                          $"Balance: {account.Balance}\nStatus: {account.Status}\n");
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputAccountAgain;
            }
            WriteLine("Please enter in the fields you wish to update(leave blank otherwise):");
            Write("Login: "******"Pin Code: ");
                ATMInterface.changeTextColor(Color.Green);
                pinCode = ReadLine();
                ATMInterface.changeTextColor(Color.Gray);
                if (!(pinCode == String.Empty) && (pinCode.Length != 5 || !Regex.Match(pinCode, @"\d\d\d\d\d").Success))
                {
                    throw new Exception("Pin Code is incorrect format");
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputPinCode;
            }
            Write("Holders Name: ");
            ATMInterface.changeTextColor(Color.Green);
            string holderName = ReadLine();

            ATMInterface.changeTextColor(Color.Gray);
            int accountStatus = 0;

inputStatusAgain:
            try
            {
                Write("Status(Active/Inactive): ");
                ATMInterface.changeTextColor(Color.Green);
                string status = ReadLine();
                ATMInterface.changeTextColor(Color.Gray);
                if (status.ToLower() != "active" && status.ToLower() != "inactive" && status != String.Empty)
                {
                    throw new Exception("Active/Inactive");
                }
                else
                {
                    accountStatus = status.ToLower() switch
                    {
                        "active" => 0,
                        "inactive" => 1,
                        "" => - 1
                    };
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                goto inputStatusAgain;
            }
            bll.deleteAccount(account.ID, person.id);
            if (login != String.Empty)
            {
                credentials.Login = login;
            }
            if (pinCode != String.Empty)
            {
                credentials.Password = pinCode;
            }
            if (holderName != String.Empty)
            {
                person.Name = holderName;
            }
            if (accountStatus != -1)
            {
                account.Status = (Account.AccountStatus)accountStatus;
            }
            bll.createAccount(person, credentials, account);
            WriteLine("Your account has been successfully been updated.");
            delay();
            return(true);
        }
Beispiel #16
0
 public static void errorMessage(string Message)
 {
     ATMInterface.changeTextColor(Color.Red);
     WriteLine(Message);
     ATMInterface.changeTextColor(Color.Gray);
 }