EntrepotATC.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 EntrepotATC : EntrepotBase, IEntrepotATC
  11. {
  12. public IList<ATC> GetByCodeRNE(string codeRNE)
  13. {
  14. IList<ATC> resultat = new List<ATC>();
  15. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  16. {
  17. try
  18. {
  19. int nbJourFormation;
  20. connexion.Open();
  21. using (SqlCommand command = connexion.CreateCommand())
  22. {
  23. //on récupère les ATC.
  24. command.CommandText = "Select ValeurETP, TypeContact, Nom, Prenom, Fonction, Fonction, Catégorie, Grade, Sum(NbJours) as NbJoursFormation from ATC INNER JOIN Contact ON (ATC.Id = Contact.Id) LEFT JOIN Formation_ATC ON (ATC.Id = Formation_ATC.IdATC) WHERE CodeRNE = @RNE GROUP BY ValeurETP, TypeContact, Nom, Prenom, Fonction, Fonction, Catégorie, Grade";
  25. command.Parameters.AddWithValue("@RNE", codeRNE);
  26. using (SqlDataReader dr = command.ExecuteReader())
  27. {
  28. while (dr.Read())
  29. {
  30. nbJourFormation = dr["NbJoursFormation"] == DBNull.Value ? 0 : Convert.ToInt32(dr["NbJoursFormation"].ToString());
  31. resultat.Add(new ATC(Convert.ToDouble(dr["ValeurETP"].ToString()), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Fonction"].ToString(), dr["TypeContact"].ToString(), dr["Catégorie"].ToString(), dr["Grade"].ToString(), nbJourFormation ));
  32. }
  33. }
  34. }
  35. }
  36. catch (Exception erreurInterne)
  37. {
  38. throw new Exception(" " + erreurInterne);
  39. }
  40. finally
  41. {
  42. if (connexion.State == ConnectionState.Open)
  43. connexion.Close();
  44. }
  45. }
  46. return resultat;
  47. }
  48. }
  49. }