示例#1
0
        public void AccountDelete()
        {
            DrawScreen draw = new DrawScreen();

            draw.TopScreen();
            Console.WriteLine(" Delete Account ");
            draw.UnderTitleLine();

            long accountNum = 0;
            bool accountValid;

            Console.Write("Enter account number: ");
            //get input 6-8 digits account number
            do
            {
                accountNum   = Convert.ToInt64(Console.ReadLine());
                accountValid = SearchAccount.CheckInputValidity(accountNum);
            } while (!accountValid);

            //check if account exists with number provided
            bool existingAccount = SearchAccount.CheckAccountExists(accountNum);

            //if exists prompt account deletion
            if (existingAccount)
            {
                string   path   = $"{accountNum}.txt";
                string[] detail = System.IO.File.ReadAllLines(path);

                //display account details
                foreach (string set in detail)
                {
                    Console.WriteLine(set);
                }
                //get user confirmation to delete
                //if confirmed delete file from path and return to menu
                if (ConfirmDelete())
                {
                    File.Delete(path);
                    Screens.mainMenu();
                }
                //ask if user wants to search again or return to menu if they dont delete previous file
                else
                {
                    CheckAnother();
                }
            }
            else
            {
                Console.WriteLine("Account does not exist ");
                Screens.mainMenu();
            }
        }
示例#2
0
        public void LastFiveTransaction()
        {
            DrawScreen draw = new DrawScreen();

            draw.TopScreen();
            Console.WriteLine(" A/C Statement ");
            draw.UnderTitleLine();

            long accountNum = 0;
            bool accountValid;

            Console.Write("Enter account number: ");
            //get input 6-8 digits account number
            do
            {
                accountNum   = Convert.ToInt64(Console.ReadLine());
                accountValid = SearchAccount.CheckInputValidity(accountNum);
            } while (!accountValid);

            //check if account exists with number provided
            bool existingAccount = SearchAccount.CheckAccountExists(accountNum);

            //if account exists prompt withdrawal money
            if (existingAccount)
            {
                Console.Clear();
                Console.WriteLine("Account Number: " + accountNum);

                string path = $"{accountNum}.txt";
                //all details from file
                string[] detail = System.IO.File.ReadAllLines(path);
                //last five transaction details
                string[] lastFive = new string[5];
                int      y        = 0;
                draw.OtherLine();
                //look at bottom five lines in file where all transactions are saved
                Console.WriteLine("upto 5 previous transactions shown: ");

                for (int x = (detail.Length - 5); x < detail.Length; x++)
                {
                    //only add transaction if it contains "transaction"
                    if (detail[x].Contains("Transaction"))
                    {
                        Console.WriteLine(detail[x]);
                        lastFive[y] = detail[x];
                        y++;
                    }
                }

                //check if user wants statement sent to email
                //YesNoEmail();
                //if user wants email statement then email last five trasnactions to their email
                draw.OtherLine();
                if (YesNoEmail())
                {
                    Console.WriteLine("Please enter your email address: ");
                    string email = Console.ReadLine();
                    EmailStatement(lastFive, email);
                    Screens.mainMenu();
                }
                //if no email then go to menu
                else
                {
                    Screens.mainMenu();
                }
            }
            //if account doesnt exist go to menu after message shown
            else
            {
                Console.WriteLine("Account does not exist ");
                Console.ReadKey();
                Screens.mainMenu();
            }
        }
示例#3
0
        // CreateAccount accountNo = new CreateAccount();

        public void WithdrawMoney()
        {
            DrawScreen draw = new DrawScreen();

            draw.TopScreen();
            Console.WriteLine(" Withdrawal ");
            draw.UnderTitleLine();

            long   withdrawalAmount;
            long   accountNum   = 0;
            bool   accountValid = false;
            long   finalAmount  = 0;
            string firstName    = null;
            string lastName     = null;
            string address      = null;
            string phone        = null;
            string email        = null;

            //get VALID account number
            Console.Write("Enter account number: ");
            do
            {
                accountNum   = Convert.ToInt64(Console.ReadLine());
                accountValid = SearchAccount.CheckInputValidity(accountNum);
            } while (!accountValid);

            //check if account exists with number provided
            bool existingAccount = SearchAccount.CheckAccountExists(accountNum);

            //if account exists prompt withdrawal money
            if (existingAccount)
            {
                Console.Write("Enter withdrawal amount: ");
                withdrawalAmount = Convert.ToInt64(Console.ReadLine());

                string   path      = $"{accountNum}.txt";
                string[] detail    = System.IO.File.ReadAllLines(path);
                bool     withdrawn = false;

                // save all other details
                //add to final amount if it already exists
                foreach (string set in detail)
                {
                    string[] splits = set.Split(':');
                    if (set.Contains("First Name"))
                    {
                        firstName = splits[1];
                    }
                    if (set.Contains("Last Name"))
                    {
                        lastName = splits[1];
                    }
                    if (set.Contains("Address"))
                    {
                        address = splits[1];
                    }
                    if (set.Contains("Phone Number"))
                    {
                        phone = splits[1];
                    }
                    if (set.Contains("Email"))
                    {
                        email = splits[1];
                    }
                    //if there is previous value minus withdraw amount and set withdraw to true
                    if (set.Contains("Amount"))
                    {
                        withdrawn   = true;
                        finalAmount = (Convert.ToInt64(splits[1]) - withdrawalAmount);
                    }
                }

                //if withdraw amount more then funds in account show error message
                if (finalAmount < 0 || !withdrawn)
                {
                    Console.WriteLine("You do not have suffecient funds in your account!!");
                    Screens.mainMenu();
                }
                //if enough funds edit file
                else
                {
                    EditFile(firstName, lastName, address, phone, email, finalAmount, withdrawalAmount, accountNum, detail);
                    Screens.mainMenu();
                }
            }
            //if no file show error message and go to menu
            else
            {
                Console.WriteLine("Account does not exist ");
                Screens.mainMenu();
            }
        }
