Пример #1
0
        /// <summary>
        /// Gets a list of available dates for a debate to be added into a list of debates.
        /// </summary>
        /// <param name="debates">The list of debates to check.</param>
        /// <param name="debate">The debate that available dates will be found for.</param>
        /// <param name="startDate">The season start date.</param>
        /// <param name="seasonLength">The length of the debate season.</param>
        /// <returns>Returns a list of DebateDate objects which hold the available dates the debate can fit in.</returns>
        public static List <DebateDate> GetAllAvailableDates(List <Debate> debates, Debate debate, DateTime startDate, int seasonLength)
        {
            List <DateTime> dates = new List <DateTime>();

            for (int i = 0; i < seasonLength; i++)
            {
                dates.Add(startDate.AddDays(7 * i));
            }
            List <Debate>[] debatesOrder = SortDebatesToPerDay(debates, dates);
            return(GetAllAvailableDates(debatesOrder, dates, debate));
        }
Пример #2
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);
 }
Пример #3
0
        /// <summary>
        /// Gets the first available date found in the list of datepairs starting at a certain index.
        /// </summary>
        /// <param name="datePairs">An array of lists where each list represents a new date.</param>
        /// <param name="d">The debate trying to be added to the date pairs.</param>
        /// <param name="startIndex">The index at which the loop begins, it will end at this index as well once it loops around.</param>
        /// <param name="listIndex">The index at which the debate can be added.</param>
        /// <param name="morning">Whether or not the debate added needs to be morning or afternoon.</param>
        /// <returns>Returns true if there was an available date, false otherwise.</returns>
        public static bool GetAvailableDate(List <Debate>[] datePairs, Debate d, int startIndex, out int listIndex, out bool morning)
        {
            bool result = GetAvailableDate(datePairs, d, startIndex, datePairs.Length, out listIndex, out morning);

            if (result)
            {
                return(result);
            }
            else
            {
                return(GetAvailableDate(datePairs, d, 0, startIndex, out listIndex, out morning));
            }
        }
Пример #4
0
        /// <summary>
        /// Creates a table row representation of a debate object.
        /// </summary>
        /// <param name="d">The debate object used to create the table row.</param>
        /// <param name="includeVersus">If true the table row will include a column between the two team names which contains a string "vs".</param>
        /// <returns>Returns a table row representation of the debate object.</returns>
        public static TableRow CreateDebateRow(Debate d, bool includeVersus, int rowNumber)
        {
            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;
            if (d.Team1Score >= 0)
            {
                team1ScoreCell.Text = d.Team1Score.ToString();
            }
            else
            {
                team1ScoreCell.Text = noScoreDisplay;
            }

            if (d.Team2Score >= 0)
            {
                team2ScoreCell.Text = d.Team2Score.ToString();
            }
            else
            {
                team2ScoreCell.Text = noScoreDisplay;
            }

            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 (includeVersus)
            {
                row.Cells.Add(vsCell);
            }
            row.Cells.Add(team2Cell);
            row.Cells.Add(team1ScoreCell);
            row.Cells.Add(team2ScoreCell);
            row.Cells.Add(dateCell);
            row.Cells.Add(morningCell);

            if (rowNumber % 2 == 0)
            {
                row.BackColor = rowColor2;
            }
            else
            {
                row.BackColor = rowColor1;
            }

            return(row);
        }
Пример #5
0
        /// <summary>
        /// Gets all the available dates in an array of list of debates.
        /// </summary>
        /// <param name="debates">The debates ordered on a per day basis.</param>
        /// <param name="dates">The dates in the debates list.</param>
        /// <param name="debate">The debate whose availability is being checked for.</param>
        /// <returns>Returns a list of DebateDates, the available dates.</returns>
        private static List <DebateDate> GetAllAvailableDates(List <Debate>[] debates, List <DateTime> dates, Debate debate)
        {
            List <DebateDate> debateDates = new List <DebateDate>();

            bool result = true;
            bool morning;
            int  index;

            while (result)
            {
                result = GetAvailableDate(debates, debate, out index, out morning);
                if (result)
                {
                    debates[index].Add(new Debate(debate.ID, debate.Team1, debate.Team2, -1, -1, dates[index], morning));
                    debateDates.Add(new DebateDate(dates[index], morning));
                }
            }

            return(debateDates);
        }
