Exemplo n.º 1
0
        public void SearchAccountScreen()
        {
            CheckDBacc checkDBacc = new CheckDBacc();

            //do while loop to keep display the screen incase user want to re enter
            do
            {
                try
                {
                    this.error = false;
                    Console.Clear();
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    Console.WriteLine("\t|                       Search An Account                     |");
                    Console.WriteLine("\t =============================================================");
                    Console.WriteLine("\t|                 Enter the Account number below              |");
                    Console.WriteLine("\t|                                                             |");
                    Console.Write("\t| Account number: ");

                    //record cursor position
                    int numberLeft = Console.CursorLeft;
                    int numberTop  = Console.CursorTop;
                    Console.Write("                                            |\n");
                    Console.WriteLine("\t|                                                             |");
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    this.feedbackLeft = Console.CursorLeft;
                    this.feedbackTop  = Console.CursorTop;

                    //set cursor posiition to account number position
                    Console.SetCursorPosition(numberLeft, numberTop);

                    string tempInput = Console.ReadLine();
                    this.accNum = Convert.ToInt32(tempInput);

                    //check if account entered is within 10 digits
                    //check if enter = 0 because in accDB, after account deletion, 0 would be placeholder
                    if (tempInput.Length > 10 || this.accNum == 0)
                    {
                        throw new Exception("Account number invalid");
                    }
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);

                    //check if acc number is in the accDB.txt
                    if (!checkDBacc.checkExist(this.accNum))
                    {
                        Console.WriteLine("\t\t Account not found");
                    }
                    else if (checkDBacc.checkExist(this.accNum))
                    {
                        //display the account detail
                        displayFound(this.accNum);
                        this.feedbackLeft = Console.CursorLeft;
                        this.feedbackTop  = Console.CursorTop;
                    }

                    //let user decide if want to continue
                    throw new Exception("");
                }
                catch (OverflowException ex)
                {
                    ex.ToString();
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t Account number invalid");
                    this.error = ExceptionHandle();
                }
                catch (Exception e)
                {
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t " + e.Message);
                    this.error = ExceptionHandle();
                }
            } while (this.error);
        }
Exemplo n.º 2
0
        public void StatementScreen()
        {
            ErrorHandler errorHandler = new ErrorHandler();
            CheckDBacc   checkDBacc   = new CheckDBacc();

            //do while loop incase user wants to re enter
            do
            {
                try
                {
                    this.error = false;
                    Console.Clear();
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    Console.WriteLine("\t|                           Statement                         |");
                    Console.WriteLine("\t =============================================================");
                    Console.WriteLine("\t|                 Enter the Account number below              |");
                    Console.WriteLine("\t|                                                             |");
                    Console.Write("\t| Account number: ");

                    //record cursor position
                    int numberLeft = Console.CursorLeft;
                    int numberTop  = Console.CursorTop;
                    Console.Write("                                            |\n");
                    Console.WriteLine("\t|                                                             |");
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    this.feedbackLeft = Console.CursorLeft;
                    this.feedbackTop  = Console.CursorTop;

                    //set cursor position
                    Console.SetCursorPosition(numberLeft, numberTop);

                    string tempInput = Console.ReadLine();
                    //Console.WriteLine(tempInput);
                    this.accNum = Convert.ToInt32(tempInput);

                    //check for input digit less than 10
                    //check for input 0 for accDB use 0 as placeholder
                    if (tempInput.Length > 10 || this.accNum == 0)
                    {
                        throw new Exception("Invalid account number");
                    }
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    if (!checkDBacc.checkExist(this.accNum))
                    {
                        throw new Exception("Account not found");
                    }
                    else if (checkDBacc.checkExist(this.accNum))
                    {
                        Console.WriteLine("\t\t Account found, statement is displayed below.");
                        Console.WriteLine("");

                        //display statement
                        DisplayFound(this.accNum);
                    }
                }
                catch (OverflowException ex)
                {
                    ex.ToString();
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t Account number is too long");
                    this.error = errorHandler.CheckUserInput();
                }
                catch (Exception e)
                {
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t " + e.Message);

                    //set error based on userInput
                    this.error = errorHandler.CheckUserInput();
                }
            } while (this.error);
        }
