Exemple #1
0
        //Methode pour recuperer les reponses d'un sondage et en faire une liste
        public static List <Reponse> GetAllReponse(int IdSondage)
        {
            List <Reponse> mesReponse = new List <Reponse>();
            SqlConnection  connexion  = new SqlConnection(SqlConnectionString);

            connexion.Open();

            SqlCommand maCommande = new SqlCommand(@"SELECT * " +
                                                   "FROM Reponse " +
                                                   "WHERE FKIdSondage=@id_sondage", connexion);

            maCommande.Parameters.AddWithValue("@id_sondage", IdSondage);
            SqlDataReader monReader = maCommande.ExecuteReader();

            int    idReponse    = 0;
            string choixReponse = "";
            int    nbVotant     = 0;
            int    fkId         = 0;

            while (monReader.Read())
            {
                idReponse    = Convert.ToInt32(monReader["IdReponse"]);
                choixReponse = (string)monReader["IntituleReponse"];
                nbVotant     = (int)monReader["NbVoteReponse"];
                fkId         = Convert.ToInt32(monReader["FKIdSondage"]);
                Reponse maReponse = new Reponse(idReponse, choixReponse, nbVotant, fkId);
                mesReponse.Add(maReponse);
            }

            connexion.Close();

            return(mesReponse);
        }
Exemple #2
0
        public static List <Reponse> GetReponseOrderedById(int idSondage)
        {
            List <Reponse> mesReponse = new List <Reponse>();

            SqlConnection connexion = new SqlConnection(SqlConnectionString);

            connexion.Open();

            SqlCommand maCommande = new SqlCommand("SELECT IdReponse, IntituleReponse, NbVoteReponse " +
                                                   "FROM Reponse " +
                                                   "WHERE FKIdSondage=@idSondage " +
                                                   "ORDER BY NbVoteReponse DESC", connexion);

            maCommande.Parameters.AddWithValue("@idSondage", idSondage);
            SqlDataReader monReader = maCommande.ExecuteReader();

            int    idReponse       = 0;
            string intituleReponse = string.Empty;
            int    nbVoteReponse   = 0;

            while (monReader.Read())
            {
                idReponse       = (int)monReader["IdReponse"];
                intituleReponse = (string)monReader["IntituleReponse"];
                nbVoteReponse   = (int)monReader["NbVoteReponse"];
                Reponse maReponse = new Reponse(idReponse, intituleReponse, nbVoteReponse);
                mesReponse.Add(maReponse);
            }


            connexion.Close();

            return(mesReponse);
        }
Exemple #3
0
        //methode pour mettre a jour le nombre de vote par reponses aprés chaque vote
        public static void UpdateNombreVoteReponse(Reponse reponse)
        {
            SqlConnection connection = new SqlConnection(SqlConnectionString);

            connection.Open();

            SqlCommand maCommande = new SqlCommand(@"UPDATE Reponse SET NbVoteReponse = @nb_vote WHERE IdReponse = @id_reponse", connection);

            maCommande.Parameters.AddWithValue("@nb_vote", reponse.NbVoteReponse);
            maCommande.Parameters.AddWithValue("@id_reponse", reponse.IdReponse);
            maCommande.ExecuteNonQuery();

            connection.Close();
        }
Exemple #4
0
        //methode pour ajouter les reponses d'un sondage en BDD
        public static int AddReponse(Reponse maReponse)
        {
            SqlConnection connexion = new SqlConnection(SqlConnectionString);

            connexion.Open();

            SqlCommand maCommande = new SqlCommand("INSERT INTO Reponse(IntituleReponse, NbVoteReponse, FKIdSondage) " +
                                                   "VALUES (@choix, @nb_vote_reponse, @FK_idSondage); " +
                                                   "SELECT SCOPE_IDENTITY()", connexion);

            maCommande.Parameters.AddWithValue("@choix", maReponse.IntituleReponse);
            maCommande.Parameters.AddWithValue("@nb_vote_reponse", maReponse.NbVoteReponse);
            maCommande.Parameters.AddWithValue("@FK_idSondage", maReponse.FKIdSondage);
            int IdReponse = Convert.ToInt32(maCommande.ExecuteScalar());

            connexion.Close();

            return(IdReponse);
        }