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);
            }
        }
        private TableRow CreateDebateRow(Debate d)
        {
            TableRow row = new TableRow();

            TableCell team1Cell      = new TableCell();
            TableCell team2Cell      = new TableCell();
            TableCell team1ScoreCell = new TableCell();
            TableCell team2ScoreCell = new TableCell();
            TableCell dateCell       = new TableCell();
            TableCell morningCell    = new TableCell();
            TableCell vsCell         = new TableCell();

            team1Cell.Width           = nameCellWidth;
            team1Cell.HorizontalAlign = HorizontalAlign.Center;
            team2Cell.Width           = nameCellWidth;
            team2Cell.HorizontalAlign = HorizontalAlign.Center;
            team1ScoreCell.Width      = statsCellWidth;
            team2ScoreCell.Width      = statsCellWidth;
            dateCell.Width            = dateCellWidth;
            morningCell.Width         = dateCellWidth;
            vsCell.Width           = vsCellWidth;
            vsCell.HorizontalAlign = HorizontalAlign.Center;

            team1Cell.Text      = d.Team1.Name;
            team2Cell.Text      = d.Team2.Name;
            team1ScoreCell.Text = d.Team1Score.ToString();
            team2ScoreCell.Text = d.Team2Score.ToString();
            dateCell.Text       = d.Date.ToString("MM/dd/yy");

            vsCell.Text = "vs";

            if (d.MorningDebate)
            {
                morningCell.Text = "Morning";
            }
            else
            {
                morningCell.Text = "Afternoon";
            }

            row.Cells.Add(team1Cell);
            if (includeVs)
            {
                row.Cells.Add(vsCell);
            }
            row.Cells.Add(team2Cell);
            row.Cells.Add(team1ScoreCell);
            row.Cells.Add(team2ScoreCell);
            row.Cells.Add(dateCell);
            row.Cells.Add(morningCell);


            return(row);
        }
