// RECUPERATION RESULTAT BDD POUR RESULTAT SONDAGE public static Reponse AfficherQuestionReponse(int idSondage) { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); SqlCommand afficherQuestionReponse = new SqlCommand(@"SELECT * FROM Sondage,Reponse WHERE IdSondage = @IdSondage and FKIdSondage = @IdSondage", connection); afficherQuestionReponse.Parameters.AddWithValue("@IdSondage", idSondage); SqlDataReader reader = afficherQuestionReponse.ExecuteReader(); reader.Read(); // Table Sondage int idsondage = (int)reader["IdSondage"]; // plus claire mais dangereux si je rechange nom dans la BDD string question = (string)reader["Question"]; string choix1 = (string)reader["Choix1"]; string choix2 = (string)reader["Choix2"]; string choix3 = (string)reader["Choix3"]; string choix4 = (string)reader["Choix4"]; //bool isChoixMultiple = (bool)reader["Choix4"]; fonctionne pas // bool isDisabled = (bool)reader.GetBoolean["IsDisabled"]; fonctionne pas bool isChoixMultiple = reader.GetBoolean(6); bool isDisabled = reader.GetBoolean(7); int numProtection = (int)reader["NumProtection"]; // Table Reponse int nombreVoteC1 = (int)reader["NombreVoteC1"]; int nombreVoteC2 = (int)reader["NombreVoteC2"]; int nombreVoteC3 = (int)reader["NombreVoteC3"]; int nombreVoteC4 = (int)reader["NombreVoteC4"]; int nombreTotalVote = (int)reader["NombreTotalVote"]; int fKIdSondage = (int)reader["FKIdSondage"]; Sondage sondage = new Sondage(idsondage, question, choix1, choix2, choix3, choix4, isChoixMultiple, isDisabled, numProtection); Reponse vote = new Reponse(sondage, nombreVoteC1, nombreVoteC2, nombreVoteC3, nombreVoteC4, nombreTotalVote, fKIdSondage); return(vote); } }
// Création dans la table réponse de la BDD les champs séléctionné par l'utilisateur dans la view Formulaire public static void CreationReponse(int idSondage) { Reponse model = new Reponse(idSondage); using (SqlConnection connection = new SqlConnection(ConnectionString)) // NombreVoteC1 ... C : correspond à choix 1; dans la BDD dans table Reponse NombreVoteC1: cela signifie Nombre vite pour choix1 { connection.Open(); SqlCommand insererReponseBDD = new SqlCommand("INSERT INTO Reponse(NombreVoteC1, NombreVoteC2, NombreVoteC3, NombreVoteC4, NombreTotalVote, FKIdSondage) VALUES (@nombreVoteC1,@nombreVoteC2,@nombreVoteC3,@nombreVoteC4,@nombreTotalVote,@fKIdSondage)", connection); insererReponseBDD.Parameters.AddWithValue("@nombreVoteC1", model.NombreVoteC1); // 0 : ??? insererReponseBDD.Parameters.AddWithValue("@nombreVoteC2", model.NombreVoteC2); insererReponseBDD.Parameters.AddWithValue("@nombreVoteC3", model.NombreVoteC3); insererReponseBDD.Parameters.AddWithValue("@nombreVoteC4", model.NombreVoteC4); insererReponseBDD.Parameters.AddWithValue("@nombreTotalVote", model.NombreTotalVote); insererReponseBDD.Parameters.AddWithValue("@fKIdSondage", idSondage); // != avt 0:? insererReponseBDD.ExecuteNonQuery(); // ExecuteNonQuery(): // ExecuteReader(): // dataReader.Read(): } }