예제 #1
0
 // Création d'un objet de la classe Message
 // Appel de la couche DAO pour ajouter à la base de données
 public int CreerMessage(string unCorps, DateTime uneDate, int unIdCategVip, int  unIdEvent)
 {
     Message leMessage;
     CategorieVip laCateg = new CategorieVip(unIdCategVip);
     Event lEvent = new Event(unIdEvent);
     leMessage = new Message(unCorps, uneDate, laCateg, lEvent);
     return MessageDAO.GetInstanceDAOMessage().AjoutMessage(leMessage);
 }
예제 #2
0
        public int AjoutMessage(Message unMessage)
        {
            SqlConnection cnx = AccesBD.GetInstance().GetSqlConnexion();
            SqlCommand maCommand = new SqlCommand();

            maCommand.CommandType = CommandType.StoredProcedure;
            //;

            // Verifier si un message a deja été créé pour CET event ET CETTE categorie
            maCommand.Parameters.Clear();
            maCommand.CommandText = "spExistenceMessage";
            maCommand.Parameters.Add("idCategorieVip", System.Data.SqlDbType.Int);
            maCommand.Parameters[0].Value = unMessage.LaCategorieVip;
            maCommand.Parameters.Add("idEvenement", System.Data.SqlDbType.Int);
            maCommand.Parameters[1].Value = unMessage.LEvent;

            bool ret = (bool)maCommand.ExecuteScalar();
            int nb = 0;
            // On verifie si un message existe deja (false)
            // Ou si il n'existe pas (true)
            if (ret == false)
            {
                AccesBD.GetInstance().CloseConnection();
                nb = -1;
            }
            else
            {
                if (ret == true)
                {
                    maCommand.Parameters.Clear();
                    maCommand.CommandText = "spAjoutMessage";
                    maCommand.Parameters.Add("corps", System.Data.SqlDbType.Text);
                    maCommand.Parameters[0].Value = unMessage.Corps;
                    maCommand.Parameters.Add("date", System.Data.SqlDbType.DateTime);
                    maCommand.Parameters[1].Value = unMessage.Date;
                    maCommand.Parameters.Add("categ", System.Data.SqlDbType.Int);
                    maCommand.Parameters[2].Value = unMessage.LaCategorieVip;
                    maCommand.Parameters.Add("event", System.Data.SqlDbType.Int);
                    maCommand.Parameters[3].Value = unMessage.LEvent;

                    nb = (int)maCommand.ExecuteNonQuery();
                    AccesBD.GetInstance().CloseConnection();
                }
            }
            return nb;
        }