Esempio n. 1
0
        public EditPlayerDialog()
        {
            InitializeComponent();

            this.player = new Player();
            this.playerBindingSource.DataSource = player;
        }
Esempio 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();
        }
Esempio n. 3
0
        public EditPlayerDialog(Player p)
            : this()
        {
            this.Text = p.ToString();

            this.player = p.Clone();
            this.playerBindingSource.DataSource = player;
        }
Esempio 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();
        }
Esempio 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);
        }
Esempio 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;
 }
Esempio n. 7
0
 public int GetMaxPoints(Player p)
 {
     return 2 * (table.RowCount - 1) * Rounds;
 }
Esempio 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,
     };
 }
Esempio 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);
        }
Esempio 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();
        }
Esempio n. 11
0
 private bool IsPlayerInactive(Player p)
 {
     return !p.IsActive(currentRateType);
 }
Esempio n. 12
0
 private static int ComparePlayersByBlitzRate(Player x, Player y)
 {
     return y.BlitzRate - x.BlitzRate;
 }
Esempio n. 13
0
 private void PlayerDeleteCallback(Player p)
 {
     return;
 }
Esempio n. 14
0
 public int GetMaxPoints(Player p)
 {
     return 2 * (table.RowCount - 1); //TODO many rounds
 }
Esempio n. 15
0
 private static int ComparePlayersByRapidRate(Player x, Player y)
 {
     return y.RapidRate - x.RapidRate;
 }
Esempio n. 16
0
 private static int ComparePlayersByName(Player x, Player y)
 {
     return x.Name.CompareTo(y.Name);
 }
Esempio n. 17
0
 private static int ComparePlayersByClassicRate(Player x, Player y)
 {
     return y.ClassicRate - x.ClassicRate;
 }
Esempio 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);
        }
Esempio 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;
        }
Esempio n. 20
0
        public void RemovePlayer(Player p)
        {
            removePlayerCmd.Parameters.AddWithValue("@id", p.Id);

            removePlayerCmd.ExecuteNonQuery();
        }
Esempio 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
     }
 }