コード例 #1
0
        protected void Button_CreateSchedule_Click(object sender, EventArgs e)
        {
            bool errorOccured = false;

            List <Team> teams = GetTeams();

            if (nameError)
            {
                Label_ScheduleError.Text    = "There are errors with the info given. Some team names are invalid.";
                Label_ScheduleError.Visible = true;
                errorOccured = true;
            }

            if (Calendar_Start.SelectedDates.Count <= 0)
            {
                Label_ScheduleError.Text    = "There are errors with the info given. There is no start date specified.";
                Label_ScheduleError.Visible = true;
                errorOccured = true;
            }

            if (!errorOccured)
            {
                Label_ScheduleError.Visible = false;
                //Generate schedule:
                DateTime startDate    = Calendar_Start.SelectedDate;
                int      seasonLength = int.Parse(DropDownList1.SelectedValue);
                DateTime endDate      = startDate.AddDays((seasonLength - 1) * 7);

                //Adding the teams to the database
                foreach (Team t in teams)
                {
                    int id;
                    DatabaseHandler.AddTeam(Session, t, out id);
                    t.ID = id;
                }

                //Creating the actual debates
                List <DateTime> saturdays = Help.SatBetween(startDate, endDate);
                List <TeamPair> pairs     = Help.MatchMake(saturdays, teams);
                List <Debate>   debates   = new List <Debate>();

                foreach (TeamPair p in pairs)
                {
                    Debate debate = p as Debate;
                    int    assignedID;
                    DatabaseHandler.AddDebate(Session, p, out assignedID);
                    debate.ID = assignedID;
                    debates.Add(debate);
                }

                int          seasonID;
                DebateSeason newSeason = new DebateSeason(0, false, teams, debates);
                //int test = DatabaseHandler.GetLatestSeasonID();
                DatabaseHandler.AddDebateSeason(Session, newSeason, out seasonID);

                Help.SetDebateID(Application, seasonID);

                Response.Redirect(Help.scheduleURL);
            }
        }