EntrepotContact.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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> GetAllContactByCodeRNE(string codeRNE)
  13. {
  14. IList<Contact> resultat = GetByCodeRNE(codeRNE);
  15. Contact cg = GetConseillerGeneralByRNE(codeRNE);
  16. if (cg != null)
  17. resultat.Add(cg);
  18. return resultat;
  19. }
  20. public IList<Contact> GetByCodeRNE(string codeRNE)
  21. {
  22. IList<Contact> resultat = new List<Contact>();
  23. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  24. {
  25. try
  26. {
  27. connexion.Open();
  28. using (SqlCommand command = connexion.CreateCommand())
  29. {
  30. command.CommandText = "SELECT * FROM Contact WHERE CodeRNE = @RNE";
  31. command.Parameters.AddWithValue("@RNE", codeRNE);
  32. using (SqlDataReader dr = command.ExecuteReader())
  33. {
  34. while (dr.Read())
  35. {
  36. resultat.Add(new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Fonction"].ToString(),dr["TypeContact"].ToString()));
  37. }
  38. }
  39. }
  40. }
  41. catch
  42. {
  43. throw;
  44. }
  45. finally
  46. {
  47. if (connexion.State == ConnectionState.Open)
  48. connexion.Close();
  49. }
  50. }
  51. return resultat;
  52. }
  53. public Contact GetConseillerGeneralByRNE(string codeRNE)
  54. {
  55. Contact resultat = null;
  56. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  57. {
  58. try
  59. {
  60. connexion.Open();
  61. using (SqlCommand command = connexion.CreateCommand())
  62. {
  63. command.CommandText = "SELECT * FROM Contact WHERE id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
  64. command.Parameters.AddWithValue("@RNE", codeRNE);
  65. using (SqlDataReader dr = command.ExecuteReader())
  66. {
  67. if (dr.Read())
  68. {
  69. resultat = new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Fonction"].ToString(), dr["TypeContact"].ToString());
  70. }
  71. }
  72. }
  73. }
  74. catch
  75. {
  76. throw;
  77. }
  78. finally
  79. {
  80. if (connexion.State == ConnectionState.Open)
  81. connexion.Close();
  82. }
  83. return resultat;
  84. }
  85. }
  86. }
  87. }