예제 #1
0
    public static void Main()
    {
        DictionaryBank ourBank = new DictionaryBank();

        CustomerAccount newAccount = new CustomerAccount("Rob", 1000000);

        if (ourBank.StoreAccount(newAccount))
        {
            Console.WriteLine("CustomerAccount added to bank");
        }

        BabyAccount newBabyAccount = new BabyAccount("David", 100, "Rob");

        if (ourBank.StoreAccount(newBabyAccount))
        {
            Console.WriteLine("BabyAccount added to bank");
        }

        ourBank.Save("Test.txt");

        DictionaryBank loadBank = DictionaryBank.Load("Test.txt");

        IAccount storedAccount = loadBank.FindAccount("Rob");

        if (storedAccount != null)
        {
            Console.WriteLine("CustomerAccount found in bank");
        }
        storedAccount = loadBank.FindAccount("David");
        if (storedAccount != null)
        {
            Console.WriteLine("BabyAccount found in bank");
        }
    }
예제 #2
0
        public static void EditScript(DictionaryBank ourBank)
        {
            IAccount chosenAccount;
            string   continueEditing;

            do
            {
                while (true)
                {
                    int inAccountNumber = Validation.ValidateInt("\nPlease give the account number of the account you want to edit. If you don't want to edit an account, type exit.", 000000, 999999);
                    if (inAccountNumber == -1)
                    {
                        return;
                    }
                    chosenAccount = ourBank.FindAccount(inAccountNumber);
                    if (chosenAccount == null)
                    {
                        Console.WriteLine("\nThat account number does not exist in this bank");
                    }
                    break;
                }
                if (chosenAccount != null)
                {
                    AccountEditUI edit = new AccountEditUI(chosenAccount);
                    edit.DoEdit(chosenAccount);
                }
                continueEditing = Validation.ThisOrThat("\nWould you like to edit another account [Y] or [N]? ", "You have not entered [Y] or [N].", "y", "n");
            } while (continueEditing == "y");
        }
        public static void StatusScript(DictionaryBank ourBank)
        {
            string   continueStatus;
            int      inAccountNumber;
            IAccount chosenAccount;

            do
            {
                while (true)
                {
                    inAccountNumber = Validation.ValidateInt("\n-----Account Status-----\n" +
                                                             "\nPlease give the account number of the account you want to see. If you don't want to see the status of an account, type exit.", 0, 1000000);
                    if (inAccountNumber == -1)
                    {
                        return;
                    }
                    chosenAccount = ourBank.FindAccount(inAccountNumber);
                    if (chosenAccount == null)
                    {
                        Console.WriteLine("\nThere is no account with this account number. Are you sure you typed it correctly?");
                        continue;
                    }
                    break;
                }
                Console.WriteLine(chosenAccount.ToString());
                continueStatus = Validation.ThisOrThat("\nWould you like to the see status of another account [Y] or [N]?", "Please give your answer as [Y] or [N]", "y", "n");
            } while (continueStatus == "y");
        }
예제 #4
0
        public static void DeleteScript(DictionaryBank ourBank)
        {
            string continueDeleting;
            int    inAccountNumber;

            do
            {
                while (true)
                {
                    inAccountNumber = Validation.ValidateInt("\n-----Account Deletion-----\n" +
                                                             "\nPlease give the account number of the account you want to delete. If you don't want to delete an account, type exit.", 0, 1000000);
                    if (inAccountNumber == -1)
                    {
                        return;
                    }
                    string answer = Validation.ThisOrThat("\nAre you sure you want to delete this account, this cannot be undone. Type [Y] or [N].", "Please give your answer as [Y] or [N]", "y", "n");
                    if (answer == "n")
                    {
                        break;
                    }
                    ourBank.DeleteAccount(inAccountNumber);
                    break;
                }
                continueDeleting = Validation.ThisOrThat("\nWould you like to delete another account [Y] or [N]?", "Please give your answer as [Y] or [N]", "y", "n");
            } while (continueDeleting == "y");
        }
예제 #5
0
        public static void CreateScript(DictionaryBank ourBank)
        {
            string continueCreating;

            do
            {
                Console.WriteLine("\n-----Account Creation-----\n" +
                                  "\nWhat type of account would you like to create?" +
                                  "\n      Type customer for a new customer account" +
                                  "\n      Type baby for a new baby account");
                string input = Validation.TrimLower(Console.ReadLine());
                switch (input)
                {
                case "customer":
                    AccountCreateUI create = new AccountCreateUI(ourBank);
                    create.CreateCustomerAccount();
                    break;

                case "baby":
                    create = new AccountCreateUI(ourBank);
                    create.CreateBabyAccount();
                    break;

                default:
                    Console.WriteLine("You did not select a baby or customer account");
                    break;
                }
                continueCreating = Validation.ThisOrThat("\nWould you like to create another account [Y] or [N]?", "You have not entered [Y] or [N]", "y", "n");
            } while (continueCreating == "y");
        }
