private void populateKnockoutTables()
        {
            DataTable table = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutTeams);
            int       count = 0;

            foreach (string eventName in m_selectedEventNames)
            {
                for (int i = 0; i < m_dataViews[eventName].Count; ++i)
                {
                    if (m_selectedTeams[m_currentTabNumber][eventName][i])
                    {
                        DataRow dRow = m_dataViews[eventName][i].Row;
                        int     originalTeamNumber = AccessDatabaseUtilities.getIntValue(dRow, "Team_Number");
                        string  teamName           = AccessDatabaseUtilities.getStringValue(dRow, "Team_Name");
                        string  memberNames        = AccessDatabaseUtilities.getStringValue(dRow, "Member_Names");
                        int     teamNumber         = count + 1;
                        DataRow newRow             = table.Rows[count];
                        newRow["Team_Number"]          = teamNumber;
                        newRow["Team_Name"]            = teamName;
                        newRow["Member_Names"]         = memberNames;
                        newRow["Original_Team_Number"] = originalTeamNumber;
                        newRow["Original_Event_Name"]  = eventName;
                        count++;
                    }
                }
            }
            AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.KnockoutTeams);
        }
        private static double getDoubleValue(DataRow dRow, string columnName)
        {
            string value    = AccessDatabaseUtilities.getStringValue(dRow, columnName);
            string newValue = value.Replace("\"", "");

            return(string.IsNullOrWhiteSpace(newValue) ? 0 : double.Parse(newValue));
        }
Ejemplo n.º 3
0
        private void setUpMatches(int roundNumber)
        {
            DataTable table = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + roundNumber);
            // Overwrite existing team numbers to avoid unique value errors
            int count = -1;

            foreach (DataRow dRow in table.Rows)
            {
                dRow["Team_Number"] = count--;
            }
            AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + roundNumber);
            DataTable previousTable = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + (roundNumber + 1));
            int       matchNumber   = 1;

            foreach (DataRow dRow in table.Rows)
            {
                DataRow[] dRows     = previousTable.Select("Match_Number = " + matchNumber);
                DataRow   winnerRow = findWinner(dRows);
                dRow["Team_Number"] = AccessDatabaseUtilities.getIntValue(winnerRow, "Team_Number");
                dRow["Team_Name"]   = AccessDatabaseUtilities.getStringValue(winnerRow, "Team_Name");
                matchNumber++;
            }
            AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + roundNumber);
            knockoutRoundsCombobox.SelectedIndex = roundNumber - 1;
        }