Exemplo n.º 3
0
        public void DeleteScreen()
        {
            ErrorHandler errorHandler = new ErrorHandler();
            CheckDBacc   checkDBacc   = new CheckDBacc();

            //do while loop if user wants to re-enter
            do
            {
                try
                {
                    this.error = false;
                    Console.Clear();
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    Console.WriteLine("\t|                       Delete an Account                     |");
                    Console.WriteLine("\t =============================================================");
                    Console.WriteLine("\t|                 Enter the Account number below              |");
                    Console.WriteLine("\t|                                                             |");
                    Console.Write("\t| Account number: ");
                    //record the current cursor position
                    int numberLeft = Console.CursorLeft;
                    int numberTop  = Console.CursorTop;
                    Console.Write("                                            |\n");
                    Console.WriteLine("\t|                                                             |");
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    this.feedbackLeft = Console.CursorLeft;
                    this.feedbackTop  = Console.CursorTop;
                    //set cursor position
                    Console.SetCursorPosition(numberLeft, numberTop);

                    string tempInput = Console.ReadLine();
                    this.accNum = Convert.ToInt32(tempInput);

                    //check user input if greater than 10 digit
                    //check for 0 because accDB use 0 as placeholders
                    if (tempInput.Length > 10 || this.accNum == 0)
                    {
                        throw new Exception("Invalid account number");
                    }
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    if (!checkDBacc.checkExist(this.accNum))
                    {
                        throw new Exception("Account not found");
                    }
                    else if (checkDBacc.checkExist(this.accNum))
                    {
                        Console.WriteLine("\t\t Account found, Details are displayed below.");
                        Console.WriteLine("");
                        //display account detail
                        //inside diplayFound would call delete file function
                        DisplayFound(this.accNum);
                    }
                }
                catch (OverflowException ex)
                {
                    ex.ToString();
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t Account number is too long");
                    this.error = errorHandler.CheckUserInput();
                }

                catch (Exception e)
                {
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t " + e.Message);
                    this.error = errorHandler.CheckUserInput();
                }
            } while (this.error);
        }
Exemplo n.º 4
0
        public void DepositScreen()
        {
            ErrorHandler errorHandler = new ErrorHandler();
            CheckDBacc   checkDBacc   = new CheckDBacc();


            //do while loop if user want to re-enter
            do
            {
                try
                {
                    this.error = false;
                    Console.Clear();
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    Console.WriteLine("\t|                           Deposit                           |");
                    Console.WriteLine("\t =============================================================");
                    Console.WriteLine("\t|                   Enter The Details Below                   |");
                    Console.WriteLine("\t|                                                             |");
                    Console.Write("\t| Account Number: ");

                    //record the current cursor position
                    int accLeft = Console.CursorLeft;
                    int accTop  = Console.CursorTop;
                    Console.Write("                                            |\n");
                    Console.Write("\t| Amount: $");
                    int amountLeft = Console.CursorLeft;
                    int amountTop  = Console.CursorTop;
                    Console.Write("                                                   |\n");
                    Console.WriteLine("\t|                                                             |");
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    this.feedbackLeft = Console.CursorLeft;
                    this.feedbackTop  = Console.CursorTop;

                    //set cursor position
                    Console.SetCursorPosition(accLeft, accTop);
                    string tempInput = Console.ReadLine();
                    this.accNum = Convert.ToInt32(tempInput);

                    //check if input is within 10 digit
                    //check for 0 because accDB use 0 as placeholders
                    if (tempInput.Length > 10 || this.accNum == 0)
                    {
                        throw new Exception("Invalid account number");
                    }

                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    if (!checkDBacc.checkExist(this.accNum))
                    {
                        throw new Exception("Account number invalid");
                    }
                    else if (checkDBacc.checkExist(this.accNum))
                    {
                        Console.WriteLine("\t\t Account found! Enter the amount...");
                        this.feedbackLeft = Console.CursorLeft;
                        this.feedbackTop  = Console.CursorTop;
                        Console.SetCursorPosition(amountLeft, amountTop);
                        tempInput = Console.ReadLine();

                        //Convert the user input to 2 decimal
                        this.amount = Math.Round(Convert.ToDouble(tempInput), 2);

                        //change the amount in file
                        depostToDB(this.accNum, this.amount);
                        Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                        Console.WriteLine("\t\t Deposit successful");
                        Console.WriteLine("\t\t Press any key to go to menu..");
                    }

                    Console.ReadKey();
                }
                catch (OverflowException ex)
                {
                    ex.ToString();
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t Account number is too long");
                    this.error = errorHandler.CheckUserInput();
                }
                catch (Exception e)
                {
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t " + e.Message);
                    //based on user input, set error to true or false
                    this.error = errorHandler.CheckUserInput();
                }
            } while (this.error);
        }