예제 #6
0
    public static DictionaryBank Load(System.IO.TextReader textIn)
    {
        DictionaryBank result      = new DictionaryBank();
        string         countString = textIn.ReadLine();
        int            count       = int.Parse(countString);

        for (int i = 0; i < count; i++)
        {
            Account account = Account.Load(textIn);
            result.accountDictionary.Add(account.GetName(), account);
        }
        return(result);
    }
예제 #7
0
    public static DictionaryBank Load(System.IO.TextReader textIn)
    {
        DictionaryBank result      = new DictionaryBank();
        string         countString = textIn.ReadLine();
        int            count       = int.Parse(countString);

        for (int i = 0; i < count; i++)
        {
            string   className = textIn.ReadLine();
            IAccount account   =
                AccountFactory.MakeAccount(className, textIn);
            result.StoreAccount(account);
        }
        return(result);
    }
예제 #8
0
    public static void Main()
    {
        DictionaryBank ourBank = new DictionaryBank();

        Account newAccount = new Account("Rob", "Robs House", 1000000);

        if (ourBank.StoreAccount(newAccount) == true)
        {
            Console.WriteLine("Account added to bank");
        }

        IAccount storedAccount = ourBank.FindAccount("Rob");

        if (storedAccount != null)
        {
            Console.WriteLine("Account found in bank");
        }
    }
예제 #9
0
        public static void Main()
        {
            Console.WriteLine("\n-------------------------------\n" +
                              "------Welcome to the bank------\n" +
                              "-------------------------------\n\n\n");
            DictionaryBank ourBank = DictionaryBank.Load("database.txt");

            if (!ourBank.AccountsInBank()) //at the moment, if this tries to load an empty document, it returns a null value and throws an exception that i cant do anything with. Might need to try a "TRYCATCH"
            {
            }

            string userValue;

            do
            {
                Console.WriteLine("\n-----Feature Select-----\n" +
                                  "\n    Create a new account (type new)" +
                                  "\n    Edit an existing account (type edit)" +
                                  "\n    See the status of an existing account (type status)" +
                                  "\n    Delete an existing account (type delete)" +
                                  "\n    Or type exit to exit the program");
                userValue = Validation.TrimLower(Console.ReadLine());
                switch (userValue)
                {
                case "new":
                    AccountCreateUI.CreateScript(ourBank);
                    break;

                case "edit":
                    AccountEditUI.EditScript(ourBank);
                    break;

                case "status":
                    AccountStatusUI.StatusScript(ourBank);
                    break;

                case "delete":
                    AccountDeleteUI.DeleteScript(ourBank);
                    break;
                }
            } while (userValue != "exit");
            ourBank.Save("database.txt");
            Console.ReadLine();
        }
예제 #10
0
    public static void Main()
    {
        DictionaryBank ourBank = new DictionaryBank();

        Account newAccount = new Account("Rob", 1000000);

        if (ourBank.StoreAccount(newAccount) == true)
        {
            Console.WriteLine("Account added to bank");
        }

        ourBank.Save("Test.txt");

        DictionaryBank loadBank = DictionaryBank.Load("Test.txt");

        IAccount storedAccount = ourBank.FindAccount("Rob");

        if (storedAccount != null)
        {
            Console.WriteLine("Account found in bank");
        }
    }
예제 #11
0
    public static DictionaryBank Load(string filename)
    {
        System.IO.TextReader textIn = null;
        DictionaryBank       result = null;

        try
        {
            textIn = new System.IO.StreamReader(filename);
            result = DictionaryBank.Load(textIn);
        }
        catch
        {
            return(null);
        }
        finally
        {
            if (textIn != null)
            {
                textIn.Close();
            }
        }

        return(result);
    }
예제 #12
0
 public void LoadConfig()
 {
     this.bank = DictionaryBank.Load(this.bankFileName);
 }
 public AccountStatusUI(DictionaryBank inBank)
 {
     ourBank = inBank;
 }
예제 #14
0
 public AccountDeleteUI(DictionaryBank inBank)
 {
     ourBank = inBank;
 }
예제 #15
0
 public AccountCreateUI(DictionaryBank inBank)
 {
     ourBank = inBank;
 }