private void AddGolferScores(Table scoreCardTable, GolferInfo golferInfo, Scoring.MatchupResults resultsA, Scoring.MatchupResults resultsB, CourseInfo courseInfo)
    {
        //Row 5
        TableRow team1APlayerRow = new TableRow();

        AddCell(team1APlayerRow, golferInfo.Aplayer1Name + " (" + golferInfo.Aplayer1Hcp.ToString() + ")", true);
        TableRow team2APlayerRow = new TableRow();

        AddCell(team2APlayerRow, golferInfo.Aplayer2Name + " (" + golferInfo.Aplayer2Hcp.ToString() + ")", true);
        TableRow team1BPlayerRow = new TableRow();

        AddCell(team1BPlayerRow, golferInfo.Bplayer1Name + " (" + golferInfo.Bplayer1Hcp.ToString() + ")", true);
        TableRow team2BPlayerRow = new TableRow();

        AddCell(team2BPlayerRow, golferInfo.Bplayer2Name + " (" + golferInfo.Bplayer2Hcp.ToString() + ")", true);

        for (int i = 0; i < 9; i++)
        {
            AddCell(team1APlayerRow, resultsA.player1Scores[i].ToString(), resultsA.whoWonHole[i] == 1, courseInfo.holeParRatings[i] > (int)resultsA.player1Scores[i]);
            AddCell(team2APlayerRow, resultsA.player2Scores[i].ToString(), resultsA.whoWonHole[i] == 2, courseInfo.holeParRatings[i] > (int)resultsA.player2Scores[i]);
            AddCell(team1BPlayerRow, resultsB.player1Scores[i].ToString(), resultsB.whoWonHole[i] == 1, courseInfo.holeParRatings[i] > (int)resultsB.player1Scores[i]);
            AddCell(team2BPlayerRow, resultsB.player2Scores[i].ToString(), resultsB.whoWonHole[i] == 2, courseInfo.holeParRatings[i] > (int)resultsB.player2Scores[i]);
        }
        AddCell(team1APlayerRow, resultsA.grossScorePlayer1.ToString(), true);
        AddCell(team2APlayerRow, resultsA.grossScorePlayer2.ToString(), true);
        AddCell(team1BPlayerRow, resultsB.grossScorePlayer1.ToString(), true);
        AddCell(team2BPlayerRow, resultsB.grossScorePlayer2.ToString(), true);

        AddCell(team1APlayerRow, resultsA.netScorePlayer1.ToString(), true);
        AddCell(team2APlayerRow, resultsA.netScorePlayer2.ToString(), true);
        AddCell(team1BPlayerRow, resultsB.netScorePlayer1.ToString(), true);
        AddCell(team2BPlayerRow, resultsB.netScorePlayer2.ToString(), true);

        AddCell(team1APlayerRow, resultsA.totalPtsPlayer1.ToString(), true);
        AddCell(team2APlayerRow, resultsA.totalPtsPlayer2.ToString(), true);
        AddCell(team1BPlayerRow, resultsB.totalPtsPlayer1.ToString(), true);
        AddCell(team2BPlayerRow, resultsB.totalPtsPlayer2.ToString(), true);

        scoreCardTable.Rows.Add(team1APlayerRow);
        scoreCardTable.Rows.Add(team2APlayerRow);
        scoreCardTable.Rows.Add(team1BPlayerRow);
        scoreCardTable.Rows.Add(team2BPlayerRow);
    }
    private string[] CreateTitleLabelTextForMatchup(GolferInfo golferNames, Scoring.MatchupResults resultsA, Scoring.MatchupResults resultsB, out Boolean APlayersTied, out Boolean BPlayersTied)
    {
        List <string> retVal = new List <string>();
        string        aPlayerString, bPlayerString;

        APlayersTied = false;
        BPlayersTied = false;
        if (resultsA.netScorePlayer1 <= resultsA.netScorePlayer2)
        {
            aPlayerString = golferNames.Aplayer1Name + " (" + resultsA.grossScorePlayer1 + ") vs. " + golferNames.Aplayer2Name + " (" + resultsA.grossScorePlayer2 + ") - ";
            if (resultsA.netScorePlayer1 == resultsA.netScorePlayer2)
            {
                APlayersTied = true;
            }
        }
        else
        {
            aPlayerString = golferNames.Aplayer2Name + " (" + resultsA.grossScorePlayer2 + ") vs. " + golferNames.Aplayer1Name + " (" + resultsA.grossScorePlayer1 + ") - ";
        }

        if (resultsB.netScorePlayer1 <= resultsB.netScorePlayer2)
        {
            bPlayerString = golferNames.Bplayer1Name + " (" + resultsB.grossScorePlayer1 + ") vs. " + golferNames.Bplayer2Name + " (" + resultsB.grossScorePlayer2 + ") - ";
            if (resultsB.netScorePlayer1 == resultsB.netScorePlayer2)
            {
                APlayersTied = true;
            }
        }
        else
        {
            bPlayerString = golferNames.Bplayer2Name + " (" + resultsB.grossScorePlayer2 + ") vs. " + golferNames.Bplayer1Name + " (" + resultsB.grossScorePlayer1 + ") - ";
        }

        retVal.Add(aPlayerString);
        retVal.Add(bPlayerString);

        return(retVal.ToArray());
    }
