예제 #1
0
        /// <summary>
        /// Refreshes the page with a new order for the table on page load.
        /// </summary>
        /// <param name="debateOrderVar">The variable to order debates by.</param>
        private void RedirectWithParameters(DebateOrderVar debateOrderVar)
        {
            if (this.debateOrderVar == debateOrderVar && debateOrderType != OrderBy.Descending) //If team order is already by name, then we flip them.
            {
                ViewState["dOrderType"] = (int)OrderBy.Descending;
            }
            else
            {
                ViewState["dOrderType"] = (int)OrderBy.Ascending;
            }

            ViewState["debateOrder"] = (int)teamOrderVar;

            dateOrder = int.Parse(DropDownList_Date.SelectedValue);
            teamOrder = int.Parse(DropDownList_TeamName.SelectedValue);

            ViewState["date"]         = dateOrder;
            ViewState["team"]         = teamOrder;
            ViewState["seasonID"]     = seasonIndex;
            ViewState["tOrderType"]   = (int)debateOrderType;
            ViewState["debateOrder"]  = (int)debateOrderVar;
            ViewState["prevSeasonID"] = seasonIndex;

            Help.ForcePostBack(this);
        }
예제 #2
0
        protected void DropDownList_Teams_SelectedIndexChanged(object sender, EventArgs e)
        {
            int val = int.Parse(DropDownList_Teams.SelectedValue);

            currentTeam = val;

            ViewState["teams"] = currentTeam.ToString();
            Help.ForcePostBack(this);
        }
예제 #3
0
        protected void Button_Search_Click(object sender, EventArgs e)
        {
            dateOrder = int.Parse(DropDownList_Date.SelectedValue);
            teamOrder = int.Parse(DropDownList_TeamName.SelectedValue);

            ViewState["date"] = dateOrder;
            ViewState["team"] = teamOrder;

            Help.ForcePostBack(this);
        }
예제 #4
0
        /// <summary>
        /// Refreshes the page with a new order for the table on page load.
        /// </summary>
        /// <param name="debateOrderVar"></param>
        private void RedirectWithParameters(DebateOrderVar debateOrderVar)
        {
            if (dOrder == debateOrderVar && order != OrderBy.Descending) //If team order is already by name, then we flip them.
            {
                ViewState["Order"] = (int)OrderBy.Descending;
            }
            else
            {
                ViewState["Order"] = (int)OrderBy.Ascending;
            }

            dateOrder = int.Parse(DropDownList_Date.SelectedValue);
            teamOrder = int.Parse(DropDownList_TeamName.SelectedValue);

            ViewState["dOrder"] = (int)debateOrderVar;
            ViewState["date"]   = dateOrder;
            ViewState["team"]   = teamOrder;

            Help.ForcePostBack(this);
        }
예제 #5
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.
                }
            }
        }
예제 #6
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);
        }