// Procède à l'importation des joueurs. private void LoadPlayers() { string query = "select * from players"; using (DataTableReader reader = SqlTools.ExecuteReader(query)) { while (reader.Read()) { // Calcul de la latéralité. string hand = reader.GetString("hand"); bool? isLeftHanded = null; if (!string.IsNullOrWhiteSpace(hand)) { isLeftHanded = hand.Trim().ToUpper() == "L"; } new Player(reader.GetUint64("ID"), reader.GetString("name"), reader.GetString("nationality"), isLeftHanded, reader.GetUint32Null("height"), reader.GetDateTimeNull("date_of_birth"), reader.GetDateTimeNull("date_begin"), reader.GetDateTimeNull("date_end")); _dataLoadingProgressEventHandler?.Invoke(new DataLoadingProgressEvent(100 * ++_currentDataCount / _totalDataCount)); } } // Importation de l'historique des nationalités. query = "select * from players_nat_history order by date_end"; using (DataTableReader reader = SqlTools.ExecuteReader(query)) { while (reader.Read()) { Player.AddNationalitiesHistoryEntry(reader.GetUint64("ID"), reader.GetString("nationality"), reader.GetDateTime("date_end")); _dataLoadingProgressEventHandler?.Invoke(new DataLoadingProgressEvent(100 * ++_currentDataCount / _totalDataCount)); } } }
/// <summary> /// Importe des matchs depuis la base de données selon des paramètres optionnels. /// </summary> /// <param name="editionId">Identifiant d'édition de tournoi.</param> /// <param name="playerId">Identifiant de joueur.</param> /// <returns>Les matchs importés.</returns> public IEnumerable <Match> LoadMatches(uint?editionId, ulong?playerId) { List <Match> matchs = new List <Match>(); Match.SetBatchMode(true); string query = "select * from matches where 1 = 1"; List <SqlParam> sqlParams = new List <SqlParam>(); if (editionId.HasValue) { query += " and edition_ID = @edition"; sqlParams.Add(new SqlParam("@edition", DbType.UInt32, editionId.Value)); } if (playerId.HasValue) { query += " and (winner_ID = @player or loser_ID = @player)"; sqlParams.Add(new SqlParam("@player", DbType.UInt32, playerId.Value)); } using (DataTableReader reader = SqlTools.ExecuteReader(query, sqlParams.ToArray())) { while (reader.Read()) { Match match = new Match(reader.GetUint64("ID"), reader.GetUint32("edition_ID"), reader.GetUint16("match_num"), (Round)reader.GetByte("round_ID"), reader.GetByte("best_of"), reader.GetUint32Null("minutes"), reader.GetBoolean("unfinished"), reader.GetBoolean("retirement"), reader.GetBoolean("walkover"), reader.GetUint32("winner_ID"), reader.GetUint32Null("winner_seed"), reader.GetString("winner_entry"), reader.GetUint32Null("winner_rank"), reader.GetUint32Null("winner_rank_points"), reader.GetUint32("loser_ID"), reader.GetUint32Null("loser_seed"), reader.GetString("loser_entry"), reader.GetUint32Null("loser_rank"), reader.GetUint32Null("loser_rank_points")); match.DefineStatistics(reader.ToDynamicDictionnary <uint?>(true), reader.ToDynamicDictionnary <uint?>(true)); for (byte i = 1; i <= 5; i++) { match.AddSetByNumber(i, reader.GetByteNull("w_set_" + i.ToString()), reader.GetByteNull("l_set_" + i.ToString()), reader.GetUint16Null("tb_set_" + i.ToString())); } matchs.Add(match); if (Config.GetBool(AppKey.ComputeMatchesWhileLoading)) { _dataLoadingProgressEventHandler?.Invoke(new DataLoadingProgressEvent(100 * ++_currentDataCount / _totalDataCount)); } } } Match.SetBatchMode(false); return(matchs); }