Ejemplo n.º 1
0
        public static bool DelProjet(Projet pr)
        {
            // création connection
            using (SqlConnection sqlConnect = GetConnection())
            {
                // projet forfait
                using (SqlCommand sqlCde = new SqlCommand())
                {
                    //initialiser la connection de la commande
                    sqlCde.Connection = sqlConnect;
                    string strSql = "DelProjet";
                    sqlCde.CommandText = strSql;
                    sqlCde.CommandType = CommandType.StoredProcedure;

                    // affectation du parametre idprojet à la procédure stockée
                    sqlCde.Parameters.Clear();
                    sqlCde.Parameters.Add(new SqlParameter("@idProjet", SqlDbType.Int)).Value = pr.CodeProjet;
                    try
                    {

                        int n = sqlCde.ExecuteNonQuery();
                        if (n != 1)
                            throw new DaoExceptionAfficheMessage("L'opération n'a pas été réalisée");
                        return true;
                    }
                    catch (SqlException se)
                    {
                        throw new DaoExceptionAfficheMessage("L'opération de suppression n'a pas été réalisée: \n" + se.Message, se);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private static void AffectParamCde(Projet pr, SqlCommand sqlCde)
 {
     sqlCde.CommandType = CommandType.StoredProcedure;
     sqlCde.Parameters.Clear();
     // affectation des parametres communs 
     sqlCde.Parameters.Add(new SqlParameter("@idClient", SqlDbType.Int)).Value = pr.LeClient.CodeClient;
     sqlCde.Parameters.Add(new SqlParameter("@nomprojet", SqlDbType.VarChar, 30)).Value = pr.NomProjet;
     sqlCde.Parameters.Add(new SqlParameter("@ddebut", SqlDbType.Date)).Value = pr.DDebut;
     sqlCde.Parameters.Add(new SqlParameter("@dfin", SqlDbType.Date)).Value = pr.DFin;
     if (pr.Contact != string.Empty)
         sqlCde.Parameters.Add(new SqlParameter("@contactclient", SqlDbType.VarChar, 30)).Value = pr.Contact;
     if (pr.MailContact != string.Empty)
         sqlCde.Parameters.Add(new SqlParameter("@mailcontact", SqlDbType.VarChar, 30)).Value = pr.MailContact;
     // affectation des parametres particuliers
     Type t = pr.GetType();
     if (t.Name == "ProjetForfait")
     {
         sqlCde.Parameters.Add(new SqlParameter("@mtcontrat", SqlDbType.Money)).Value = ((ProjetForfait)pr).MontantContrat;
         sqlCde.Parameters.Add(new SqlParameter("@penaliteouinon", SqlDbType.Bit)).Value = ((ProjetForfait)pr).PenaliteOuiNon;
         sqlCde.Parameters.Add(new SqlParameter("@idcoll", SqlDbType.Int)).Value = ((ProjetForfait)pr).ChefDeProjet.CodeColl;
     }
     else
     {
         sqlCde.Parameters.Add(new SqlParameter("@tarifjournalier", SqlDbType.Money)).Value = ((ProjetRegie)pr).TarifJournalier;
         sqlCde.Parameters.Add(new SqlParameter("@idQualif", SqlDbType.TinyInt)).Value = ((ProjetRegie)pr).Qualification.CodeQualif;
     }
 }
Ejemplo n.º 3
0
        public static void UpdProjet(Projet pr)
        {
            // création connection
            using (SqlConnection sqlConnect = GetConnection())
            {
                // projet forfait
                using (SqlCommand sqlCde = new SqlCommand())
                {
                    //initialiser la connection de la commande
                    sqlCde.Connection = sqlConnect;
                    string strSql = "UpdProjet";
                    sqlCde.CommandText = strSql;

                    // Affectation des parametres à la commande
                    AffectParamCde(pr, sqlCde);

                    // ajout du code projet en entrée
                    sqlCde.Parameters.Add(new SqlParameter("@idprojet", SqlDbType.Int)).Value = pr.CodeProjet;

                    // exécution de la requete
                    //========================
                    try
                    {
                        int n = sqlCde.ExecuteNonQuery();
                        if (n != 1)
                            throw new DaoExceptionAfficheMessage("L'opération n'a pas été réalisée");
                    }
                    catch (SqlException se)
                    {
                        throw new DaoExceptionAfficheMessage("La mise à jour n'a pas été réalisée: \n" + se.Message);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static int AddProjet(Projet pr)
        {
            // création connection
            using (SqlConnection sqlConnect = GetConnection())
            {
                // projet forfait
                using (SqlCommand sqlCde = new SqlCommand())
                {
                    //initialiser la connection de la commande
                    sqlCde.Connection = sqlConnect;
                    string strSql = "AddProjet";
                    sqlCde.CommandText = strSql;

                    // Affectation des parametres à la commande
                    AffectParamCde(pr, sqlCde);
                    // ajout du parametre typeprojet (uniquement en add)
                    sqlCde.Parameters.Add(new SqlParameter("@idTypeP", SqlDbType.TinyInt)).Value = 1;

                    // ajout du code projet en sortie 
                    SqlParameter pOut = new SqlParameter("@idProjet", SqlDbType.Int);
                    pOut.Direction = ParameterDirection.Output;
                    sqlCde.Parameters.Add(pOut);
                    
                    // exécution de la requete
                    //========================
                    try
                    {
                        int n = sqlCde.ExecuteNonQuery();
                        if (n != 1)
                            throw new DaoExceptionAfficheMessage("L'opération n'a pas été réalisée");
                        return (int)pOut.Value;
                    }
                    catch (SqlException se)
                    {
                        throw new DaoExceptionAfficheMessage("L'opération n'a pas été réalisée: \n" + se.Message, se);
                    }
                }
            }
        }