Пример #6
0
        /// <summary>
        /// Gets the first available date found in the list of date pairs.
        /// </summary>
        /// <param name="datePairs">An array of lists where each list represents a new date.</param>
        /// <param name="d">The debate trying to be added to the date pairs.</param>
        /// <param name="startIndex">The index at which the loop begins.</param>
        /// <param name="endIndex">The end at which the loop stops.</param>
        /// <param name="listIndex">The index at which the debate can be added.</param>
        /// <param name="morning">Whether or not the debate added needs to be morning or afternoon.</param>
        /// <returns>Returns true if there was an available date, false otherwise.</returns>
        public static bool GetAvailableDate(List <Debate>[] datePairs, Debate d, int startIndex, int endIndex, out int listIndex, out bool morning)
        {
            int maxDebatesPerDay = MaxMorningsPerDay + MaxAfternoonsPerDay;

            listIndex = -1;
            morning   = true;

            for (int k = startIndex; k < endIndex; k++) // each (List<Debate> debateDay in datePairs)
            {
                List <Debate> debateDay = datePairs[k]; //The current day being looked at.

                if (debateDay.Count == 0)               //If there is no debate on this day then we go ahead and use this day.
                {
                    listIndex = k;
                    return(true);
                }
                else if (debateDay.Count < maxDebatesPerDay) //If there is an available day...
                {
                    bool morningTaken   = false;
                    bool afternoonTaken = false;
                    bool conflict       = false;
                    for (int i = 0; i < debateDay.Count; i++) //We go through each debate on this day..
                    {
                        Team team1 = debateDay[i].Team1;      //Get the team 1
                        Team team2 = debateDay[i].Team2;      //Get the team 2
                        if (team1.ID == d.Team1.ID || //We check if the ids between team 1 and 2 on both debates conflict
                            team1.ID == d.Team2.ID ||
                            team2.ID == d.Team1.ID ||
                            team2.ID == d.Team2.ID)
                        {
                            if (debateDay[i].MorningDebate) //We log whether it's a morning or afternoon that is taken.
                            {
                                morningTaken = true;
                            }
                            else
                            {
                                afternoonTaken = true;
                            }
                        }

                        if (morningTaken && afternoonTaken) //Once both are taken we consider this day impossible to be free.
                        {
                            conflict = true;
                            break; //And so we move on to the next day.
                        }
                    }

                    if (!conflict)               //If there was no conflict (and so either morning or afternoon is available)
                    {
                        if (morningTaken)        //We check if the morning is impossible
                        {
                            morning = false;     //We assign an afternoon time.
                        }
                        else if (afternoonTaken) //But if it was the afternoon that is impossible
                        {
                            morning = true;      //We assign the morning.
                        }
                        listIndex = k;
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #7
0
 /// <summary>
 /// Gets the first available date found in the list of date pairs.
 /// </summary>
 /// <param name="datePairs">An array of lists where each list represents a new date.</param>
 /// <param name="d">The debate trying to be added to the date pairs.</param>
 /// <param name="listIndex">The index at which the debate can be added.</param>
 /// <param name="morning">Whether or not the debate added needs to be morning or afternoon.</param>
 /// <returns>Returns true if there was an available date, false otherwise.</returns>
 public static bool GetAvailableDate(List <Debate>[] datePairs, Debate d, out int listIndex, out bool morning)
 {
     return(GetAvailableDate(datePairs, d, 0, datePairs.Length, out listIndex, out morning));
 }
Пример #8
0
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            User loggedUser = Help.GetUserSession(Session);

            if (loggedUser != null)
            {
                ErrorLabel.Visible = false;
                for (int rowNum = 1; rowNum < Table1.Rows.Count; rowNum++) //Starts at row 1 since row 0 is header row.
                {
                    DropDownList TeamScore1Control = Table1.Rows[rowNum].Cells[3].FindControl("ddl" + rowNum) as DropDownList;
                    DropDownList TeamScore2Control = Table1.Rows[rowNum].Cells[4].FindControl("ddl#" + rowNum) as DropDownList;
                    int          team1Score        = int.Parse(TeamScore1Control.SelectedValue);
                    int          team2Score        = int.Parse(TeamScore2Control.SelectedValue);
                    int          id;
                    bool         success = int.TryParse(Table1.Rows[rowNum].Cells[6].Text, NumberStyles.Any, CultureInfo.InvariantCulture, out id);
                    Debate       debate  = debates[rowNum - 1];
                    if (team1Score >= 0 && team2Score >= 0)
                    {
                        debate.Team1Score = team1Score;
                        debate.Team2Score = team2Score;

                        bool result = DatabaseHandler.UpdateDebate(Session, debate);
                        for (int i = 0; i < debates.Count; i++)
                        {
                            if (debates[i].Team1.ID == debate.Team1.ID)
                            {
                                debates[i].Team1 = debate.Team1;
                            }
                            else if (debates[i].Team2.ID == debate.Team1.ID)
                            {
                                debates[i].Team2 = debate.Team1;
                            }
                            if (debates[i].Team1.ID == debate.Team2.ID)
                            {
                                debates[i].Team1 = debate.Team2;
                            }
                            else if (debates[i].Team2.ID == debate.Team2.ID)
                            {
                                debates[i].Team2 = debate.Team2;
                            }
                        }
                    }
                    else if (team1Score >= 0 || team2Score >= 0) //If this runs then both teams were not assigned a valid score and only one of them was.
                    {
                        ErrorLabel.Text    = "Both teams must be scored. Check Debate " + id;
                        ErrorLabel.Visible = true;
                        break; //Stops the loop so the user can fix the information before submitting the rest.
                    }
                    else //There was no score at all.
                    {
                        if (debate.Team1Score >= 0 && debate.Team2Score >= 0)
                        {
                            debate.Team1Score = team1Score;
                            debate.Team2Score = team2Score;

                            bool result = DatabaseHandler.UpdateDebate(Session, debate);
                            for (int i = 0; i < debates.Count; i++)
                            {
                                if (debates[i].Team1.ID == debate.Team1.ID)
                                {
                                    debates[i].Team1 = debate.Team1;
                                }
                                else if (debates[i].Team2.ID == debate.Team1.ID)
                                {
                                    debates[i].Team2 = debate.Team1;
                                }
                                if (debates[i].Team1.ID == debate.Team2.ID)
                                {
                                    debates[i].Team1 = debate.Team2;
                                }
                                else if (debates[i].Team2.ID == debate.Team2.ID)
                                {
                                    debates[i].Team2 = debate.Team2;
                                }
                            }
                        }
                    }
                }

                //Now we determine if there is any ties and if so we must generate a new match for each tie.
                if (DatabaseHandler.DebateSeasonScored(debateSeasonID))
                {
                    DebateSeason season              = DatabaseHandler.GetDebateSeason(debateSeasonID);
                    List <Team>  teams               = season.Teams;
                    List <Team>  rankedTeams         = Help.RankTeams(teams);
                    Debate       tieBreaker          = null;
                    DateTime     tieBreakerStartDate = seasonStartDate.AddDays((seasonLength) * 7);
                    bool         seasonUpdated       = false;
                    for (int i = 0; i < rankedTeams.Count; i++)
                    {
                        for (int j = i + 1; j < rankedTeams.Count; j++)
                        {
                            if (rankedTeams[i].Rank == 1 && rankedTeams[j].Rank == 1)
                            {
                                seasonUpdated = true;
                                tieBreaker    = new Debate(0, rankedTeams[i], rankedTeams[j], -1, -1, seasonStartDate, true);
                                int id;
                                DatabaseHandler.AddDebate(Session, tieBreaker, out id);
                                tieBreaker.ID = id;
                                season.Debates.Add(tieBreaker);
                                List <DebateDate> availableDates = new List <DebateDate>();
                                while (availableDates.Count == 0)
                                {
                                    tieBreakerStartDate = tieBreakerStartDate.AddDays(7);
                                    availableDates      = Help.GetAllAvailableDates(season.Debates, tieBreaker, tieBreakerStartDate, 1);
                                }
                                tieBreaker.MorningDebate = availableDates[0].Morning;
                                tieBreaker.Date          = availableDates[0].Date;
                                DatabaseHandler.UpdateDebate(Session, tieBreaker);
                            }
                        }
                    }

                    if (seasonUpdated)
                    {
                        TimeSpan length = tieBreakerStartDate - seasonStartDate;
                        season.Length = (length.Days / 7);
                        DatabaseHandler.UpdateDebateSeason(Session, season);
                    }
                }

                TableCell resetCell;
                for (int i = 1; i < Table1.Rows.Count; i++) //We must now reset all other reschedulings so there is not any out of date possibilities.
                {
                    resetCell = Table1.Rows[i].Cells[5];
                    DropDownList list   = resetCell.FindControl(i.ToString()) as DropDownList;
                    Label        label  = resetCell.FindControl("L" + i) as Label;
                    LinkButton   button = resetCell.FindControl("R" + i) as LinkButton;
                    if (list.Visible)
                    {
                        label.Visible = true;
                        button.Text   = "Reschedule";
                        list.Visible  = false;
                    }
                }

                if (loggedUser.PermissionLevel == 2)
                {
                    Response.Redirect(Request.RawUrl);
                }
                else
                {
                    //Do nothing because you should be the Super.
                    Help.ForcePostBack(this); //We force a post back to remove the reschedule button on scored debates.
                }
            }
        }
Пример #9
0
        private void RescheduleBut_Command(object sender, CommandEventArgs e)
        {
            int debateID;
            int rowNumber;

            ParseRescheduleString(e.CommandArgument as string, out debateID, out rowNumber);

            Debate debate = null;

            foreach (Debate d in debates)
            {
                if (d.ID == debateID)
                {
                    debate = d;
                    break;
                }
            }

            TableRow  row  = Table1.Rows[rowNumber];
            TableCell cell = row.Cells[5];

            LinkButton   but          = cell.FindControl("R" + rowNumber) as LinkButton;
            DropDownList dropDownList = cell.FindControl(rowNumber.ToString()) as DropDownList;

            dropDownList.Visible = true;
            if (but.Text == "Confirm Reschedule")
            {
                string value = dropDownList.SelectedValue;
                if (value != string.Empty)
                {
                    DateTime date;
                    bool     morning;
                    ParseDateTimeString(value, out date, out morning);
                    debate.Date          = date;
                    debate.MorningDebate = morning;
                    DatabaseHandler.UpdateDebate(Session, debate);
                }
                dropDownList.Enabled = false;
                dropDownList.Visible = false;
                but.Text             = "Reschedule";
                Help.ForcePostBack(this);
            }
            else
            {
                TableCell resetCell;
                for (int i = 1; i < Table1.Rows.Count; i++) //We must now reset all other reschedulings so there is not any out of date possibilities.
                {
                    if (i != rowNumber)                     //We do not reset the clicked row.
                    {
                        resetCell = Table1.Rows[i].Cells[5];
                        DropDownList list   = resetCell.FindControl(i.ToString()) as DropDownList;
                        Label        label  = resetCell.FindControl("L" + i) as Label;
                        LinkButton   button = resetCell.FindControl("R" + i) as LinkButton;
                        if (list.Visible)
                        {
                            label.Visible = true;
                            button.Text   = "Reschedule";
                            list.Visible  = false;
                        }
                    }
                }
                but.Text = "Confirm Reschedule";
                List <DebateDate> dates = Help.GetAllAvailableDates(debates, debate, seasonStartDate, seasonLength);
                dropDownList.Items.Clear();
                dropDownList.Enabled = true;
                ListItem listItem = new ListItem();
                listItem.Text  = "Do not reschedule.";
                listItem.Value = string.Empty;
                dropDownList.Items.Add(listItem);
                for (int i = 0; i < dates.Count; i++)
                {
                    listItem = new ListItem();
                    string morningAppend = "during the afternoon.";
                    if (dates[i].Morning)
                    {
                        morningAppend = "during the morning.";
                    }
                    listItem.Text  = dates[i].Date.ToString("MM/dd/yy") + " " + morningAppend;
                    listItem.Value = CreateDateTimeString(dates[i].Date, dates[i].Morning);
                    dropDownList.Items.Add(listItem);
                }

                ViewState["id"]      = debateID;
                ViewState["rowNumb"] = rowNumber;

                cell.Controls.Add(but);
            }
            //Help.ForcePostBack(this);
        }
Пример #10
0
        private TableRow CreateDebateRow(Debate d, int rowNum, User loggedUser)
        {
            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;
            team1ScoreCell.HorizontalAlign = HorizontalAlign.Center;
            team2ScoreCell.Width           = statsCellWidth;
            team2ScoreCell.HorizontalAlign = HorizontalAlign.Center;
            dateCell.Width           = dateCellWidth;
            dateCell.HorizontalAlign = HorizontalAlign.Center;
            //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("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;//0;
            }
            else
            {
                ddl.SelectedIndex = d.Team1Score + 1; //The + 2 is because of the 1 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("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;//0;
            }
            else
            {
                ddl1.SelectedIndex = d.Team2Score + 1; //The + 1 is because of the 1 extra index items in ddl
            }
            team2ScoreCell.Controls.Add(ddl1);

            //Creating the date cell
            DropDownList dateTimeList = new DropDownList();

            dateTimeList.Visible = false;
            dateTimeList.ID      = rowNum.ToString();
            Label dateLabel = new Label();

            dateLabel.ID = "L" + rowNum;
            if (d.MorningDebate)
            {
                dateLabel.Text = d.Date.ToString("MM/dd/yy") + " during the morning.";
            }
            else
            {
                dateLabel.Text = d.Date.ToString("MM/dd/yy") + " during the afternoon.";
            }
            dateCell.Controls.Add(dateLabel);
            dateCell.Controls.Add(dateTimeList);
            dateCell.Controls.Add(new LiteralControl("<br />"));

            if (d.Team1Score < 0 && d.Team2Score < 0 && loggedUser.PermissionLevel >= 3)
            {
                LinkButton rescheduleBut = new LinkButton();
                rescheduleBut.Text            = "Reschedule";
                rescheduleBut.ID              = "R" + rowNum;
                rescheduleBut.CommandArgument = CreateRescheduleString(d.ID, rowNum);
                rescheduleBut.Command        += RescheduleBut_Command;
                dateCell.Controls.Add(rescheduleBut);
            }
            else
            {
                dateCell.Controls.Add(new LiteralControl("<br />"));
            }

            vsCell.Text = "vs";

            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(idCell);

            rowColor++;
            if (rowColor % 2 != 0)
            {
                row.BackColor = Help.rowColor2;
            }
            else
            {
                row.BackColor = Help.rowColor1;
            }

            return(row);
        }