Exemplo n.º 1
0
        //Methode pour recuperer les infos d'un sondage avec son ID
        public static Sondage GetSondageById(int idSondage)
        {
            SqlConnection connection = new SqlConnection(SqlConnectionString);

            connection.Open();

            SqlCommand maCommande = new SqlCommand(@"SELECT * " +
                                                   "FROM Sondage " +
                                                   "WHERE IdSondage=@id_sondage", connection);

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

            monReader.Read();

            int     id = Convert.ToInt32(monReader["IdSondage"]);
            string  questionSondage = (string)monReader["QuestionSondage"];
            bool    choixMultiple   = (bool)monReader["ChoixMultiple"];
            string  urlPartage      = Convert.ToString(monReader["UrlPartage"]);
            string  urlSuppression  = Convert.ToString(monReader["UrlSuppression"]);
            string  urlResultat     = Convert.ToString(monReader["UrlResultat"]);
            int     nbVotant        = Convert.ToInt32(monReader["NbVotant"]);
            int     fkIdCreateur    = Convert.ToInt32(monReader["FKIdCreateur"]);
            string  guid            = Convert.ToString(monReader["Guid"]);
            bool    actif           = Convert.ToBoolean(monReader["Actif"]);
            Sondage monSondage      = new Sondage(id, questionSondage, choixMultiple, urlPartage, urlSuppression, urlResultat, nbVotant, fkIdCreateur, guid, actif);

            connection.Close();

            return(monSondage);
        }
Exemplo n.º 2
0
        //methode pour mettre a jour le nombre de votant d'un sondage
        public static void UpdateNombreVotant(Sondage unSondage)
        {
            SqlConnection connection = new SqlConnection(SqlConnectionString);

            connection.Open();

            SqlCommand maCommande = new SqlCommand(@"UPDATE Sondage SET NbVotant = @nb_votant WHERE IdSondage = @id_sondage", connection);

            maCommande.Parameters.AddWithValue("@nb_votant", unSondage.NbVotant);
            maCommande.Parameters.AddWithValue("@id_sondage", unSondage.IdSondage);
            maCommande.ExecuteNonQuery();

            connection.Close();
        }
Exemplo n.º 3
0
        public static void DisableSondage(Sondage unSondage)
        {
            SqlConnection connection = new SqlConnection(SqlConnectionString);

            connection.Open();

            SqlCommand maCommande = new SqlCommand(@"UPDATE Sondage SET Actif=@actif WHERE IdSondage=@id_sondage", connection);

            maCommande.Parameters.AddWithValue("@actif", unSondage.Actif);
            maCommande.Parameters.AddWithValue("@id_sondage", unSondage.IdSondage);
            maCommande.ExecuteNonQuery();

            connection.Close();
        }
Exemplo n.º 4
0
 public decimal GetPourcentage(Sondage unSondage)
 {
     if (unSondage.NbVotant == 0)
     {
         return(0);
     }
     else if (!unSondage.ChoixMultiple)
     {
         return(Math.Round((((decimal)this.NbVoteReponse / (decimal)unSondage.NbVotant) * 100), 2));
     }
     else
     {
         return(Math.Round((((decimal)this.NbVoteReponse / (decimal)DAL.GetSommeVoteDesReponses(unSondage.IdSondage) * 100)), 2));
     }
 }
Exemplo n.º 5
0
        public static void EnvoiMail(Sondage sondage, Createur createur)
        {
            string EmailEnvoyeur = "*****@*****.**";
            string password      = "******";
            string objet         = "Votre sondage a été crée ";

            string htmlBody = @"<!doctype html>
                                            <html>
                                                <body>
                                                <headers>
                                                    <img src=""https://image.noelshack.com/fichiers/2018/05/2/1517339614-simpoll.png"" alt=""Logo Simpoll""/>
                                                </headers>
                                                <div>
                                                <h2>Merci " + createur.PrenomCreateur + @" d'avoir choisi Simpoll pour créer votre sondage</h2>
                                                </div>
                                                <p>Voici vos 3 liens :</p>
                                                    <ul>
                                                        <li>" + sondage.UrlPartage + @"</li>
                                                        <li>" + sondage.UrlResultat + @"</li>
                                                        <li>" + sondage.UrlSuppression + @"</li>
                                                    </ul>
                                                <p>La team Simpoll vous dit à bientôt pour de nouveaux sondage !!</p>
                                                </body>
                                                </html>";

            SmtpClient smtp = new SmtpClient
            {
                Host           = "smtp.gmail.com",
                Port           = 25,
                EnableSsl      = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials    = new NetworkCredential(EmailEnvoyeur, password),
            };

            MailMessage message = new MailMessage(EmailEnvoyeur, createur.EmailCreateur, objet, htmlBody)
            {
                IsBodyHtml = true
            };

            smtp.Send(message);
        }
