Exemple #1
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (RoundListBox1.SelectedItem != null)
            {
                first = (TurneeData.RoundData)RoundListBox1.SelectedItem;
                LabelPlayers1.Text = "Players in 1st";
                foreach (TurneeData.PlayerScore ps in first.playerScores)
                {
                    LabelPlayers1.Text += "\n" + ps.playerName;
                }
            }
            if (RoundListBox2.SelectedItem != null)
            {
                second             = (TurneeData.RoundData)RoundListBox2.SelectedItem;
                LabelPlayers2.Text = "Players in 2nd";
                foreach (TurneeData.PlayerScore ps in second.playerScores)
                {
                    LabelPlayers2.Text += "\n" + ps.playerName;
                }
            }

            if (RoundListBox1.SelectedItem != null && RoundListBox2.SelectedItem != null)
            {
                namesOk = true;
                foreach (TurneeData.PlayerScore ps in first.playerScores)
                {
                    namesOk = second.playerScores.Contains(ps) ? false : namesOk;
                }
                CanCombineLabel.Text = namesOk ? CanCombineLabel.Text : "Same names found!";

                parsOk = first.pars.SequenceEqual(second.pars);
                CanCombineLabel.Text = parsOk ? CanCombineLabel.Text : "Courses don't match!";

                if (parsOk && namesOk)
                {
                    CanCombineLabel.Text = "Rounds can be combined";
                }
            }
            else
            {
                CanCombineLabel.Text = defaultText;
            }
        }
Exemple #2
0
        // Change round score table
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            RoundGrid.Rows.Clear();
            RoundGrid.Columns.Clear();
            RoundGrid.Refresh();
            TurneeData.RoundData roundData = ((TurneeData.RoundData)RoundsListBox.SelectedItem);
            RoundGrid.ColumnCount = roundData.playerScores.Length + 1;
            var playerTotalScores = new int[roundData.playerScores.Length + 1];

            // Add player columns
            for (int i = 0; i < RoundGrid.ColumnCount; i++)
            {
                RoundGrid.Columns[i].HeaderText = i == 0 ? "Par" : roundData.playerScores[i - 1].playerName;
                RoundGrid.Columns[i].Width      = 60;
                RoundGrid.Columns[i].SortMode   = DataGridViewColumnSortMode.NotSortable;
            }

            // Add scores
            var row = new string[roundData.playerScores.Length + 1];

            for (int i = 0; i < roundData.pars.Length; i++)
            {
                for (int j = 0; j < roundData.playerScores.Length; j++)
                {
                    row[j + 1] = roundData.playerScores[j].scores[i].ToString();
                    playerTotalScores[j + 1] += roundData.playerScores[j].scores[i];
                }
                row[0] = roundData.pars[i].ToString();
                playerTotalScores[0] += roundData.pars[i];
                RoundGrid.Rows.Add(row);
                RoundGrid.Rows[i].HeaderCell.Value = (i + 1).ToString();
            }

            // Add total score
            for (int i = 0; i < RoundGrid.ColumnCount; i++)
            {
                var sign = (playerTotalScores[i] - playerTotalScores[0]) >= 0 ? "+" : "";
                row[i] = i == 0 ?
                         playerTotalScores[0].ToString() :
                         playerTotalScores[i].ToString() + " (" + sign + (playerTotalScores[i] - playerTotalScores[0]).ToString() + ")";
            }
            RoundGrid.Rows.Add(row);
            RoundGrid.Rows[RoundGrid.Rows.Count - 1].HeaderCell.Value = "Total";

            for (int c = 1; c < RoundGrid.Columns.Count; c++)
            {
                for (int r = 0; r < RoundGrid.Rows.Count - 1; r++)
                {
                    switch (int.Parse(RoundGrid.Rows[r].Cells[c].Value.ToString()) - int.Parse(RoundGrid.Rows[r].Cells[0].Value.ToString()))
                    {
                    case -3:
                        RoundGrid.Rows[r].Cells[c].Style.BackColor = Color.White;
                        break;

                    case -2:
                        RoundGrid.Rows[r].Cells[c].Style.BackColor = Color.White;
                        break;

                    case -1:
                        RoundGrid.Rows[r].Cells[c].Style.BackColor = Color.DodgerBlue;
                        break;

                    case 0:
                        RoundGrid.Rows[r].Cells[c].Style.BackColor = Color.Lime;
                        break;

                    case 1:
                        RoundGrid.Rows[r].Cells[c].Style.BackColor = Color.Yellow;
                        break;

                    case 2:
                        RoundGrid.Rows[r].Cells[c].Style.BackColor = Color.DarkOrange;
                        break;

                    default:
                        RoundGrid.Rows[r].Cells[c].Style.BackColor = Color.Red;
                        break;
                    }
                }
            }
            UpdateComponentSizes();
        }