Пример #1
0
        // Collects and sets monthly deposit amount for Type 2 account
        private void SetMonthlyDeposit()
        {
            uint  validID     = 0;
            float validAmount = 0.0f;
            bool  done        = false;

            while (!done)
            {
                validID     = GetValidandExistingID("Enter Account ID: ");
                validAmount = MenuSystem.GetValidAmount("Enter Monthly Deposit: ");
                Console.WriteLine("Press “s” or “S” if you want to submit ");
                Console.Write("Press any other keys if you want to cancel ");
                string input = Console.ReadLine();
                if (input == "s" || input == "S")
                {
                    if (_Accounts[(int)validID - 1].GetType() == typeof(Type2Account)) // must be Type 2 account
                    {
                        Type2Account temp = (Type2Account)_Accounts[(int)validID - 1];
                        temp.MonthlyDeposit         = validAmount;
                        _Accounts[(int)validID - 1] = temp;
                        done = true;
                    }
                    else
                    {
                        Console.WriteLine("You must select a Type 2 account to set a monthly deposit. Please re-enter account ID.");
                    }
                }
            }
        }
Пример #2
0
        // Reads in Account data from file
        public List <Account> LoadAccountData(List <Customer> inCustomers)
        {
            List <Account> inAccounts = new List <Account>();
            DateTime       openedDate, closedDate;
            string         opened = "", closed = "";
            Account        acc;

            try
            {
                _AccountsFileStream = File.Open(_AccountsFileName, FileMode.Open, FileAccess.Read);
                StreamReader sr         = new StreamReader(_AccountsFileStream);
                int          noAccounts = Convert.ToInt32(sr.ReadLine());
                for (int i = 0; i < noAccounts; i++)
                {
                    int accountType = Convert.ToInt32(sr.ReadLine());
                    int accountID   = Convert.ToInt32(sr.ReadLine());
                    int ownerID     = Convert.ToInt32(sr.ReadLine());
                    opened = sr.ReadLine();
                    try
                    {
                        openedDate = DateTime.ParseExact(opened, "d/M/yyyy",
                                                         System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Invalid Opened date for Account ID: {0}. Today's date used instead", accountID);
                        openedDate = DateTime.Now;
                    }
                    closed = sr.ReadLine();
                    float balance = (float)Convert.ToDecimal(sr.ReadLine());
                    if (accountType == 1)
                    {
                        acc = new Type1Account(inCustomers[ownerID - 1], openedDate, balance);
                    }
                    else
                    {
                        acc = new Type2Account(inCustomers[ownerID - 1], openedDate, balance);
                    }
                    if (closed != "")
                    {
                        try
                        {
                            closedDate = DateTime.ParseExact(closed, "d/M/yyyy",
                                                             System.Globalization.CultureInfo.InvariantCulture);
                            acc.Close(closedDate);
                        }
                        catch (FormatException)
                        {
                            Console.WriteLine("Invalid Closed date for Account ID: {0}. Today's date used instead", accountID);
                            closedDate = DateTime.Now;
                        }
                    }
                    inAccounts.Add(acc);
                }
                sr.Close();
                _AccountsFileStream.Close();
            }
            catch (Exception)
            {
                Console.WriteLine("Unable to load or read file: {0}. No data loaded.", _AccountsFileName);
            }
            return(inAccounts);
        }
Пример #3
0
        // Collects and validates input to create a new Account
        private void CreateAccount()
        {
            bool    done = false, typeOkay = false, balOkay = false;
            string  inOwnerID = "", inAccountID = "", inInitBal = "";
            uint    ownerID = 0;
            float   balance = 0.0f;
            Account acc;

            while (!done)
            {
                Console.Write("Enter Owner ID: ");
                inOwnerID = Console.ReadLine();
                ownerID   = ValidOwnerID(inOwnerID);
                if (ownerID == 0) // Not a valid ID, need to re-enter
                {
                    continue;
                }
                while (!typeOkay)
                {
                    Console.Write("Enter Account Type (1 or 2): ");
                    inAccountID = Console.ReadLine();
                    if (inAccountID == "1" || inAccountID == "2") // Account type 1 or 2
                    {
                        typeOkay = true;
                    }
                    else
                    {
                        Console.WriteLine("Invalid account type entered. Please re-enter.");
                    }
                }
                while (!balOkay)
                {
                    Console.Write("Enter Initial Balance: ");
                    inInitBal = Console.ReadLine();
                    try
                    {
                        balance = float.Parse(inInitBal);
                        if (balance > 0.0f)
                        {
                            balOkay = true;
                        }
                        else
                        {
                            Console.WriteLine("Inital balance must be greater then zero. Please re-enter.");
                        }
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Invalid initial balance entered. Please re-enter.");
                    }
                }
                Console.WriteLine("Press “s” or “S” if you want to submit ");
                Console.Write("Press any other keys if you want to cancel ");
                string menuInput = Console.ReadLine();
                if (menuInput == "S" || menuInput == "s")
                {
                    if (inAccountID == "1")
                    {
                        acc = new Type1Account(_Customers[(int)ownerID - 1], DateTime.Now, balance); // bind Type 1 Account
                    }
                    else
                    {
                        acc = new Type2Account(_Customers[(int)ownerID - 1], DateTime.Now, balance); // bind Type 2 Account
                    }
                    _Accounts.Add(acc);                                                              // Add to system collection of accounts
                    Console.WriteLine(acc);
                }
                done = true;
            }
        }