示例#3
0
    public static EventStats GetEventResults(int LeagueID, int LeagueEventID, Dictionary <int, int> handicaps)
    {
        EventStats retVal = new EventStats();

        retVal.initialize();

        Dictionary <int, int>          matchups       = DatabaseFunctions.GetMatchups(LeagueEventID);
        Dictionary <string, string>    LeagueSettings = DatabaseFunctions.GetLeagueSettings(LeagueID);
        Dictionary <int, List <byte> > scores         = DatabaseFunctions.GetScores(LeagueEventID);
        CourseInfo            courseInfo = DatabaseFunctions.GetCourseInfo(LeagueEventID);
        Dictionary <int, int> subs       = DatabaseFunctions.GetSubs(LeagueEventID);

        if (handicaps == null)
        {
            handicaps = Scoring.GetPlayerHandicapsForEvent(LeagueID, LeagueEventID, scores.Keys.ToList());
        }

        if (LeagueSettings.ContainsKey("MaxHandicap"))
        {
            int        maxhandicap = int.Parse(LeagueSettings["MaxHandicap"]);
            List <int> keys        = handicaps.Keys.ToList();
            foreach (int key in keys)
            {
                if (handicaps[key] > maxhandicap)
                {
                    handicaps[key] = maxhandicap;
                }
            }
        }

        int Team1PlayerA_ID, Team1PlayerB_ID, Team2PlayerA_ID, Team2PlayerB_ID;
        //Add No shows to Handicaps and scores
        var noShowScores = Scoring.GetNoShowScores(courseInfo);

        scores.Add(0, noShowScores);
        scores.Add(-1, noShowScores);
        scores.Add(-2, noShowScores);

        if (LeagueSettings.ContainsKey("NewScoring"))
        {
            handicaps.Add(0, 7);  //no show
            handicaps.Add(-1, 7); //blind1
            handicaps.Add(-2, 7); //blind2
        }
        else
        {
            handicaps.Add(0, 0);  //no show
            handicaps.Add(-1, 9); //blind1
            handicaps.Add(-2, 9); //blind2
        }

        Dictionary <int, Team> teams = DatabaseFunctions.GetTeams(LeagueID);

        int index = 0;

        //foreach matchup
        foreach (int team1ID in matchups.Keys)
        {
            Scoring.GetGolferIDs(team1ID, LeagueEventID, subs, handicaps, scores, out Team1PlayerA_ID, out Team1PlayerB_ID);
            Scoring.GetGolferIDs(matchups[team1ID], LeagueEventID, subs, handicaps, scores, out Team2PlayerA_ID, out Team2PlayerB_ID);
            Scoring.MatchupResults results_A = Scoring.GetMatchupResults(scores[Team1PlayerA_ID], scores[Team2PlayerA_ID], handicaps[Team1PlayerA_ID], handicaps[Team2PlayerA_ID], courseInfo);
            results_A.Team1PlayerID = Team1PlayerA_ID;
            results_A.Team2PlayerID = Team2PlayerA_ID;
            Scoring.MatchupResults results_B = Scoring.GetMatchupResults(scores[Team1PlayerB_ID], scores[Team2PlayerB_ID], handicaps[Team1PlayerB_ID], handicaps[Team2PlayerB_ID], courseInfo);
            results_B.Team1PlayerID = Team1PlayerB_ID;
            results_B.Team2PlayerID = Team2PlayerB_ID;
            index++;

            if (LeagueSettings.ContainsKey("SubPtsLimit"))
            {
                results_A = AdjustResultsForSubs(results_A, WasPlayerSubbing(Team1PlayerA_ID, team1ID, subs, teams), WasPlayerSubbing(Team2PlayerA_ID, matchups[team1ID], subs, teams));
                results_B = AdjustResultsForSubs(results_B, WasPlayerSubbing(Team1PlayerB_ID, team1ID, subs, teams), WasPlayerSubbing(Team2PlayerB_ID, matchups[team1ID], subs, teams));
            }

            if (LeagueSettings.ContainsKey("NewScoring"))
            {
                results_A = AdjustResultsForNoShows(results_A, Team1PlayerA_ID, Team2PlayerA_ID);
                results_B = AdjustResultsForNoShows(results_B, Team1PlayerB_ID, Team2PlayerB_ID);
            }

            if (Team1PlayerA_ID > 0)
            {
                retVal.grossScores.Add(Team1PlayerA_ID, results_A.grossScorePlayer1);
                retVal.netScores.Add(Team1PlayerA_ID, results_A.netScorePlayer1);
            }
            if (Team2PlayerA_ID > 0)
            {
                retVal.grossScores.Add(Team2PlayerA_ID, results_A.grossScorePlayer2);
                retVal.netScores.Add(Team2PlayerA_ID, results_A.netScorePlayer2);
            }
            if (Team1PlayerB_ID > 0)
            {
                retVal.netScores.Add(Team1PlayerB_ID, results_B.netScorePlayer1);
                retVal.grossScores.Add(Team1PlayerB_ID, results_B.grossScorePlayer1);
            }

            if (Team2PlayerB_ID > 0)
            {
                retVal.grossScores.Add(Team2PlayerB_ID, results_B.grossScorePlayer2);
                retVal.netScores.Add(Team2PlayerB_ID, results_B.netScorePlayer2);
            }

            int team1MedalPlayPts, team2MedalPlayPts;
            CalculateMedalPlay(out team1MedalPlayPts, out team2MedalPlayPts, results_A, results_B, LeagueSettings);

            retVal.teamPts.Add(team1ID, results_A.totalPtsPlayer1 + results_B.totalPtsPlayer1 + team1MedalPlayPts);
            retVal.teamPts.Add(matchups[team1ID], results_A.totalPtsPlayer2 + results_B.totalPtsPlayer2 + team2MedalPlayPts);
            retVal.matchupResultsA.Add(team1ID, results_A);
            retVal.matchupResultsB.Add(team1ID, results_B);
        }

        return(retVal);
    }
    private void AddCollapsablePanel(string index, GolferInfo golferNames, Scoring.MatchupResults resultsA, Scoring.MatchupResults resultsB, CourseInfo courseInfo)
    {
        Table scoreCardTable = new Table();

        AddCourseInfoRows(scoreCardTable, courseInfo);
        AddGolferScores(scoreCardTable, golferNames, resultsA, resultsB, courseInfo);

        decimal team1totalPts = 0, team2totalPts = 0;

        team1totalPts = resultsA.totalPtsPlayer1 + resultsB.totalPtsPlayer1;
        team2totalPts = resultsA.totalPtsPlayer2 + resultsB.totalPtsPlayer2;
        string medalPlayWinner = "";

        if ((resultsA.netScorePlayer1 + resultsB.netScorePlayer1) < (resultsA.netScorePlayer2 + resultsB.netScorePlayer2))
        {
            medalPlayWinner = golferNames.Team1Name + "  (" + (resultsA.netScorePlayer1 + resultsB.netScorePlayer1).ToString() + " to " + (resultsA.netScorePlayer2 + resultsB.netScorePlayer2).ToString() + ")";
            team1totalPts  += 2;
        }
        else if ((resultsA.netScorePlayer1 + resultsB.netScorePlayer1) > (resultsA.netScorePlayer2 + resultsB.netScorePlayer2))
        {
            medalPlayWinner = golferNames.Team2Name + "  (" + (resultsA.netScorePlayer2 + resultsB.netScorePlayer2).ToString() + " to " + (resultsA.netScorePlayer1 + resultsB.netScorePlayer1).ToString() + ")";
            team2totalPts  += 2;
        }
        else
        {
            team1totalPts  += 1;
            team2totalPts  += 1;
            medalPlayWinner = "Teams Tied";
        }
        //Add Row for Medal Play
        TableRow row = new TableRow();

        row.BorderStyle = BorderStyle.Solid;
        TableCell mpCell1 = AddCell(row, "Medal Play Winner (2pts): ");
        TableCell mpCell2 = AddCell(row, medalPlayWinner);

        mpCell1.ColumnSpan = 3;
        mpCell2.ColumnSpan = 10;
        mpCell1.Font.Size  = 14;
        mpCell2.Font.Size  = 14;
        mpCell1.Font.Bold  = true;
        //medalPlayCell.BorderStyle = BorderStyle.Solid;
        scoreCardTable.Rows.Add(row);

        TableRow total_pts_row = new TableRow();

        total_pts_row.BorderStyle = BorderStyle.Solid;
        TableCell c1 = AddCell(total_pts_row, "Total Pts: ");

        c1.ColumnSpan      = 1;
        c1.HorizontalAlign = HorizontalAlign.Center;
        c1.Font.Size       = 14;
        c1.Font.Bold       = true;
        TableCell c2 = AddCell(total_pts_row, golferNames.Team1Name + " " + team1totalPts.ToString() + " -----");

        c2.ColumnSpan      = 8;
        c2.HorizontalAlign = HorizontalAlign.Center;
        c2.Font.Size       = 14;
        //c2.BorderStyle = BorderStyle.Solid;

        TableCell c3 = AddCell(total_pts_row, golferNames.Team2Name + " " + team2totalPts.ToString());

        c3.ColumnSpan      = 4;
        c3.HorizontalAlign = HorizontalAlign.Center;
        c3.Font.Size       = 14;
        //c3.BorderStyle = BorderStyle.Solid;
        scoreCardTable.Rows.Add(total_pts_row);

        //Boolean AplayersTied, BplayersTied;
        //string[] titleLabelText = CreateTitleLabelTextForMatchup(golferNames, resultsA, resultsB, out AplayersTied, out BplayersTied);


        // Create Header Panel
        Panel panelHead = new Panel();

        panelHead.ID           = "pH" + index;
        panelHead.BackImageUrl = "~/images/bg-menu-main.png";


        if (resultsA.totalPtsPlayer1 > resultsA.totalPtsPlayer2)
        {
            panelHead.Controls.Add(AddTrophy());
        }
        string text = golferNames.Aplayer1Name + " (" + resultsA.grossScorePlayer1 + ") vs. ";

        panelHead.Controls.Add(CreateTitleLable(text));

        if (resultsA.totalPtsPlayer2 > resultsA.totalPtsPlayer1)
        {
            panelHead.Controls.Add(AddTrophy());
        }
        text = golferNames.Aplayer2Name + " (" + resultsA.grossScorePlayer2 + ") ----- ";
        panelHead.Controls.Add(CreateTitleLable(text));


        if (resultsB.totalPtsPlayer1 > resultsB.totalPtsPlayer2)
        {
            panelHead.Controls.Add(AddTrophy());
        }
        text = golferNames.Bplayer1Name + " (" + resultsB.grossScorePlayer1 + ") vs. ";
        panelHead.Controls.Add(CreateTitleLable(text));

        if (resultsB.totalPtsPlayer2 > resultsB.totalPtsPlayer1)
        {
            panelHead.Controls.Add(AddTrophy());
        }
        text = golferNames.Bplayer2Name + " (" + resultsB.grossScorePlayer2 + ")";
        panelHead.Controls.Add(CreateTitleLable(text));


        // Add Label inside header panel to display text
        //Label lblHead1 = new Label();
        //lblHead1.ForeColor = Color.White;
        //lblHead1.ID = "lblHeader" + index + "_1";
        //lblHead1.Font.Size = 16;
        //lblHead1.Text = titleLabelText[0];

        //Label lblHead2 = new Label();
        //lblHead2.ForeColor = Color.White;
        //lblHead2.Font.Size = 16;
        //lblHead2.ID = "lblHeader" + index + "_2";
        //lblHead2.Text = titleLabelText[1];

        //if (!AplayersTied)//if they didnt tie then the winning player is listed first, insert trophy
        //{
        //    System.Web.UI.WebControls.Image trophy1 = new System.Web.UI.WebControls.Image();
        //    trophy1.ImageUrl = "~/images/trophy4.png";

        //    //trophy1.Height = new Unit(30, UnitType.Pixel);
        //    //trophy1.Width = new Unit(20, UnitType.Pixel);
        //    //trophy1.Width = new Unit(51, UnitType.Pixel);
        //    panelHead.Controls.Add(trophy1);
        //}
        //panelHead.Controls.Add(lblHead1);

        //if (!BplayersTied)//if they didnt tie then the winning player is listed first, insert trophy
        //{
        //    System.Web.UI.WebControls.Image trophy2 = new System.Web.UI.WebControls.Image();
        //    trophy2.ImageUrl = "~/images/trophy4.png";
        //    //trophy2.Height = new Unit(60, UnitType.Pixel);
        //    panelHead.Controls.Add(trophy2);
        //}
        //panelHead.Controls.Add(lblHead2);


        System.Web.UI.WebControls.Image expandButton = new System.Web.UI.WebControls.Image();
        expandButton.ID         = "expandButton" + index;
        expandButton.ImageAlign = ImageAlign.Right;
        panelHead.Controls.Add(expandButton);
        panelHead.HorizontalAlign = HorizontalAlign.Left;


        //Create Body Panel
        Panel panelBody = new Panel();

        panelBody.ID = "pB" + index;

        // Add Label inside body Panel to display text
        //Label lblB = new Label();
        //lblB.ID = "lblBody" + index;
        //lblB.Text = "This panel was added dynamically";
        panelBody.Controls.Add(scoreCardTable);

        // Create CollapsiblePanelExtender
        CollapsiblePanelExtender cpe = new CollapsiblePanelExtender();

        cpe.ID = "cpe_" + index;
        cpe.TargetControlID   = panelBody.ID;
        cpe.ExpandControlID   = panelHead.ID;
        cpe.CollapseControlID = panelHead.ID;
        cpe.ScrollContents    = false;
        cpe.Collapsed         = true;
        cpe.ExpandDirection   = CollapsiblePanelExpandDirection.Vertical;
        cpe.SuppressPostBack  = true;
        //cpe.TextLabelID = lblHead.ID;
        cpe.ExpandedImage  = "~/images/collapse_blue.jpg";
        cpe.CollapsedImage = "~/images/expand_blue.jpg";
        cpe.ImageControlID = expandButton.ID;
        //cpe.CollapsedText = "Click to Show Content..";
        //cpe.ExpandedText = "";

        this.Panel_Matchups.ContentTemplateContainer.Controls.Add(panelHead);
        this.Panel_Matchups.ContentTemplateContainer.Controls.Add(panelBody);
        this.Panel_Matchups.ContentTemplateContainer.Controls.Add(cpe);
        this.Panel_Matchups.ContentTemplateContainer.Controls.Add(new LiteralControl("&nbsp"));
    }