Ejemplo n.º 1
0
        /// <summary>
        /// Crée les éditions des tournois disputés dans une année.
        /// L'intégration manuelle des nouveaux tournois (ou ceux mis à jour) doit être réalisée au préalable.
        /// Les données relatives à la coupe Davis sont ignorées.
        /// </summary>
        public void IntegrateEditionOfTournaments()
        {
            string insertEditionQuery = SqlTools.BuildInsertQuery("editions", new Dictionary <string, string>()
            {
                { "tournament_ID", "@id" },
                { "year", "@year" },
                { "draw_size", "@drawsize" },
                { "date_begin", "@bdate" },
                { "date_end", "@edate" },
                { "surface_ID", "@surface" },
                { "slot_order", "@slot" },
                { "is_indoor", "@indoor" },
                { "level_ID", "@level" },
                { "substitute_ID", "@substitute" },
                { "name", "@name" },
                { "city", "@city" }
            });

            List <string> uniqueTournamentList = new List <string>();

            foreach (Dictionary <string, string> match in _matchs)
            {
                if (!uniqueTournamentList.Contains(match["tourney_id"]))
                {
                    uniqueTournamentList.Add(match["tourney_id"]);

                    string baseCode = match["tourney_id"].Substring(5);

                    using (DataTableReader reader = SqlTools.ExecuteReader("select * from tournaments where original_code in (@code2, @code1)",
                                                                           new SqlParam("@code1", DbType.String, baseCode), new SqlParam("@code2", DbType.String, GetGenericTournamentCode(baseCode))))
                    {
                        if (reader.Read())
                        {
                            DateTime dateBegin = Tools.FormatCsvDateTime(match["tourney_date"]);
                            // Pas le vrai type SQL, mais san importance
                            int drawSize = Convert.ToInt32(match["draw_size"]);

                            // TODO : système de préparation de la requête SQL
                            SqlTools.ExecuteNonQuery(insertEditionQuery,
                                                     new SqlParam("@id", DbType.UInt32, reader.GetUint64("ID")),
                                                     new SqlParam("@year", DbType.UInt32, _year),
                                                     new SqlParam("@drawsize", DbType.UInt16, drawSize),
                                                     new SqlParam("@bdate", DbType.DateTime, dateBegin.ToString("yyyy-MM-dd")),
                                                     new SqlParam("@edate", DbType.DateTime, ComputeEditionEndDate(dateBegin, drawSize).ToString("yyyy-MM-dd")),
                                                     new SqlParam("@surface", DbType.Byte, reader.GetByte("surface_ID")),
                                                     new SqlParam("@slot", DbType.Byte, reader.GetByteNull("slot_order")),
                                                     new SqlParam("@indoor", DbType.Boolean, reader.GetByte("is_indoor") == 1),
                                                     new SqlParam("@level", DbType.Byte, reader.GetByte("level_ID")),
                                                     new SqlParam("@substitute", DbType.UInt32, reader.GetUint64Null("substitute_ID")),
                                                     new SqlParam("@name", DbType.String, reader.GetString("name")),
                                                     new SqlParam("@city", DbType.String, reader.GetString("city")));
                        }
                        else
                        {
                            Tools.WriteLog(string.Format("Le tournoi {0} a été ignoré. C'est une erreur s'il ne s'agit pas d'un match de coupe Davis.", match["tourney_id"]));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <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);
        }