public static DartsPlayer GetPlayer(int playerId)
        {
            DartsPlayer player = new DartsPlayer(playerId);

            SqlConnection connSql = new SqlConnection(
                Gravoc.Encryption.Encryption.Decrypt(Properties.Settings.Default.ConnectionString));
            connSql.Open();

            SqlCommand cmdSql = new SqlCommand("GetPlayer", connSql);
            cmdSql.CommandType = System.Data.CommandType.StoredProcedure;
            cmdSql.Parameters.AddWithValue("@PlayerID", playerId);

            using (SqlDataReader rReader = cmdSql.ExecuteReader())
            {
                if (rReader.Read())
                {
                    player.Name = Convert.ToString(rReader["Name"]);
                    player._Rating = new Rating(Convert.ToDouble(rReader["RatingMean"]), Convert.ToDouble(rReader["RatingDeviation"]));
                }
            }

            cmdSql = new SqlCommand("GetPlayerClassRatings", connSql);
            cmdSql.CommandType = System.Data.CommandType.StoredProcedure;
            cmdSql.Parameters.AddWithValue("@PlayerID", playerId);

            using (SqlDataReader rReader = cmdSql.ExecuteReader())
            {
                while (rReader.Read())
                {
                    player.ClassRatings.Add(Convert.ToInt32(rReader["Class"]),
                        new Rating(Convert.ToDouble(rReader["RatingMean"]), Convert.ToDouble(rReader["RatingDeviation"])));
                }
            }

            cmdSql = new SqlCommand("GetPlayerCampaignRatings", connSql);
            cmdSql.CommandType = System.Data.CommandType.StoredProcedure;
            cmdSql.Parameters.AddWithValue("@PlayerID", playerId);

            using (SqlDataReader rReader = cmdSql.ExecuteReader())
            {
                while (rReader.Read())
                {
                    player.CampaignRatings.Add(Convert.ToInt32(rReader["Campaign"]),
                        new Rating(Convert.ToDouble(rReader["RatingMean"]), Convert.ToDouble(rReader["RatingDeviation"])));
                }
            }

            connSql.Close();

            return player;
        }
예제 #2
0
        public DartsPlayer GetPlayerByName(string name)
        {
            // TODO return a player
            DartsPlayer player = new DartsPlayer(0);

            return player;
        }
예제 #3
0
        public void CommitGame(DartsPlayer player, Match match, string ratingToAdjust)
        {
            SqlConnection connSql = new SqlConnection(
                Gravoc.Encryption.Encryption.Decrypt(Properties.Settings.Default.ConnectionString));
            connSql.Open();

            SqlCommand cmdSql = new SqlCommand("CommitGame", connSql);
            cmdSql.CommandType = System.Data.CommandType.StoredProcedure;

            cmdSql.Parameters.AddWithValue("@Match", match.MatchId);
            cmdSql.Parameters.AddWithValue("@GameNumber", GameNumber);
            cmdSql.Parameters.AddWithValue("@GameType", Convert.ToInt32(_GameType));
            cmdSql.Parameters.AddWithValue("@Player", player.Id);
            if (AwayDartsPlayers.Contains(player) ^ IsHomeWin)
                cmdSql.Parameters.AddWithValue("@Result", 1);
            else
                cmdSql.Parameters.AddWithValue("@Result", 0);
            cmdSql.Parameters.AddWithValue("@RatingToAdjust", ratingToAdjust);
            switch(ratingToAdjust)
            {
                case "player":
                    cmdSql.Parameters.AddWithValue("@NewRatingMean", player._Rating.Mean);
                    cmdSql.Parameters.AddWithValue("@NewRatingDeviation", player._Rating.StandardDeviation);
                    break;
                case "campaign":
                    cmdSql.Parameters.AddWithValue("@NewRatingMean", player.CampaignRatings[Convert.ToInt32(match._Campaign.ID)].Mean);
                    cmdSql.Parameters.AddWithValue("@NewRatingDeviation", player.CampaignRatings[Convert.ToInt32(match._Campaign.ID)].StandardDeviation);
                    break;
                case "class":
                    cmdSql.Parameters.AddWithValue("@NewRatingMean", player.ClassRatings[Convert.ToInt32(match._Campaign._Class)].Mean);
                    cmdSql.Parameters.AddWithValue("@NewRatingDeviation", player.ClassRatings[Convert.ToInt32(match._Campaign._Class)].StandardDeviation);
                    break;
                default:
                    cmdSql.Parameters.AddWithValue("@NewRatingMean", -1);
                    cmdSql.Parameters.AddWithValue("@NewRatingDeviation", -1);
                    break;
            }

            cmdSql.ExecuteNonQuery();

            connSql.Close();
        }