using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using CG67.FicheCollege.Domaine; using CG67.FicheCollege.Interface; namespace CG67.FicheCollege.Entrepot { public class EntrepotActionEducative : EntrepotBase, IEntrepotActionEducative { public IList GetByCodeRNEAndAnnee(string codeRNE, int annee) { //definition de l'IList de retour. IList resultat = new List(); //utilisation de la connection pour sql server. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion)) { try { //tentative de connection. connexion.Open(); using (SqlCommand command = connexion.CreateCommand()) { //mise en place de la requete. command.CommandText = "Select * from ActionEducative INNER JOIN Etablissement_ActionEducative ON (Etablissement_ActionEducative.IdActionEducative = ActionEducative.Id) WHERE CodeRNE = @RNE AND Annee = @Annee ORDER BY TypeAction, Libelle"; //mise en place des attributs. command.Parameters.AddWithValue("@RNE", codeRNE); command.Parameters.AddWithValue("@Annee", annee); //lancement de la requete using (SqlDataReader dr = command.ExecuteReader()) { //rajout des résultats de la requete dans l'IList de retour. while (dr.Read()) { resultat.Add(new ActionEducative(dr["TypeAction"].ToString(),dr["Libelle"].ToString(), dr.GetBoolean(dr.GetOrdinal("participer")), Convert.ToInt32(dr["NbEleves"].ToString()), Convert.ToDouble(dr["MontantSubvention"].ToString()),dr["DétailAction"].ToString())); } } } } catch (Exception e) { //renvoie de l'exception ... throw new Exception(e.ToString()); } finally { //on ferme la connection si elle est ouverte. if (connexion.State == ConnectionState.Open) connexion.Close(); } } //retour de l'IList de résultat. return resultat; } } }