/****************************************************************** * OPERATIONS - REMOVE FIXTURES FROM TEAMS * ******************************************************************/ public static void removeTeamFixtures(League whichLeague, Team deleteTeam, int fixtureDeleteCounter) { // loop through all fixtures in the league... foreach (Fixture F in whichLeague.getAllLeagueFixtures().ToArray()) { // if the home team names match then remove the team and all its selected fixtures... if (F.getFixtureHomeTeam().Contains(deleteTeam.getTeamName())) { whichLeague.deleteFixture(whichLeague.getAllLeagueFixtures(), F, fixtureDeleteCounter); fixtureDeleteCounter -= 1; } // if the away team names match then remove the team and all its selected fixtures... if (F.getFixtureAwayTeam().Contains(deleteTeam.getTeamName())) { whichLeague.deleteFixture(whichLeague.getAllLeagueFixtures(), F, fixtureDeleteCounter); fixtureDeleteCounter -= 1; } // otherwise increment the deletion counter... fixtureDeleteCounter += 1; } // rewrite the text file without the selected team... Operations.writeAllFixtures(frmMainMenu.inputFootball, frmMainMenu.allLeagues); }
/****************************************************************** * OPERATIONS - DELETE PROCESSED FIXTURE * ******************************************************************/ public static void deletePlayedFixture(League whichLeague, Fixture whichFixture) { whichLeague = (League)frmMainMenu.allLeagues[frmMainMenu.leagueSelected]; var theLeagues = whichLeague.getAllLeagueFixtures(); // loop through each fixture in 'theLeagues', convert to array to prevent // the Enumerator changed error exception to be thrown by compiler... foreach (Fixture f in theLeagues.ToArray()) { // Get the correct fixture... if (f.getFixtureHomeTeam() == whichFixture.getFixtureHomeTeam() && f.getFixtureAwayTeam() == whichFixture.getFixtureAwayTeam()) { // otherwise delete the item at the selected index... whichLeague.getAllLeagueFixtures().RemoveAt(frmMainMenu.fixtureSelected); Operations.writeAllLeagues(frmMainMenu.inputFootball, frmMainMenu.allLeagues); Operations.writeAllFixtures(frmMainMenu.inputFootball, frmMainMenu.allLeagues); // prompt the user that the fixture has been deleted... MessageBox.Show("Success - The Fixture: " + f.getFixtureHomeTeam() + " vs " + f.getFixtureAwayTeam() + " has been deleted.", "Fixture Deleted"); } } }
/****************************************************************** * EDIT FIXTURE - GET THE FIXTURE DETAILS * ******************************************************************/ private void getFixtureDetails() { try { // local variables... int selectedLeague = frmMainMenu.leagueSelected; int selectedFixture = frmMainMenu.fixtureSelected; ArrayList allOfTheLeagues = frmMainMenu.allLeagues; League currentLeague = (League)allOfTheLeagues[selectedLeague]; Fixture currentFixture = (Fixture)currentLeague.getAllLeagueFixtures()[selectedFixture]; // set input fields to the currentFixture details... cboLeagues.Text = currentLeague.getLeagueName(); txtFixtureDate.Text = currentFixture.getFixtureDate(); txtFixtureTime.Text = currentFixture.getFixtureTime(); txtFixtureLocation.Text = currentFixture.getFixtureLocation(); cboHomeTeam.Text = currentFixture.getFixtureHomeTeam(); cboAwayTeam.Text = currentFixture.getFixtureAwayTeam(); // loop through each team in allTeams... foreach (Team t in frmMainMenu.allTeams) { // check to see if the right home team has been selected... if (t.getTeamName().ToString() == cboHomeTeam.Text) { // render the left panel using t's details... renderHome(t); } // check to see if the right away team is selected if (t.getTeamName().ToString() == cboAwayTeam.Text) { // render the left panel using t's details... renderAway(t); } } } catch (IndexOutOfRangeException) { } catch (Exception) { MessageBox.Show("Please select a fixture from the list before trying to edit one.", "Operation Failed"); } }
/****************************************************************** * EDIT FIXTURE - EDIT THE FIXTURE * ******************************************************************/ private void btnEditFixture_Click(object sender, EventArgs e) { // local variables... bool validationCheck = false; League whichLeague = (League)frmMainMenu.allLeagues[frmMainMenu.leagueSelected]; // initialisation... // FIXTURE ORDER = fixtureLeague, fixtureDate, fixtureTime, fixtureLocation, fixtureHomeTeam, fixtureAwayTeam string tempFixtureLeague = cboLeagues.Text; string tempFixtureDate = txtFixtureDate.Text; string tempFixtureTime = txtFixtureTime.Text; string tempFixtureLocation = txtFixtureLocation.Text; string tempFixtureHomeTeam = cboHomeTeam.Text; string tempFixtureAwayTeam = cboAwayTeam.Text; // do validation... validationCheck = cboLeagues != null && Operations.notNullTextBox(txtFixtureDate, "the fixture date") && Operations.notNullTextBox(txtFixtureTime, "the fixture time") && Operations.notNullTextBox(txtFixtureLocation, "the fixtures location") && cboHomeTeam != null && cboAwayTeam != null; // if the validation returns true then... if (validationCheck) { // create the tempFixture object... Fixture tempFixture = new Fixture(tempFixtureDate, tempFixtureTime, tempFixtureLocation, tempFixtureHomeTeam, tempFixtureAwayTeam); // use the replaceFixture method (in League) to replace team, then rewrite file... whichLeague.replaceFixture(whichLeague.getAllLeagueFixtures(), tempFixture, frmMainMenu.fixtureSelected); Operations.writeAllFixtures(frmMainMenu.inputFootball, frmMainMenu.allLeagues); // prompt the user of success and reset the form... MessageBox.Show("SUCCESS: The fixture has been amended, " + tempFixtureHomeTeam + " shall play " + tempFixtureAwayTeam + " on " + tempFixtureDate + " at " + tempFixtureTime + " at " + tempFixtureLocation + "."); resetForm(); } }
/****************************************************************** * 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