EntrepotContact.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 EntrepotContact : EntrepotBase, IEntrepotContact
  11. {
  12. public IList<Contact> GetByCodeRNE(string codeRNE)
  13. {
  14. IList<Contact> resultat = new List<Contact>();
  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 * FROM Contact WHERE CodeRNE = @RNE";
  23. command.Parameters.AddWithValue("@RNE", codeRNE);
  24. using (SqlDataReader dr = command.ExecuteReader())
  25. {
  26. while (dr.Read())
  27. {
  28. resultat.Add(new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Fonction"].ToString(),dr["TypeContact"].ToString()));
  29. }
  30. }
  31. }
  32. }
  33. catch (Exception erreurInterne)
  34. {
  35. throw new Exception(" " + erreurInterne);
  36. }
  37. finally
  38. {
  39. if (connexion.State == ConnectionState.Open)
  40. connexion.Close();
  41. }
  42. }
  43. return resultat;
  44. }
  45. }
  46. }