Exemplo n.º 6
0
        //methode pour mettre a jour un sondage avec ses url aprés la creation du sondage
        public static void UpdateSondage(Sondage unSondage, int idSondage)
        {
            SqlConnection connection = new SqlConnection(SqlConnectionString);

            connection.Open();

            SqlCommand maCommande = new SqlCommand(@"UPDATE Sondage 
                                                     SET UrlPartage=@url_partage, 
                                                         UrlSuppression=@url_suppression, 
                                                         UrlResultat=@url_resultat 
                                                     WHERE IdSondage=@id_sondage"
                                                   , connection);

            maCommande.Parameters.AddWithValue("@url_partage", unSondage.UrlPartage);
            maCommande.Parameters.AddWithValue("@url_suppression", unSondage.UrlSuppression);
            maCommande.Parameters.AddWithValue("@url_resultat", unSondage.UrlResultat);
            maCommande.Parameters.AddWithValue("@id_sondage", idSondage);
            maCommande.ExecuteNonQuery();

            connection.Close();
        }
Exemplo n.º 7
0
        public static Sondage GetSondageByGuid(string guid)
        {
            SqlConnection connection = new SqlConnection(SqlConnectionString);

            connection.Open();

            SqlCommand maCommande = new SqlCommand(@"SELECT * FROM Sondage WHERE Guid=@my_guid", connection);

            maCommande.Parameters.AddWithValue("@my_guid", (string)guid);
            SqlDataReader monReader = maCommande.ExecuteReader();

            int    id = 0;
            string questionSondage = "";
            bool   choixMultiple   = true;
            string urlPartage      = "";
            string urlSuppression  = "";
            string urlResultat     = "";
            int    nbVotant        = 0;
            int    fkIdCreateur    = 0;
            string myGuid          = "";
            bool   actif           = true;

            monReader.Read();

            id = (int)monReader["IdSondage"];
            questionSondage = (string)monReader["QuestionSondage"];
            choixMultiple   = (bool)monReader["ChoixMultiple"];
            urlPartage      = Convert.ToString(monReader["UrlPartage"]);
            urlSuppression  = Convert.ToString(monReader["UrlSuppression"]);
            urlResultat     = Convert.ToString(monReader["UrlResultat"]);
            nbVotant        = Convert.ToInt32(monReader["NbVotant"]);
            fkIdCreateur    = Convert.ToInt32(monReader["FKIdCreateur"]);
            myGuid          = Convert.ToString(monReader["Guid"]);
            actif           = Convert.ToBoolean(monReader["Actif"]);
            Sondage monSondage = new Sondage(id, questionSondage, choixMultiple, urlPartage, urlSuppression, urlResultat, nbVotant, fkIdCreateur, myGuid, actif);

            connection.Close();

            return(monSondage);
        }
Exemplo n.º 8
0
        //Methode pour ajouter un sondage en BDD et recuperer l'ID de son createur
        public static int AddSondage(Sondage unSondage)
        {
            SqlConnection connexion = new SqlConnection(SqlConnectionString);

            connexion.Open();

            SqlCommand maCommande = new SqlCommand(@"INSERT INTO Sondage(QuestionSondage, ChoixMultiple, NbVotant, FKIdCreateur, Guid, Actif) " +
                                                   "VALUES (@question, @choix_multiple, @nb_votant, @FK_idCreateur, @my_guid, @actif); " +
                                                   "SELECT SCOPE_IDENTITY()", connexion);

            maCommande.Parameters.AddWithValue("@question", unSondage.QuestionSondage);
            maCommande.Parameters.AddWithValue("@choix_multiple", unSondage.ChoixMultiple);
            maCommande.Parameters.AddWithValue("@nb_votant", unSondage.NbVotant);
            maCommande.Parameters.AddWithValue("@FK_idCreateur", unSondage.FKIdCreateur);
            maCommande.Parameters.AddWithValue("@my_guid", unSondage.Guid);
            maCommande.Parameters.AddWithValue("@actif", unSondage.Actif);

            int IdSondage = Convert.ToInt32(maCommande.ExecuteScalar());

            connexion.Close();

            return(IdSondage);
        }
Exemplo n.º 9
0
 public SondageAvecReponse(Sondage sondage, List <Reponse> mesReponses)
 {
     this.Sondage     = sondage;
     this.MesReponses = mesReponses;
 }