Exemplo n.º 5
0
        public void WithdrawScreen()
        {
            ErrorHandler errorHandler = new ErrorHandler();
            CheckDBacc   checkDBacc   = new CheckDBacc();

            do
            {
                try
                {
                    this.error = false;
                    Console.Clear();
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    Console.WriteLine("\t|                           Withdraw                          |");
                    Console.WriteLine("\t =============================================================");
                    Console.WriteLine("\t|                   Enter The Details Below                   |");
                    Console.WriteLine("\t|                                                             |");
                    Console.Write("\t| Account Number: ");

                    //record cursor position
                    int accLeft = Console.CursorLeft;
                    int accTop  = Console.CursorTop;
                    Console.Write("                                            |\n");
                    Console.Write("\t| Amount: $");
                    int amountLeft = Console.CursorLeft;
                    int amountTop  = Console.CursorTop;
                    Console.Write("                                                   |\n");
                    Console.WriteLine("\t|                                                             |");
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    this.feedbackLeft = Console.CursorLeft;
                    this.feedbackTop  = Console.CursorTop;

                    //set cursor position
                    Console.SetCursorPosition(accLeft, accTop);
                    string tempInput = Console.ReadLine();
                    this.accNum = Convert.ToInt32(tempInput);

                    //check if user input is less than 10 digit
                    //check for 0 because 0 is used as placeholders in accDB
                    if (tempInput.Length > 10 || this.accNum == 0)
                    {
                        throw new Exception("Invalid account number");
                    }

                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);

                    //check if user account exist in accDB
                    if (!checkDBacc.checkExist(this.accNum))
                    {
                        throw new Exception("Account number invalid");
                    }
                    else if (checkDBacc.checkExist(this.accNum))
                    {
                        Console.WriteLine("\t\t Account found! Enter the amount...");
                        this.feedbackLeft = Console.CursorLeft;
                        this.feedbackTop  = Console.CursorTop;

                        //set cursor back to amount
                        Console.SetCursorPosition(amountLeft, amountTop);
                        tempInput = Console.ReadLine();

                        //round the input to 2 decimal
                        this.amount = Math.Round(Convert.ToDouble(tempInput), 2);
                        withDrawFromDB(this.accNum, this.amount);
                        Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                        Console.WriteLine("\t\t Withdraw successful");
                        Console.WriteLine("\t\t Press any key to go to menu..");
                    }

                    Console.ReadKey();
                }
                catch (OverflowException ex)
                {
                    ex.ToString();
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t Account number is too long");
                    this.error = errorHandler.CheckUserInput();
                }
                catch (Exception e)
                {
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t " + e.Message);
                    //check userinput if its y or n, and set error accordingl
                    this.error = errorHandler.CheckUserInput();
                }
            } while (this.error);
        }