Ejemplo n.º 4
0
        private string getTeamLink(Object teamNumberObject, bool showNumber, bool showName)
        {
            string result = "";

            if (teamNumberObject == DBNull.Value)
            {
                return("-");
            }
            int       teamNumber = (int)teamNumberObject;
            DataTable table      = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutTeams);

            DataRow[] dRows = table.Select("Team_Number = " + teamNumber);
            Debug.Assert(dRows.Length == 1);
            DataRow dRow = dRows[0];
            string  originalEventName = AccessDatabaseUtilities.getStringValue(dRow, "Original_Event_Name");

            if (string.IsNullOrWhiteSpace(originalEventName))
            {
                result = "<span title='" + dRow["Member_Names"] + "' >" + (showNumber ? dRow["Team_Number"] + " " : "") + (showName ? dRow["Team_Name"] : "") + "</span>";
            }
            else
            {
                int originalTeamNumber = AccessDatabaseUtilities.getIntValue(dRow, "Original_Team_Number");
                //string webpagesRootDirectory = Path.Combine("..", "..", Constants.WebpagesFolderName, Utilities.makeIdentifier_(originalEventName));
                //string link = Path.Combine(webpagesRootDirectory, "teams", "team" + originalTeamNumber + "score.html");
                string webpagesRootDirectory = "../" + Utilities.makeIdentifier_(originalEventName);
                string link = webpagesRootDirectory + "/teams/team" + originalTeamNumber + "score.html";
                result = "<a href='" + link + "' title='" + dRow["Member_Names"] + "'>" + (showNumber ? dRow["Team_Number"] + " " : "") + (showName ? dRow["Team_Name"] : "") + "</a>";
            }
            return(result);
        }
        private void populateSwissLeagueTables(int numberOfRounds, int numberOfTeams)
        {
            DataTable table = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.EventNames);
            int       count = 1;
            DataTable computedScoresTable = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.EventComputedScores);

            foreach (string eventName in m_selectedEventNames)
            {
                for (int i = 0; i < m_dataViews[eventName].Count; ++i)
                {
                    if (m_selectedTeams[m_currentTabNumber][eventName][i])
                    {
                        DataRow dRow = m_dataViews[eventName][i].Row;
                        int     originalTeamNumber = AccessDatabaseUtilities.getIntValue(dRow, "Team_Number");
                        string  teamName           = AccessDatabaseUtilities.getStringValue(dRow, "Team_Name");
                        string  memberNames        = AccessDatabaseUtilities.getStringValue(dRow, "Member_Names");
                        double  totalScore         = AccessDatabaseUtilities.getDoubleValue(dRow, "Total_Score");
                        int     teamNumber         = count;
                        DataRow newRow             = table.NewRow();
                        newRow["Team_Number"]          = keepOriginalTeamNumbersCheckbox.Checked?originalTeamNumber:teamNumber;
                        newRow["Team_Name"]            = teamName;
                        newRow["Member_Names"]         = memberNames;
                        newRow["Carryover"]            = carryoverTotalCheckbox.Checked ? totalScore : 0;
                        newRow["Original_Team_Number"] = originalTeamNumber;
                        newRow["Original_Event_Name"]  = eventName;
                        newRow["Total_Score"]          = 0;
                        newRow["Tiebreaker_Score"]     = 0;
                        newRow["Rank"] = 1;
                        table.Rows.Add(newRow);
                        newRow = computedScoresTable.NewRow();
                        newRow["Team_Number"] = keepOriginalTeamNumbersCheckbox.Checked ? originalTeamNumber : teamNumber;
                        computedScoresTable.Rows.Add(newRow);
                        count++;
                    }
                }
                DataTable scoresTable     = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.EventScores);
                int       numberOfMatches = (numberOfTeams / 2) + numberOfTeams % 2;
                for (int i = 1; i <= numberOfRounds; ++i)
                {
                    for (int j = 1; j <= numberOfMatches; ++j)
                    {
                        DataRow dRow = scoresTable.NewRow();
                        dRow["Table_Number"] = j;
                        dRow["Round_Number"] = i;
                        scoresTable.Rows.Add(dRow);
                    }
                }
            }
            AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.EventNames);
            AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.EventScores);
            AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.EventComputedScores);
        }
        private void loadSwissLeagues()
        {
            Label label = new Label();

            label.Text = "Events to Select Teams from : ";
            eventsListPanel.Controls.Clear();
            eventsListPanel.Controls.Add(label);
            DataTable table = AccessDatabaseUtilities.getDataTable(Constants.getCurrentTourneyEventsFileName(), Constants.TableName.TourneyEvents);

            foreach (DataRow dRow in table.Rows)
            {
                string eventType = AccessDatabaseUtilities.getStringValue(dRow, "Event_Type");
                string eventName = AccessDatabaseUtilities.getStringValue(dRow, "Event_Name");
                if (eventType == Constants.EventType.TeamsSwissLeague)
                {
                    CheckBox cb = new CheckBox();
                    cb.Text     = eventName;
                    cb.AutoSize = true;
                    cb.Click   += new EventHandler(eventCheckBoxes_Click);
                    eventsListPanel.Controls.Add(cb);
                }
            }
        }
        public void initializeMatches()
        {
            DataTable teamsTable = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutTeams);

            for (int i = 1; i <= numberOfRounds; ++i)
            {
                DataTable table           = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + i);
                int       totalTeams      = Convert.ToInt32(Math.Pow(2, i));
                int       numberOfMatches = totalTeams / 2;
                for (int j = 1; j <= numberOfMatches; ++j)
                {
                    DataRow   team1Row = teamsTable.Rows[j - 1];
                    DataRow   team2Row = teamsTable.Rows[totalTeams - j];
                    DataRow[] dRows    = table.Select("Match_Number = " + j);
                    Debug.Assert(dRows.Length == 2);
                    dRows[0]["Team_Number"] = AccessDatabaseUtilities.getIntValue(team1Row, "Team_Number");
                    dRows[0]["Team_Name"]   = AccessDatabaseUtilities.getStringValue(team1Row, "Team_Name");
                    dRows[1]["Team_Number"] = AccessDatabaseUtilities.getIntValue(team2Row, "Team_Number");
                    dRows[1]["Team_Name"]   = AccessDatabaseUtilities.getStringValue(team2Row, "Team_Name");
                }
                AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + i);
            }
        }
        private static string getStringValue(DataRow dRow, string columnName)
        {
            string value = AccessDatabaseUtilities.getStringValue(dRow, columnName);

            return(value.Replace("\"", ""));
        }
