EntrepotRestaurationExterne.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using CG67.FicheCollege.Domaine;
  7. using CG67.FicheCollege.Interface;
  8. namespace CG67.FicheCollege.Entrepot
  9. {
  10. public class EntrepotRestaurationExterne : EntrepotBase, IEntrepotRestaurationExterne
  11. {
  12. public IList<RestaurationExterne> GetByCodeRNEAndAnnee(string codeRNE, int annee)
  13. {
  14. IList<RestaurationExterne> resultat = new List<RestaurationExterne>();
  15. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  16. {
  17. try
  18. {
  19. connexion.Open();
  20. using (SqlCommand command = connexion.CreateCommand())
  21. {
  22. command.CommandText = "SELECT Etablissement.NomCollege, RestaurationExterne.NbEleves, RestaurationExterne.TypeAide FROM RestaurationExterne INNER JOIN Etablissement ON (Etablissement.CodeRNE = RestaurationExterne.CodeRNEaidant) WHERE RestaurationExterne.CodeRNEAide = @RNE AND RestaurationExterne.Annee = @Annee";
  23. command.Parameters.AddWithValue("@RNE", codeRNE);
  24. command.Parameters.AddWithValue("@Annee", annee);
  25. using (SqlDataReader dr = command.ExecuteReader())
  26. {
  27. while (dr.Read())
  28. {
  29. resultat.Add(new RestaurationExterne(dr["NomCollege"].ToString(), Convert.ToInt16(dr["NbEleves"].ToString()), dr["TypeAide"].ToString()));
  30. }
  31. }
  32. }
  33. }
  34. catch (Exception erreurInterne)
  35. {
  36. throw new Exception(" " + erreurInterne);
  37. }
  38. finally
  39. {
  40. if (connexion.State == ConnectionState.Open)
  41. connexion.Close();
  42. }
  43. }
  44. return resultat;
  45. }
  46. }
  47. }