예제 #1
0
        public CurrencyRepo LoadRepo()
        {
            CurrencyRepo LoadedRepo = new CurrencyRepo();

            try
            {
                // Get all the repo data and place it in a temporary string array;
                string[] RepoLoadedData = System.IO.File.ReadAllLines(SaveLocation);

                for (int CoinPosition = 0; CoinPosition < RepoLoadedData.Length; CoinPosition++)
                {
                    // Take a single loaded item from the array and separate the components into another array for transfer
                    string[] ReadCoin = RepoLoadedData[CoinPosition].Split(',');

                    // Check if the ReadCoin is blank. If not, add to repo;
                    if (ReadCoin[0] != "")
                    {
                        switch (ReadCoin[0])
                        {
                        case "Penny":
                        {
                            Penny tempC = new Penny();
                            tempC.Year = Convert.ToInt32(ReadCoin[2]);
                            LoadedRepo.AddCoin(tempC);
                            break;
                        }

                        case "Nickel":
                        {
                            Nickel tempC = new Nickel();
                            tempC.Year = Convert.ToInt32(ReadCoin[2]);
                            LoadedRepo.AddCoin(tempC);
                            break;
                        }

                        case "Dime":
                        {
                            Dime tempC = new Dime();
                            tempC.Year = Convert.ToInt32(ReadCoin[2]);
                            LoadedRepo.AddCoin(tempC);
                            break;
                        }

                        case "Quarter":
                        {
                            Quarter tempC = new Quarter();
                            tempC.Year = Convert.ToInt32(ReadCoin[2]);
                            LoadedRepo.AddCoin(tempC);
                            break;
                        }

                        case "Half Dollar":
                        {
                            HalfDollar tempC = new HalfDollar();
                            tempC.Year = Convert.ToInt32(ReadCoin[2]);
                            LoadedRepo.AddCoin(tempC);
                            break;
                        }

                        case "Dollar Coin":
                        {
                            DollarCoin tempC = new DollarCoin();
                            tempC.Year = Convert.ToInt32(ReadCoin[2]);
                            LoadedRepo.AddCoin(tempC);
                            break;
                        }
                        }
                    }
                }
                return(LoadedRepo);
                //loadInvSuccess = true;
            }
            catch (Exception e)
            {
                // Nothing to load?
                //ALLINVENTORYINFO.Initialize();
                //loadInvSuccess = false;
                return(LoadedRepo);
            }
        }