Ejemplo n.º 9
0
        private void createTeamPage(int teamNumber)
        {
            printMessage("Creating Team Page for Team Number : " + teamNumber);
            m_prefix = "../";
            StreamWriter sw = new StreamWriter(Path.Combine(m_webpagesRootDirectory, "teams", "team" + teamNumber + "score.html"));

            sw.WriteLine("<html><head></head><body>");
            DataRow dRow           = getTable(Constants.TableName.EventNames).Rows.Find(teamNumber);
            string  headerTemplate = "<h2>Scores for " + teamNumber + " : {Team_Name} ({Member_Names})</h2>";

            headerTemplate += "<h3>Carryover : {Carryover}</h3>";
            sw.WriteLine(applyTemplate_(headerTemplate, dRow));
            string originalEventName = AccessDatabaseUtilities.getStringValue(dRow, "Original_Event_Name");

            if (!string.IsNullOrWhiteSpace(originalEventName))
            {
                int    originalTeamNumber    = AccessDatabaseUtilities.getIntValue(dRow, "Original_Team_Number");
                string webpagesRootDirectory = "../../" + Utilities.makeIdentifier_(originalEventName);
                string link = webpagesRootDirectory + "/teams" + "/team" + originalTeamNumber + "score.html";
                sw.WriteLine("<a href='" + link + "' title='" + dRow["Member_Names"] + "'>Previous Round Scores for this team</a>");
            }
            headerTemplate = "<br/>[_commonPageHeader]";
            sw.WriteLine(applyTemplate_(headerTemplate, dRow));

            sw.WriteLine(Utilities.makeTablePreamble_() + "<thead><tr>");
            ArrayList tableHeader = new ArrayList();

            tableHeader.Add("Round");
            tableHeader.Add("Opponent");
            tableHeader.Add("VPs");
            tableHeader.Add("Adjustment");
            tableHeader.Add("Cumulative Score After Round");
            tableHeader.Add("Rank After Round");
            sw.WriteLine(Utilities.makeTableHeader_(tableHeader) + "</tr></thead><tbody>");
            int withdrawnRound = getIntValue(dRow, "Withdraw_Round");

            if (withdrawnRound < 1)
            {
                withdrawnRound = m_roundsCompleted + 1;
            }
            for (int i = 1; i < withdrawnRound; ++i)
            {
                ArrayList tableRow = new ArrayList();
                tableRow.Add(getRoundNumberLink(i));
                DataRow[] foundRows = getTable(Constants.TableName.EventScores).Select("Round_Number = " + i + " AND Team_1_Number = " + teamNumber);
                if (foundRows.Length > 0)
                {
                    dRow = foundRows[0];
                    tableRow.Add("" + getTeamLink(dRow["Team_2_Number"], true, true));
                    tableRow.Add("" + getDoubleValue(dRow, "Team_1_VPs"));
                    tableRow.Add("" + getDoubleValue(dRow, "Team_1_VP_Adjustment"));
                }
                else
                {
                    foundRows = getTable(Constants.TableName.EventScores).Select("Round_Number = " + i + " AND Team_2_Number = " + teamNumber);
                    if (foundRows.Length < 1)
                    {
                        tableRow.Add("-");
                        tableRow.Add("-");
                        tableRow.Add("-");
                    }
                    else
                    {
                        dRow = foundRows[0];
                        tableRow.Add("" + getTeamLink(dRow["Team_1_Number"], true, true));
                        tableRow.Add("" + getDoubleValue(dRow, "Team_2_VPs"));
                        tableRow.Add("" + getDoubleValue(dRow, "Team_2_VP_Adjustment"));
                    }
                }
                foundRows = getTable(Constants.TableName.EventComputedScores).Select("Team_Number = " + teamNumber);
                Debug.Assert(foundRows.Length <= 1);
                if (foundRows.Length < 1)
                {
                    tableRow.Add("-");
                    tableRow.Add("-");
                }
                else
                {
                    dRow = foundRows[0];
                    string columnName = "Score_After_Round_" + i;
                    if (dRow.Table.Columns.Contains(columnName))
                    {
                        tableRow.Add("" + getDoubleValue(dRow, columnName));
                    }
                    else
                    {
                        tableRow.Add("-");
                    }
                    columnName = "Rank_After_Round_" + i;
                    if (dRow.Table.Columns.Contains(columnName))
                    {
                        tableRow.Add("" + getDoubleValue(dRow, columnName));
                    }
                    else
                    {
                        tableRow.Add("-");
                    }
                }
                sw.WriteLine("<tr>" + Utilities.makeTableCell_(tableRow, i) + "</tr>");
            }
            for (int i = withdrawnRound; i <= m_roundsCompleted; ++i)
            {
                ArrayList tableRow = new ArrayList();
                tableRow.Add("" + i);
                tableRow.Add("WITHDRAWN");
                tableRow.Add("-");
                tableRow.Add("-");
                tableRow.Add("-");
                tableRow.Add("-");
                sw.WriteLine("<tr>" + Utilities.makeTableCell_(tableRow, i) + "</tr>");
            }
            for (int i = m_roundsCompleted + 1; i <= m_numberOfRounds; ++i)
            {
                ArrayList tableRow = new ArrayList();
                tableRow.Add("" + i);
                tableRow.Add("-");
                tableRow.Add("-");
                tableRow.Add("-");
                tableRow.Add("-");
                tableRow.Add("-");
                sw.WriteLine("<tr>" + Utilities.makeTableCell_(tableRow, i) + "</tr>");
            }
            sw.WriteLine("</tbody></table>");
            sw.WriteLine("</body></html>");
            sw.Close();
            reportProgress("Created Team " + teamNumber + " Score Page");
        }
Ejemplo n.º 10
0
 private string getStringValue(DataRow dRow, string columnName)
 {
     return(AccessDatabaseUtilities.getStringValue(dRow, columnName));
 }