Beispiel #1
0
        //Retourne les stats
        public static Statistique getSats(int noJoueur)
        {
            Statistique stat = null;
            OleDbConnection connexion = new OleDbConnection(connBD);
            try
            {
                connexion.Open();
                commande = new OleDbCommand("SELECT * FROM tblStatistique WHERE noJoueur=@noJoueur", connexion);
                commande.Parameters.Add("@noJoueur", OleDbType.Integer).Value = noJoueur;

                OleDbDataReader reader = commande.ExecuteReader();
                while (reader.Read())
                {
                    int nbGagne = reader["nbPartieGagne"] == DBNull.Value ? 0 : Convert.ToInt32(reader["nbPartieGagne"]);
                    int nbPerdu = reader["nbPartiePerdu"] == DBNull.Value ? 0 : Convert.ToInt32(reader["nbPartiePerdu"]);
                    int score = reader["score"] == DBNull.Value ? 0 : Convert.ToInt32(reader["score"]);
                    stat = new Statistique(nbGagne, nbPerdu, score);
                }

                return stat;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                commande.Dispose();
                connexion.Close();
            }
        }
Beispiel #2
0
 private void Affichage()
 {
     statistique = Utilitaire.getSats(leJoueur);
     lblGagne.Text = statistique.NbPartieGagne.ToString();
     lblPerdu.Text = statistique.NbPartiePerdu.ToString();
     lblPourcentage.Text = statistique.NbPartiePerdu == 0 ? "100,00%" : ((double)statistique.NbPartieGagne / ((double)statistique.NbPartiePerdu + (double)statistique.NbPartieGagne)).ToString("P2");
     lblScore.Text = statistique.Score.ToString();
     Dictionary<String, Statistique> dicoTop = Utilitaire.getTop3();
     for (int i = 0; i < dicoTop.Count; i++)
     {
         Label lab = (Label)Controls["lbl" + (i + 1).ToString()];
         Label labScore = (Label)Controls["lblScore" + (i + 1).ToString()];
         lab.Text = dicoTop.Keys.ElementAt(i);
         labScore.Text = ((Statistique)dicoTop.Values.ElementAt(i)).Score.ToString();
     }
 }