Exemplo n.º 3
0
 /// <summary>
 ///Replaces a debate within the debate season.
 /// </summary>
 /// <param name="id">The id of the debate to replace.</param>
 /// <param name="newDebate">The new debate to replace with.</param>
 /// <returns>Returns true if the debate was replaced. False otherwise.</returns>
 public bool ReplaceDebate(int id, Debate newDebate)
 {
     for (int i = 0; i < debates.Count; i++)
     {
         if (debates[i].ID == id)
         {
             debates[i] = newDebate;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets Debate Id, Score1, and Score2 from the DropDownBoxes and updates the debate with the correct Id.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            int    DebateID = Int32.Parse(DropDownList3.SelectedValue);
            int    Score1   = Int32.Parse(DropDownList1.SelectedValue);
            int    Score2   = Int32.Parse(DropDownList2.SelectedValue);
            Debate debate   = DatabaseHandler.GetDebate(DebateID);

            debate.Team1Score = Score1;
            debate.Team2Score = Score2;

            DatabaseHandler.UpdateDebate(Session, debate);
        }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            User loggedUser = Help.GetUserSession(Session);

            for (int rowNum = 1; rowNum < Table1.Rows.Count; rowNum++) //Starts at row 1 since row 0 is header row.
            {
                int          id;
                bool         success           = int.TryParse(Table1.Rows[rowNum].Cells[7].Text, NumberStyles.Any, CultureInfo.InvariantCulture, out id);
                Debate       debate            = DatabaseHandler.GetDebate(id);
                DropDownList TeamScore1Control = Table1.Rows[rowNum].Cells[3].FindControl("ddl" + rowNum) as DropDownList;
                DropDownList TeamScore2Control = Table1.Rows[rowNum].Cells[4].FindControl("ddl#" + rowNum) as DropDownList;
                debate.Team1Score = Int32.Parse(TeamScore1Control.SelectedValue);
                debate.Team2Score = Int32.Parse(TeamScore2Control.SelectedValue);
                bool result = DatabaseHandler.UpdateDebate(Session, debate);
            }
            if (loggedUser.PermissionLevel == 2)
            {
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                //Do nothing because you should be the Super.
            }
        }
        private TableRow CreateDebateRow(Debate d, int rowNum)
        {
            TableRow row = new TableRow();

            TableCell team1Cell      = new TableCell();
            TableCell team2Cell      = new TableCell();
            TableCell team1ScoreCell = new TableCell();
            TableCell team2ScoreCell = new TableCell();
            TableCell dateCell       = new TableCell();
            TableCell morningCell    = new TableCell();
            TableCell vsCell         = new TableCell();
            TableCell idCell         = new TableCell();

            team1Cell.Width           = nameCellWidth;
            team1Cell.HorizontalAlign = HorizontalAlign.Center;
            team2Cell.Width           = nameCellWidth;
            team2Cell.HorizontalAlign = HorizontalAlign.Center;
            team1ScoreCell.Width      = statsCellWidth;
            team2ScoreCell.Width      = statsCellWidth;
            dateCell.Width            = dateCellWidth;
            morningCell.Width         = dateCellWidth;
            vsCell.Width           = vsCellWidth;
            vsCell.HorizontalAlign = HorizontalAlign.Center;
            idCell.Width           = statsCellWidth;
            idCell.HorizontalAlign = HorizontalAlign.Center;

            team1Cell.Text = d.Team1.Name;
            team2Cell.Text = d.Team2.Name;
            DropDownList ddl = new DropDownList();

            ddl.ID = "ddl" + rowNum;
            ddl.Items.Add(new ListItem("", "-1"));         //Unscored value
            ddl.Items.Add(new ListItem("Forfeit", "-99")); // add list items
            ddl.Items.Add(new ListItem("0", "0"));
            ddl.Items.Add(new ListItem("1", "1"));
            ddl.Items.Add(new ListItem("2", "2"));
            ddl.Items.Add(new ListItem("3", "3"));
            ddl.Items.Add(new ListItem("4", "4"));
            ddl.Items.Add(new ListItem("5", "5"));
            if (d.Team1Score == -1)
            {
                ddl.SelectedIndex = 0;
            }
            else if (d.Team1Score == -99)
            {
                ddl.SelectedIndex = 1;
            }
            else
            {
                ddl.SelectedIndex = d.Team1Score + 2; //The + 2 is because of the 2 extra index items in ddl
            }
            team1ScoreCell.Controls.Add(ddl);

            DropDownList ddl1 = new DropDownList();

            ddl1.ID = "ddl#" + rowNum;
            ddl1.Items.Add(new ListItem("", "-1"));         //Unscored value
            ddl1.Items.Add(new ListItem("Forfeit", "-99")); // add list items
            ddl1.Items.Add(new ListItem("0", "0"));
            ddl1.Items.Add(new ListItem("1", "1"));
            ddl1.Items.Add(new ListItem("2", "2"));
            ddl1.Items.Add(new ListItem("3", "3"));
            ddl1.Items.Add(new ListItem("4", "4"));
            ddl1.Items.Add(new ListItem("5", "5"));
            if (d.Team2Score == -1)
            {
                ddl1.SelectedIndex = 0;
            }
            else if (d.Team2Score == -99)
            {
                ddl1.SelectedIndex = 1;
            }
            else
            {
                ddl1.SelectedIndex = d.Team2Score + 2; //The + 2 is because of the 2 extra index items in ddl
            }
            team2ScoreCell.Controls.Add(ddl1);
            dateCell.Text = d.Date.ToString("MM/dd/yy");

            vsCell.Text = "vs";

            if (d.MorningDebate)
            {
                morningCell.Text = "Morning";
            }
            else
            {
                morningCell.Text = "Afternoon";
            }

            idCell.Text = "" + d.ID;

            row.Cells.Add(team1Cell);
            if (includeVs)
            {
                row.Cells.Add(vsCell);
            }
            row.Cells.Add(team2Cell);
            row.Cells.Add(team1ScoreCell);
            row.Cells.Add(team2ScoreCell);
            row.Cells.Add(dateCell);
            row.Cells.Add(morningCell);
            row.Cells.Add(idCell);


            return(row);
        }