示例#4
0
        public void MainMenu() //main menu
        {
            Console.Title = "Main Menu";
            Console.Clear();

            Console.ForegroundColor = ConsoleColor.Cyan;

            draw.TopScreen();
            Console.WriteLine(" MAIN MENU ");
            draw.UnderTitleLine();

            //display all available menus
            Console.WriteLine("1. Create new account");
            Console.WriteLine("2. Search for account");
            Console.WriteLine("3. Deposit");
            Console.WriteLine("4. Withdraw");
            Console.WriteLine("5. A/C statement");
            Console.WriteLine("6. Delete account");
            Console.WriteLine("7. Exit");

            draw.BottomScreen();

            Console.Write(" Enter your choice 1-7: ");

            //get user input to traverse through the application
            try
            {
                //switch cases accordingly to user input
                //aesthetics and user friendly names are set accordingly
                //titles are set which lable each screen on top
                //each screen is set to clear when prompted removing all previous trash
                int menuChoice = Int32.Parse(new string(Console.ReadKey().KeyChar, 1));
                Console.WriteLine();
                switch (menuChoice)
                {
                case 1:
                    Console.Title = "Create new account";
                    Console.Clear();

                    CreateAccount newAccount = new CreateAccount();
                    newAccount.NewUser();
                    //createAccount();
                    break;

                case 2:
                    Console.Title = "Search Account";
                    Console.Clear();

                    SearchAccount search = new SearchAccount();
                    search.AccountSearch();
                    Console.WriteLine("done and dusted");
                    break;

                case 3:
                    Console.Title = "Deposit into Account";
                    Console.Clear();

                    Deposit deposit = new Deposit();
                    deposit.DepositMoney();

                    break;

                case 4:
                    Console.Title = "Withdraw from Account";
                    Console.Clear();

                    Withdraw withdraw = new Withdraw();
                    withdraw.WithdrawMoney();

                    break;

                case 5:
                    Console.Title = "Account Statement";
                    Console.Clear();

                    Statement lastStatement = new Statement();
                    lastStatement.LastFiveTransaction();

                    break;

                case 6:
                    Console.Title = "Delete Account";
                    Console.Clear();

                    DeleteAccount accDelete = new DeleteAccount();
                    accDelete.AccountDelete();

                    break;

                case 7:
                    // Console.WriteLine("Press any key to confirm exit, Thanks!");
                    break;
                }
            }
            //excption message such as letter entered in above numeric switch statement
            catch (FormatException)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Something went wrong, Press any key to return to menu ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.ReadKey();
                MainMenu();

                Console.ReadKey();
            }
        }
示例#5
0
        public void DepositMoney()
        {
            DrawScreen draw = new DrawScreen();

            draw.TopScreen();
            Console.WriteLine(" Deposit ");
            draw.UnderTitleLine();

            long   depositAmount;
            long   accountNum   = 0;
            bool   accountValid = false;
            long   finalAmount  = 0;
            string firstName    = null;
            string lastName     = null;
            string address      = null;
            string phone        = null;
            string email        = null;

            Console.Write("Enter account number: ");
            //get Valid account number 6-8 digits
            do
            {
                accountNum   = Convert.ToInt64(Console.ReadLine());
                accountValid = SearchAccount.CheckInputValidity(accountNum);
            } while (!accountValid);

            //check if account exists with number provided
            bool existingAccount = SearchAccount.CheckAccountExists(accountNum);

            //if account exists prompt deposit money
            if (existingAccount)
            {
                Console.Write("Enter deposit amount: ");
                depositAmount = Convert.ToInt64(Console.ReadLine());

                string   path      = $"{accountNum}.txt";
                string[] detail    = File.ReadAllLines(path);
                bool     deposited = false;

                //save all other details
                //add to final amount if it already exists
                foreach (string set in detail)
                {
                    string[] splits = set.Split(':');
                    if (set.Contains("First Name"))
                    {
                        firstName = splits[1];
                    }
                    if (set.Contains("Last Name"))
                    {
                        lastName = splits[1];
                    }
                    if (set.Contains("Address"))
                    {
                        address = splits[1];
                    }
                    if (set.Contains("Phone Number"))
                    {
                        phone = splits[1];
                    }
                    if (set.Contains("Email"))
                    {
                        email = splits[1];
                    }
                    if (set.Contains("Transaction"))
                    {
                        //make no changes if it contains 'transactions'
                    }
                    if (set.Contains("Amount"))
                    {
                        finalAmount = (Convert.ToInt64(splits[1]) + depositAmount);
                        deposited   = true;
                    }
                }
                //if amount doesnt exists in final then deposit amount = final amount
                if (!deposited)
                {
                    finalAmount = depositAmount;
                }
                //make appropriate changes to file and exit appropriately
                EditFile(firstName, lastName, address, phone, email, finalAmount, depositAmount, accountNum, detail);
                Screens.mainMenu();
            }
            //if account doesnt exist display error message and go to menu
            else
            {
                Console.WriteLine("Account does not exist ");
                Screens.mainMenu();
            }
        }