protected void CreateSchedule(object sender, CommandEventArgs e) { int NumEvents = 0; //get number of events try { NumEvents = int.Parse(TextBox_NumEvents.Text); } catch { //todo: show error pop up return; } //get a list of teams (in random order) Dictionary <int, string> teamInfo = DatabaseFunctions.GetTeamNames(leagueID); Dictionary <int, List <GolfLeagueWebsiteGlobals.Matchup> > weeklyMatchups = new Dictionary <int, List <GolfLeagueWebsiteGlobals.Matchup> >(); List <string> allMatchups = new List <string>(); List <int> teamIDs = new List <int>(teamInfo.Keys); //add a bye in if there is an odd number of teams if (teamIDs.Count % 2 == 1) { teamIDs.Add(-1); } List <int> teamIDGroupOne = new List <int>(); List <int> teamIDGroupTwo = new List <int>(); teamIDGroupOne.AddRange(teamIDs.GetRange(teamIDs.Count / 2, teamIDs.Count / 2)); teamIDGroupTwo.AddRange(teamIDs.GetRange(0, teamIDs.Count / 2)); //foreach event for (int i = 0; i < NumEvents; i++) { List <GolfLeagueWebsiteGlobals.Matchup> currentWeekMatchups = new List <GolfLeagueWebsiteGlobals.Matchup>(); for (int j = 0; j < teamIDGroupOne.Count; j++) { GolfLeagueWebsiteGlobals.Matchup matchup = new GolfLeagueWebsiteGlobals.Matchup(); matchup.Team1ID = teamIDGroupOne[j]; matchup.Team2ID = teamIDGroupTwo[j]; currentWeekMatchups.Add(matchup); } weeklyMatchups.Add(i + 1, currentWeekMatchups); RotateLists(teamIDGroupOne, teamIDGroupTwo); } int SeasonID = DatabaseFunctions.GetCurrentSeasonID(leagueID.ToString()); DatabaseFunctions.SaveLeagueSchedule(weeklyMatchups, leagueID, SeasonID); }
protected void GenerateEvents(object sender, CommandEventArgs e) { int seasonID = int.Parse((string)e.CommandArgument); int NumEvents = 0; //get number of events try { NumEvents = int.Parse(TextboxNumberOfWeeksToAdd.Text); } catch { Response.Write("<script language='javascript'>alert('Must Enter Number of Events to Create.');</script>"); ModalPopupExtender2.Show();//Keep Generate Events Modal Open. return; } string teamIDsCommaSeperated = TeamsToUseValues.Value; //take out the last comma teamIDsCommaSeperated = teamIDsCommaSeperated.TrimEnd(','); string[] teamIDsSplit = teamIDsCommaSeperated.Split(','); List <int> teamIDs = new List <int>(); foreach (string teamID in teamIDsSplit) { teamIDs.Add(int.Parse(teamID)); } Dictionary <int, List <GolfLeagueWebsiteGlobals.Matchup> > weeklyMatchups = new Dictionary <int, List <GolfLeagueWebsiteGlobals.Matchup> >(); List <string> allMatchups = new List <string>(); //add a bye in if there is an odd number of teams if (teamIDs.Count % 2 == 1) { teamIDs.Add(-1); } List <int> teamIDGroupOne = new List <int>(); List <int> teamIDGroupTwo = new List <int>(); teamIDGroupOne.AddRange(teamIDs.GetRange(teamIDs.Count / 2, teamIDs.Count / 2)); teamIDGroupTwo.AddRange(teamIDs.GetRange(0, teamIDs.Count / 2)); int startingWeekIndex = DatabaseFunctions.GetEvents(leagueID, seasonID).Count; //foreach event for (int i = 0; i < NumEvents; i++) { List <GolfLeagueWebsiteGlobals.Matchup> currentWeekMatchups = new List <GolfLeagueWebsiteGlobals.Matchup>(); for (int j = 0; j < teamIDGroupOne.Count; j++) { GolfLeagueWebsiteGlobals.Matchup matchup = new GolfLeagueWebsiteGlobals.Matchup(); matchup.Team1ID = teamIDGroupOne[j]; matchup.Team2ID = teamIDGroupTwo[j]; currentWeekMatchups.Add(matchup); } weeklyMatchups.Add(i + startingWeekIndex + 1, currentWeekMatchups); RotateLists(teamIDGroupOne, teamIDGroupTwo); } DatabaseFunctions.SaveLeagueSchedule(weeklyMatchups, leagueID, seasonID); }