コード例 #1
0
ファイル: DataAcces.cs プロジェクト: NicoEb/SiteSondage
        // Récupère le sondage depuis le base de donnée pour le désactiver
        public static ClassSondage RecupererSondagePourDesactiver(int idSondage, int numeroSecurite)
        {
            using (SqlConnection connection = new SqlConnection(ChaineConnexionBDD))
            {
                connection.Open();

                SqlCommand requeteSQL = new SqlCommand(@"SELECT * FROM Sondage,Resultats WHERE IdSondage = @ID and CleDeSecurite = @cleSecu and  FK_Id_sondage = @ID", connection);

                requeteSQL.Parameters.AddWithValue("@ID", idSondage);
                requeteSQL.Parameters.AddWithValue("@cleSecu", numeroSecurite);
                SqlDataReader reader = requeteSQL.ExecuteReader();

                reader.Read();


                idSondage = reader.GetInt32(0);
                string question      = reader.GetString(1);
                string choix1        = reader.GetString(2);
                string choix2        = reader.GetString(3);
                string choix3        = reader.GetString(4);
                string choix4        = reader.GetString(5);
                bool   choixMultiple = reader.GetBoolean(6);
                bool   etatDuSondage = reader.GetBoolean(7);
                numeroSecurite = reader.GetInt32(8);



                ClassSondage sondage = new ClassSondage(idSondage, question, choix1, choix2, choix3, choix4, choixMultiple, etatDuSondage, numeroSecurite);



                return(sondage);
            }
        }
コード例 #2
0
ファイル: ClassResultat.cs プロジェクト: NicoEb/SiteSondage
 public ClassResultat(ClassSondage vote, int resultatChoix1, int resultatChoix2, int resultatChoix3, int resultatChoix4, int nombreDevotant)
 {
     Vote           = vote;
     ResultatChoix1 = resultatChoix1;
     ResultatChoix2 = resultatChoix2;
     ResultatChoix3 = resultatChoix3;
     ResultatChoix4 = resultatChoix4;
     NombreDevotant = nombreDevotant;
 }
コード例 #3
0
ファイル: DataAcces.cs プロジェクト: NicoEb/SiteSondage
        // Désactive sondage en base de donnée lui donne la valeur 1 lorsque l'on supprime sondage
        public static void MetAJourEtatDuSOndage(ClassSondage sondage)
        {
            SqlConnection connection = new SqlConnection(ChaineConnexionBDD);

            connection.Open();

            SqlCommand requete = new SqlCommand("UPDATE Sondage SET EtatDuSondage = 1  WHERE IdSondage = @idSondage ", connection);


            requete.Parameters.AddWithValue("@idSondage", sondage.IdSondage);


            requete.ExecuteNonQuery();
            connection.Close();
        }
コード例 #4
0
ファイル: DataAcces.cs プロジェクト: NicoEb/SiteSondage
        // Récupère les resultats depuis le base de donnée
        public static ClassResultat RecupererResultatEnBdd(int idSondage)
        {
            using (SqlConnection connection = new SqlConnection(ChaineConnexionBDD))
            {
                connection.Open();

                SqlCommand requeteSQL = new SqlCommand(@"SELECT * FROM sondage,resultats WHERE IdSondage = @ID and FK_Id_sondage = @ID", connection);

                requeteSQL.Parameters.AddWithValue("@ID", idSondage);
                SqlDataReader reader = requeteSQL.ExecuteReader();

                reader.Read();

                int    idsondage      = reader.GetInt32(0);
                string question       = reader.GetString(1);
                string choix1         = reader.GetString(2);
                string choix2         = reader.GetString(3);
                string choix3         = reader.GetString(4);
                string choix4         = reader.GetString(5);
                bool   choixMultiple  = reader.GetBoolean(6);
                bool   etatDuSondage  = reader.GetBoolean(7);
                int    numeroSecurite = reader.GetInt32(8);
                int    resultatChoix1 = reader.GetInt32(9);
                int    resultatChoix2 = reader.GetInt32(10);
                int    resultatChoix3 = reader.GetInt32(11);
                int    resultatChoix4 = reader.GetInt32(12);
                int    nombreDeVotant = reader.GetInt32(13);



                ClassSondage  sondage = new ClassSondage(idsondage, question, choix1, choix2, choix3, choix4, choixMultiple, etatDuSondage, numeroSecurite);
                ClassResultat vote    = new ClassResultat(sondage, resultatChoix1, resultatChoix2, resultatChoix3, resultatChoix4, nombreDeVotant);


                return(vote);
            }
        }
コード例 #5
0
ファイル: DataAcces.cs プロジェクト: NicoEb/SiteSondage
        // Insère sondage en base de donnée
        public static int InsererEnBDD(ClassSondage nouveauSondage)
        {
            using (SqlConnection connection = new SqlConnection(ChaineConnexionBDD))
            {
                connection.Open();

                SqlCommand requete = new SqlCommand("INSERT INTO Sondage(Question,Choix1,Choix2,Choix3,Choix4,ChoixMultiple,EtatDuSondage,CleDeSecurite) OUTPUT Inserted.IdSondage VALUES  (@question,@choix1,@choix2,@choix3,@choix4,@choixM,@etatSondage,@cleSecu)", connection);

                requete.Parameters.AddWithValue("@question", nouveauSondage.Question);
                requete.Parameters.AddWithValue("@choix1", nouveauSondage.Choix1);
                requete.Parameters.AddWithValue("@choix2", nouveauSondage.Choix2);
                requete.Parameters.AddWithValue("@choix3", nouveauSondage.Choix3);
                requete.Parameters.AddWithValue("@choix4", nouveauSondage.Choix4);
                requete.Parameters.AddWithValue("@choixM", nouveauSondage.ChoixMultiple);
                requete.Parameters.AddWithValue("@etatSondage", nouveauSondage.EtatDuSondage);
                requete.Parameters.AddWithValue("@cleSecu", nouveauSondage.NumeroSecurite);

                int idInsere = (int)requete.ExecuteScalar();

                InsererIDDansResultat(idInsere);

                return(idInsere);
            }
        }