Exemplo n.º 1
0
        /******************************************************************
        *          OPERATIONS - READ IN LEAGUE & FIXTURE DATA             *
        ******************************************************************/
        public static void readFootball(string theFile, ArrayList allLeaguesandFixtures)
        {
            // local variables
            StreamReader inLeagues = null;
            bool         anyMoreLeaguesAndFixtures = false;

            string[] leagueData  = new string[frmMainMenu.numLeagueItems];
            string[] FixtureData = new string[frmMainMenu.numFixtureItems];
            League   tempLeague;
            Fixture  tempFixture;
            int      numFixturesInLeagues;

            // if the file opened without error then...
            if (Operations.fileOpenForReadOK(theFile, ref inLeagues))
            {
                // read the first League Fixtures
                anyMoreLeaguesAndFixtures = Operations.getNext(frmMainMenu.numLeagueItems, inLeagues, leagueData);

                // loop through for all League's in file
                while (anyMoreLeaguesAndFixtures == true)
                {
                    try
                    {
                        numFixturesInLeagues = Convert.ToInt32(leagueData[3]);      // last item is num of teams

                        // LEAGUE ORDER = leagueName, leagueSponsor, leaguePrize, leagueNumFixtures
                        tempLeague = new League(leagueData[0], leagueData[1], leagueData[2], Convert.ToInt32(leagueData[3]));

                        // Read all Fixture's into the League
                        for (int i = 0; i < numFixturesInLeagues; i++)
                        {
                            getNext(frmMainMenu.numFixtureItems, inLeagues, FixtureData);

                            // Fixture order = fixtureData, fixtureTime, fixtureLocation, fixtureHomeTeam, fixtureAwayTeam
                            tempFixture = new Fixture(FixtureData[0], FixtureData[1], FixtureData[2], FixtureData[3], FixtureData[4]);

                            tempLeague.addFixtureToLeague(tempLeague.getAllLeagueFixtures(), tempFixture);
                        }

                        // add the league and its fixtures into the data-structure
                        allLeaguesandFixtures.Add(tempLeague);
                        //tempLeague.addLeagueToLeague(tempLeague.getAllLeagues(), tempLeague);

                        anyMoreLeaguesAndFixtures = getNext(frmMainMenu.numLeagueItems, inLeagues, leagueData);
                    }
                    catch (FormatException)
                    {
                        break;
                    }
                }
            }

            // close the streamReader
            if (inLeagues != null)
            {
                inLeagues.Close();
            }

            //   foreach (League L in allLeaguesandFixtures)
            // {

            //   L.addLeagueToLeague(L.getAllLeagues(), L);


            //    }
        } // end read books