Exemplo n.º 1
0
        public EditPlayerDialog()
        {
            InitializeComponent();

            this.player = new Player();
            this.playerBindingSource.DataSource = player;
        }
Exemplo n.º 2
0
        public void AddPlayer(Player p)
        {
            int c = table.ColumnCount;
            int n = table.RowCount;
            int r = table.Rows.Add();

            DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn()
            {
                HeaderText = (n + 1).ToString(),
                Width = 50,
                SortMode = DataGridViewColumnSortMode.Programmatic,
                MaxInputLength = 3,
                ReadOnly = true,
                Name = "colPlayer" + n.ToString()
            };

            table.Columns.Insert(n + playersStartIndex, col);

            table.Rows[r].Cells[0].Value = (n + 1).ToString();
            table.Rows[r].Cells[1].Value = p.GetNameWithRate(Type);
            table.Rows[r].Tag = p;

            table[n + playersStartIndex, n].Style.BackColor = System.Drawing.SystemColors.WindowFrame;
            CountTable();
        }
Exemplo n.º 3
0
        public EditPlayerDialog(Player p)
            : this()
        {
            this.Text = p.ToString();

            this.player = p.Clone();
            this.playerBindingSource.DataSource = player;
        }
Exemplo n.º 4
0
        public void AddPlayer(Player p)
        {
            int n = table.RowCount;
            int r = table.Rows.Add();

            table.Rows[r].Cells[0].Value = (n + 1).ToString();
            table.Rows[r].Cells[1].Value = p.GetNameWithRate(Type);
            table.Rows[r].Tag = p;
            CountTable();
        }
Exemplo n.º 5
0
        public int GetAverageRate(Player p)
        {
            int sum = 0;
            for (int i = 0; i < table.RowCount; ++i)
            {
                sum += GetPlayer(i).GetRate(Type);
            }

            return EloTable.DivideRound(sum, table.RowCount);
        }
Exemplo n.º 6
0
 private int GetIndexByPlayer(Player p)
 {
     for (int i = 0; i < table.RowCount; ++i)
     {
         if (GetPlayer(i).Id == p.Id)
         {
             return i;
         }
     }
     return -1;
 }
Exemplo n.º 7
0
 public int GetMaxPoints(Player p)
 {
     return 2 * (table.RowCount - 1) * Rounds;
 }
Exemplo n.º 8
0
 public TournamentResult GetResult(Player p)
 {
     int index = GetIndexByPlayer(p);
     return new TournamentResult()
     {
         Participant = p,
         //Event = GetTournament(),
         Points = (int)table.Rows[index].Cells["colPoints"].Tag,
         SeqNumber = index + 1,
     };
 }
Exemplo n.º 9
0
        private void InsertPlayerIntoViewList(Player p, int index, int count)
        {
            ListViewItem item = new ListViewItem(new[] {(index + 1).ToString(),
                                                             p.Name,
                                                             p.GetRate(currentRateType).ToString(),
                                                             p.GetUpdateDate(currentRateType).ToString("dd.MM.yyyy HH:mm")
                                                            });

            item.Tag = p;
            item.UseItemStyleForSubItems = false;
            if (index < (count + 1) / 2)
            {
                playersListLeft.InsertItem(item);
            }
            else
            {
                playersListRight.InsertItem(item);
            }

            HighlightOldPlayer(item);
        }
Exemplo n.º 10
0
        public void UpdatePlayer(Player p)
        {
            editPlayerCmd.Parameters.AddWithValue("@name", p.Name);
            editPlayerCmd.Parameters.AddWithValue("@rblitz", p.BlitzRate);
            editPlayerCmd.Parameters.AddWithValue("@rrapid", p.RapidRate);
            editPlayerCmd.Parameters.AddWithValue("@rclassic", p.ClassicRate);
            editPlayerCmd.Parameters.AddWithValue("@blitzup", p.BlitzLastUpdate.ToUniversalTime());
            editPlayerCmd.Parameters.AddWithValue("@rapidup", p.RapidLastUpdate.ToUniversalTime());
            editPlayerCmd.Parameters.AddWithValue("@classicup", p.ClassicLastUpdate.ToUniversalTime());
            editPlayerCmd.Parameters.AddWithValue("@id", p.Id);

            editPlayerCmd.ExecuteNonQuery();
        }
Exemplo n.º 11
0
 private bool IsPlayerInactive(Player p)
 {
     return !p.IsActive(currentRateType);
 }
Exemplo n.º 12
0
 private static int ComparePlayersByBlitzRate(Player x, Player y)
 {
     return y.BlitzRate - x.BlitzRate;
 }
Exemplo n.º 13
0
 private void PlayerDeleteCallback(Player p)
 {
     return;
 }
Exemplo n.º 14
0
 public int GetMaxPoints(Player p)
 {
     return 2 * (table.RowCount - 1); //TODO many rounds
 }
Exemplo n.º 15
0
 private static int ComparePlayersByRapidRate(Player x, Player y)
 {
     return y.RapidRate - x.RapidRate;
 }
Exemplo n.º 16
0
 private static int ComparePlayersByName(Player x, Player y)
 {
     return x.Name.CompareTo(y.Name);
 }
Exemplo n.º 17
0
 private static int ComparePlayersByClassicRate(Player x, Player y)
 {
     return y.ClassicRate - x.ClassicRate;
 }
Exemplo n.º 18
0
        private void OnTablePlayerDeleted(Player p)
        {
            if (!showInactivePlayers && IsPlayerInactive(p))
            {
                inactivePlayers.Add(p);
                return;
            }

            availablePlayers.Insert(0, p);
            if (currentDataSource == searchResult)
            {
                if (p.Name.StartsWith(searchPlayer.Text, ignoreCase))
                {
                    searchResult.Insert(0, p);
                }
            }
            else if (currentDataSource == noResult)
            {
                if (p.Name.StartsWith(searchPlayer.Text, ignoreCase))
                {
                    searchResult.Insert(0, p);
                    currentDataSource = searchResult;
                }
            }
            SetDataSource(currentDataSource);
        }
Exemplo n.º 19
0
        public List<Player> LoadAllPlayers(PlayerSortType st, GameType gt)
        {
            SQLiteCommand selectCmd = GetSelectCmd(st, gt);

            List<Player> players = new List<Player>();
            SQLiteDataReader dataReader = selectCmd.ExecuteReader();

            while (dataReader.Read())
            {
                Player p = new Player(dataReader.GetInt64(7))
                {
                    Name = dataReader.GetString(0),
                    BlitzRate = dataReader.GetInt32(1),
                    RapidRate = dataReader.GetInt32(2),
                    ClassicRate = dataReader.GetInt32(3),
                    BlitzLastUpdate = dataReader.GetDateTime(4),
                    RapidLastUpdate = dataReader.GetDateTime(5),
                    ClassicLastUpdate = dataReader.GetDateTime(6),
                };

                players.Add(p);
            }
            dataReader.Close();
            return players;
        }
Exemplo n.º 20
0
        public void RemovePlayer(Player p)
        {
            removePlayerCmd.Parameters.AddWithValue("@id", p.Id);

            removePlayerCmd.ExecuteNonQuery();
        }
Exemplo n.º 21
0
 private void EditPlayer(Player player)
 {
     EditPlayerDialog editDialog = new EditPlayerDialog(player);
     if(editDialog.ShowDialog() == DialogResult.OK)
     {
         dbMgr.UpdatePlayer(editDialog.GetPlayer());
         ReloadPlayersAndView(); //TODO just update the item
     }
 }