protected void Page_Load(object sender, EventArgs e)
        {
            int currentDebateID = Help.GetDebateSeasonID(Application);

            if (currentDebateID != -1)
            {
                //Gathering query values
                NameValueCollection queryValues = HttpUtility.ParseQueryString(Request.QueryString.ToString());
                string orderString     = queryValues.Get("Order");
                string teamOrderString = queryValues.Get("OrderTeams");

                if (orderString != null)
                {
                    order = (OrderBy)(int.Parse(orderString));
                }
                if (teamOrderString != null)
                {
                    teamOrder = (TeamOrderVar)(int.Parse(teamOrderString));
                }

                teams = DatabaseHandler.GetDebateSeasonTeams(currentDebateID);
                teams = Help.RankTeams(teams);

                teams = Help.OrderTeams(order, teamOrder, teams);

                TableRow header = CreateHeaderRow();
                Table1.Rows.Add(header);

                for (int i = 0; i < teams.Count; i++)
                {
                    TableRow teamRow = Help.CreateTeamRow(teams[i], i, i);
                    Table1.Rows.Add(teamRow);
                }
            }
            else
            {
                Panel_NoDebates.Visible = true;
                Panel2.Visible          = true;
            }
        }
Esempio n. 2
0
        protected void Button_CreateSchedule_Click(object sender, EventArgs e)
        {
            int  currentSeasonID = Help.GetDebateSeasonID(Application);
            bool seasonHasScore  = DatabaseHandler.DebateSeasonHasAScore(currentSeasonID);

            if (currentSeasonID == -1 || !seasonHasScore) //If the current debate season is -1 or if the current season does not have a score set we can create a schedule...
            {
                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(DropDownList_Weeks.SelectedValue);
                    DateTime endDate      = startDate.AddDays((seasonLength - 1) * 7);

                    //Adding the teams to the database
                    for (int i = 0; i < teams.Count; i++)
                    {
                        if (updateTeams.Count > 0 && i < updateTeams.Count)
                        {
                            teams[i].ID = updateTeams[i].ID;
                            DatabaseHandler.UpdateTeam(Session, teams[i]); //We update the team rather than creating a new one since these teams already exist in the database.
                        }
                        else
                        {
                            int id;
                            DatabaseHandler.AddTeam(Session, teams[i], out id);
                            teams[i].ID = id;
                        }
                    }

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

                    if (debates != null) //Creating the debates was successful.
                    {
                        foreach (Debate d in debates)
                        {
                            int assignedID;
                            d.Team1Score = -1;
                            d.Team2Score = -1;
                            DatabaseHandler.AddDebate(Session, d, out assignedID);
                            d.ID = assignedID;
                        }

                        int          seasonID  = currentSeasonID;
                        DebateSeason newSeason = new DebateSeason(currentSeasonID, false, teams, debates, startDate, seasonLength);

                        if (currentSeasonID == -1) //If the current season ID does not exist we create a new debate season.
                        {
                            DatabaseHandler.AddDebateSeason(Session, newSeason, out seasonID);
                        }
                        else //If the current season ID is a thing, we need to update the debate season instead.
                        {
                            DatabaseHandler.UpdateDebateSeason(Session, newSeason);
                        }

                        Help.SetDebateID(Application, seasonID);

                        Response.Redirect(Help.scheduleURL);
                    }
                    else
                    {
                        foreach (Team t in teams) //We must remove all the teams added to the database since there is no possible pairing.
                        {
                            DatabaseHandler.RemoveTeam(Session, t.ID, false);
                        }

                        Label_ScheduleError.Text    = "A debate pairing was not found. There are too many teams for " + seasonLength + " weeks. Increase the season length.";
                        Label_ScheduleError.Visible = true;
                    }
                }
            }
            else
            {
                Panel_RecreateSeason.Visible = false;
                Response.Redirect(Request.RawUrl); //We refresh the page so that the correct view of the page is shown.
            }
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ((MasterPage)Master).SetPagePermissionLevel(3);
            seasonID = Help.GetDebateSeasonID(Application);
            if (seasonID != -1)
            {
                //Creating the end debate season button.
                if (DatabaseHandler.DebateSeasonScored(seasonID))
                {
                    //The entire debate season has been scored, so let's add the option to end it.
                    Button endSeasonBut = new Button();
                    endSeasonBut.Width    = 180;
                    endSeasonBut.Height   = 45;
                    endSeasonBut.Text     = "End Debate Season";
                    endSeasonBut.Command += EndSeasonBut_Command;
                    Panel_OngoingSeason.Controls.AddAt(Panel_OngoingSeason.Controls.Count - 1, new LiteralControl("<br /> <br />"));
                    Panel_OngoingSeason.Controls.AddAt(Panel_OngoingSeason.Controls.Count - 1, endSeasonBut);
                    Panel_OngoingSeason.Controls.AddAt(Panel_OngoingSeason.Controls.Count - 1, new LiteralControl("<br />"));
                }

                bool scoreSet = DatabaseHandler.DebateSeasonHasAScore(seasonID);
                if (scoreSet) //The debate season has a score already set
                {
                    Panel_OngoingSeason.Visible = true;
                    Panel_Main.Visible          = false;
                    return;
                }
                else if (!IsPostBack)
                {
                    //We can still edit the season since no scores have been set, so let's set up the schedule generator with the info.
                    Panel_RecreateSeason.Visible = true;
                    updateTeams        = DatabaseHandler.GetDebateSeasonTeams(seasonID);
                    ViewState["teams"] = updateTeams.Count.ToString();
                    if (DropDownList_Teams.SelectedValue != currentTeam.ToString())
                    {
                        DropDownList_Teams.ClearSelection();
                        DropDownList_Teams.SelectedValue = currentTeam.ToString();
                    }
                    //Setting up the season parameters
                    int      length;
                    DateTime date = DatabaseHandler.GetDebateSeasonDateTime(seasonID, out length);
                    DropDownList_Weeks.ClearSelection();
                    DropDownList_Weeks.SelectedValue = length.ToString();
                    Calendar_Start.VisibleDate       = date;
                    Calendar_Start.SelectedDate      = date;
                }
            }

            string teams     = ViewState["teams"] as string;
            int    numbTeams = -1;
            bool   result    = int.TryParse(teams, out numbTeams);

            if (numbTeams <= 2)
            {
                numbTeams = 2;
            }
            if (numbTeams >= Help.GetMaximumTeams())
            {
                numbTeams = Help.GetMaximumTeams();
            }

            currentTeam = numbTeams;
            for (int i = 1; i <= currentTeam; i++)
            {
                AddTeamButton(i);
            }

            if (!IsPostBack && currentTeam > 2)
            {
                DropDownList_Teams.ClearSelection();
                DropDownList_Teams.Items.FindByValue((currentTeam.ToString())).Selected = true;
            }
            //DropDownList_Teams.Items.FindByValue((numbTeams.ToString())).Selected = true;
        }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int currentDebateID = Help.GetDebateSeasonID(Application);

            if (currentDebateID != -1)
            {
                minimumSeasonIndex = 2;
            }


            //Gathering query values
            NameValueCollection queryValues = HttpUtility.ParseQueryString(Request.QueryString.ToString());
            string pageString = queryValues.Get("page");

            if (pageString != null)
            {
                bool result = int.TryParse(pageString, out seasonIndex);
                if (!result) //If we could not parse the string then we reset the index.
                {
                    seasonIndex = minimumSeasonIndex;
                }
            }

            if (seasonIndex <= minimumSeasonIndex)
            {
                seasonIndex = minimumSeasonIndex;
                Button_PreviousSeason.Visible = false;
            }

            Panel_Search.Visible          = true;
            Panel_NoSearch.Visible        = false;
            Button_NextSeason.Enabled     = true;
            Button_PreviousSeason.Enabled = true;

            object teamOrderTypeObj   = ViewState["tOrderType"];  //Team order type
            object debateOrderTypeObj = ViewState["dOrderType"];  //Debate order type
            object teamOrderVarObj    = ViewState["teamOrder"];   //The order of teams
            object debateOrderVarObj  = ViewState["debateOrder"]; //The order of debates.
            object dateOrderObj       = ViewState["date"];
            object teamOrderObj       = ViewState["team"];
            object seasonObj          = ViewState["season"];

            if (debateOrderTypeObj != null)
            {
                debateOrderType = (OrderBy)(int.Parse(debateOrderTypeObj.ToString()));
            }
            if (debateOrderVarObj != null)
            {
                debateOrderVar = (DebateOrderVar)(int.Parse(debateOrderVarObj.ToString()));
            }
            if (teamOrderTypeObj != null)
            {
                teamOrderType = (OrderBy)(int.Parse(teamOrderTypeObj.ToString()));
            }
            if (teamOrderVarObj != null)
            {
                teamOrderVar = (TeamOrderVar)(int.Parse(teamOrderVarObj.ToString()));
            }

            if (seasonObj == null)
            {
                List <DebateSeason> debateSeasons = DatabaseHandler.GetDebateSeasons(seasonIndex, seasonIndex);
                if (debateSeasons.Count > 0)
                {
                    debateSeason = debateSeasons[0];
                }
                else  //No debates were found.. ut oh.
                {
                    Button_NextSeason.Visible = false;
                    Panel_PagePanel.Visible   = false;
                    Label_SeasonTitle.Text    = "No debate seasons here!";
                }
            }
            else
            {
                debateSeason = seasonObj as DebateSeason;
            }

            ViewState["season"] = debateSeason;

            if (debateSeason != null) //We do not display the current ongoing debate season.
            {
                if (debateSeason.ID != currentDebateID)
                {
                    //Setting up the enviroment
                    currentDebateSeason = debateSeason.ID;
                    DateTime startDate = debateSeason.StartDate;
                    DateTime endDate   = debateSeason.StartDate.AddDays(debateSeason.Length * 7);
                    Label_SeasonTitle.Text = "Debate Season that started on " + startDate.ToString("MM/dd/yy") + " and ended on " + endDate.ToString("MM/dd/yy");

                    //Generating the team rankings table
                    teams = debateSeason.Teams;
                    teams = Help.RankTeams(teams);

                    teams = Help.OrderTeams(teamOrderType, teamOrderVar, teams);

                    TableRow header = CreateTeamHeaderRow();
                    Table_Rankings.Rows.Add(header);

                    for (int i = 0; i < teams.Count; i++)
                    {
                        TableRow teamRow = Help.CreateTeamRow(teams[i], i, i);
                        Table_Rankings.Rows.Add(teamRow);
                    }

                    //Generating the search options and debate table...
                    if (dateOrderObj != null)
                    {
                        int  val;
                        bool result = int.TryParse(dateOrderObj.ToString(), out val);
                        if (result && val > 0 && val <= debateSeason.Length)
                        {
                            dateOrder = val;
                        }
                    }
                    if (teamOrderObj != null)
                    {
                        int  val;
                        bool result = int.TryParse(teamOrderObj.ToString(), out val);
                        if (result && val > 0 && val <= debateSeason.Teams.Count)
                        {
                            teamOrder = val;
                        }
                    }

                    debates = debateSeason.Debates;

                    debates = Help.OrderDebates(debateOrderType, debateOrderVar, debates);

                    TableRow debateHeader = CreateDebateHeaderRow();
                    TableData.Rows.Add(debateHeader);

                    seasonStart  = debateSeason.StartDate;
                    seasonLength = debateSeason.Length;

                    DateTime currentDate = seasonStart;

                    teams = debateSeason.Teams;

                    if (!IsPostBack) //We do not do this on page post backs (IE: After searches).
                    {
                        //Creating the team drop down
                        for (int i = 0; i < teams.Count; i++)
                        {
                            string   val      = (i + 1).ToString();
                            ListItem teamItem = new ListItem(teams[i].Name, val);
                            DropDownList_TeamName.Items.Add(teamItem);
                        }

                        //Creating the date drop down
                        for (int i = 1; i <= seasonLength; i++)
                        {
                            string   val      = i.ToString();
                            ListItem dateItem = new ListItem(currentDate.ToString("MM/dd/yy"), val);
                            DropDownList_Date.Items.Add(dateItem);
                            currentDate = currentDate.AddDays(7);
                        }
                    }

                    int addedRows = 0;
                    //Adding the debates to the table
                    if ((teamOrder > 0 || dateOrder > 0))
                    {
                        if (teamOrder > 0)
                        {
                            searchName = teams[(teamOrder - 1)].Name;
                            if (!IsPostBack)
                            {
                                DropDownList_TeamName.Items.FindByValue((teamOrder.ToString())).Selected = true;
                            }
                        }
                        if (dateOrder > 0)
                        {
                            searchDate = seasonStart.AddDays((dateOrder - 1) * 7);
                            if (!IsPostBack)
                            {
                                DropDownList_Date.Items.FindByValue((dateOrder.ToString())).Selected = true;
                            }
                        }

                        foreach (Debate d in debates)
                        {
                            if (dateOrder == 0 || (d.Date.Month == searchDate.Month &&
                                                   d.Date.Day == searchDate.Day &&
                                                   d.Date.Year == searchDate.Year))
                            {
                                if (teamOrder == 0 || (d.Team1.Name == searchName ||
                                                       d.Team2.Name == searchName))
                                {
                                    TableRow debateRow = Help.CreateDebateRow(d, includeVs, addedRows);
                                    TableData.Rows.Add(debateRow);
                                    addedRows++;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (Debate d in debates)
                        {
                            TableRow debateRow = Help.CreateDebateRow(d, includeVs, addedRows);
                            TableData.Rows.Add(debateRow);
                            addedRows++;
                        }
                    }
                    if (addedRows <= 0)
                    {
                        TableData.Visible      = false;
                        Panel_NoSearch.Visible = true;
                        Label_NoSearch.Text    = "No results match your search.";
                    }
                    else
                    {
                        TableData.Visible      = true;
                        Panel_NoSearch.Visible = false;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ((MasterPage)Master).SetPagePermissionLevel(2);
            User loggedUser = Help.GetUserSession(Session);

            if (loggedUser != null)
            {
                //Gathering query values
                NameValueCollection queryValues = HttpUtility.ParseQueryString(Request.QueryString.ToString());
                string orderString       = queryValues.Get("Order");
                string debateOrderString = queryValues.Get("dOrder");

                if (orderString != null)
                {
                    order = (OrderBy)(int.Parse(orderString));
                }
                if (debateOrderString != null)
                {
                    dOrder = (DebateOrderVar)(int.Parse(debateOrderString));
                }

                debateSeasonID = Help.GetDebateSeasonID(Application);

                if (debateSeasonID == -1) //There is no debate season going on.
                {
                    Panel_Info.Visible         = true;
                    Label_Info.Text            = "There is currently no ongoing debate season to score.";
                    Panel1.Visible             = false;
                    Panel_UpdateScores.Visible = false;
                    return; //We end the method here if there is no debate season/
                }
                debates = DatabaseHandler.GetDebateSeasonDebates(debateSeasonID);

                seasonStartDate = DatabaseHandler.GetDebateSeasonDateTime(debateSeasonID, out seasonLength);

                debates = Help.OrderDebates(order, dOrder, debates);

                TableRow header = CreateHeaderRow();
                Table1.Rows.Add(header);

                int rowNum = 1; // row 0 will be the header row.
                foreach (Debate d in debates)
                {
                    if (loggedUser.PermissionLevel == 2)
                    {
                        if (d.Team1Score == -1 && d.Team2Score == -1)
                        {
                            TableRow debateRow = CreateDebateRow(d, rowNum, loggedUser);
                            Table1.Rows.Add(debateRow);
                            rowNum++;
                        }
                    }
                    else if (loggedUser.PermissionLevel == 3)
                    {
                        TableRow debateRow = CreateDebateRow(d, rowNum, loggedUser);
                        Table1.Rows.Add(debateRow);
                        rowNum++;
                    }
                }

                if (Table1.Rows.Count == 1 && loggedUser.PermissionLevel < 3) //Only the header exists in the table. IE: There are no more debates to score.
                {
                    Panel_Info.Visible         = true;
                    Label_Info.Text            = "All debates have been scored, the season must now be ended by a " + Help.GetPermissionName(3);
                    Panel1.Visible             = false;
                    Panel_UpdateScores.Visible = false;
                }

                //Creating the end debate season button.
                if (loggedUser.PermissionLevel >= 3 && DatabaseHandler.DebateSeasonScored(debateSeasonID))
                {
                    //The entire debate season has been scored, so let's add the option to end it.
                    Button endSeasonBut = new Button();
                    endSeasonBut.Width    = UpdateButton.Width;
                    endSeasonBut.Height   = 20;
                    endSeasonBut.Text     = "End Debate Season";
                    endSeasonBut.Command += EndSeasonBut_Command;
                    Panel_UpdateScores.Controls.AddAt(Panel_UpdateScores.Controls.Count - 1, new LiteralControl("<br /> <br /> <br />"));
                    Panel_UpdateScores.Controls.AddAt(Panel_UpdateScores.Controls.Count - 1, endSeasonBut);
                    Panel_UpdateScores.Controls.AddAt(Panel_UpdateScores.Controls.Count - 1, new LiteralControl("<br />"));
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int currentDebateID = Help.GetDebateSeasonID(Application);

            Panel_Searching.Visible = true;
            Panel_NoDebate.Visible  = false;

            if (currentDebateID != -1)
            {
                object orderObj       = ViewState["Order"];
                object debateOrderObj = ViewState["dOrder"];
                object dateOrderObj   = ViewState["date"];
                object teamOrderObj   = ViewState["team"];

                if (orderObj != null)
                {
                    order = (OrderBy)(int.Parse(orderObj.ToString()));
                }
                if (debateOrderObj != null)
                {
                    dOrder = (DebateOrderVar)(int.Parse(debateOrderObj.ToString()));
                }

                object savedSeason = ViewState["Season"];

                if (savedSeason == null)
                {
                    debateSeason = DatabaseHandler.GetDebateSeason(currentDebateID);
                }
                else
                {
                    debateSeason = savedSeason as DebateSeason;
                }

                ViewState["Season"] = debateSeason;

                if (dateOrderObj != null)
                {
                    int  val;
                    bool result = int.TryParse(dateOrderObj.ToString(), out val);
                    if (result && val > 0 && val <= debateSeason.Length)
                    {
                        dateOrder = val;
                    }
                }
                if (teamOrderObj != null)
                {
                    int  val;
                    bool result = int.TryParse(teamOrderObj.ToString(), out val);
                    if (result && val > 0 && val <= debateSeason.Teams.Count)
                    {
                        teamOrder = val;
                    }
                }

                debates = debateSeason.Debates;

                debates = Help.OrderDebates(order, dOrder, debates);

                TableRow header = CreateHeaderRow();
                Table1.Rows.Add(header);

                seasonStart  = debateSeason.StartDate;
                seasonLength = debateSeason.Length;

                DateTime currentDate = seasonStart;

                teams = debateSeason.Teams;

                if (!IsPostBack) //We do not do this on page post backs (IE: After searches).
                {
                    //Creating the team drop down
                    for (int i = 0; i < teams.Count; i++)
                    {
                        string   val      = (i + 1).ToString();
                        ListItem teamItem = new ListItem(teams[i].Name, val);
                        DropDownList_TeamName.Items.Add(teamItem);
                    }

                    //Creating the date drop down
                    for (int i = 1; i <= seasonLength; i++)
                    {
                        string   val      = i.ToString();
                        ListItem dateItem = new ListItem(currentDate.ToString("MM/dd/yy"), val);
                        DropDownList_Date.Items.Add(dateItem);
                        currentDate = currentDate.AddDays(7);
                    }
                }

                int addedRows = 0;
                //Adding the debates to the table
                if ((teamOrder > 0 || dateOrder > 0))
                {
                    if (teamOrder > 0)
                    {
                        searchName = teams[(teamOrder - 1)].Name;
                        if (!IsPostBack)
                        {
                            DropDownList_TeamName.Items.FindByValue((teamOrder.ToString())).Selected = true;
                        }
                    }
                    if (dateOrder > 0)
                    {
                        searchDate = seasonStart.AddDays((dateOrder - 1) * 7);
                        if (!IsPostBack)
                        {
                            DropDownList_Date.Items.FindByValue((dateOrder.ToString())).Selected = true;
                        }
                    }

                    foreach (Debate d in debates)
                    {
                        if (dateOrder == 0 || (d.Date.Month == searchDate.Month &&
                                               d.Date.Day == searchDate.Day &&
                                               d.Date.Year == searchDate.Year))
                        {
                            if (teamOrder == 0 || (d.Team1.Name == searchName ||
                                                   d.Team2.Name == searchName))
                            {
                                TableRow debateRow = Help.CreateDebateRow(d, true, addedRows);
                                Table1.Rows.Add(debateRow);
                                addedRows++;
                            }
                        }
                    }
                }
                else
                {
                    foreach (Debate d in debates)
                    {
                        TableRow debateRow = Help.CreateDebateRow(d, true, addedRows);
                        Table1.Rows.Add(debateRow);
                        addedRows++;
                    }
                }
                if (addedRows <= 0)
                {
                    Table1.Visible         = false;
                    Panel_NoDebate.Visible = true;
                    Label_NoSchedule.Text  = "No results match your search.";
                }
                else
                {
                    Table1.Visible         = true;
                    Panel_NoDebate.Visible = false;
                }
            }
            else
            {
                Panel_Searching.Visible = false;
                Panel_NoDebate.Visible  = true;
            }
        }