EntrepotBilinguisme.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 EntrepotBilinguisme : EntrepotBase, IEntrepotBilinguisme
  11. {
  12. public Bilinguisme GetByCodeRNEAndAnnee(string codeRNE, int annee)
  13. {
  14. Bilinguisme resultat = null;
  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 Niveau, NbEleve FROM Bilinguisme WHERE CodeRne = @RNE AND Annee = @Annee";
  23. command.Parameters.AddWithValue("@RNE", codeRNE);
  24. command.Parameters.AddWithValue("@Annee", annee);
  25. using (SqlDataReader dr = command.ExecuteReader())
  26. {
  27. List<int> lstNiveaux = new List<int>();
  28. int nombreTotalEleves = 0;
  29. while (dr.Read())
  30. {
  31. //lstNiveaux.Add(Convert.ToInt16(dr["Niveau"].ToString()));
  32. //Céline, on peut pas faire tenir "3ème" dans un int!
  33. lstNiveaux.Add(Convert.ToInt16(dr["Niveau"].ToString().Substring(0,1)));
  34. nombreTotalEleves += Convert.ToInt16(dr["NbEleve"].ToString());
  35. }
  36. resultat = new Bilinguisme(lstNiveaux, nombreTotalEleves);
  37. }
  38. }
  39. }
  40. catch (Exception erreurInterne)
  41. {
  42. throw new Exception(" " + erreurInterne);
  43. }
  44. finally
  45. {
  46. if (connexion.State == ConnectionState.Open)
  47. connexion.Close();
  48. }
  49. }
  50. return resultat;
  51. }
  52. }
  53. }