EntrepotContact.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.CommandText = "SELECT * FROM Contact INNER JOIN Fonction ON Contact.IdFonction = Fonction.Id WHERE (CodeRNE = @RNE)";
  32. command.Parameters.AddWithValue("@RNE", codeRNE);
  33. using (SqlDataReader dr = command.ExecuteReader())
  34. {
  35. while (dr.Read())
  36. {
  37. resultat.Add(new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Libelle"].ToString(),dr["TypeContact"].ToString()));
  38. }
  39. }
  40. }
  41. }
  42. catch
  43. {
  44. throw;
  45. }
  46. finally
  47. {
  48. if (connexion.State == ConnectionState.Open)
  49. connexion.Close();
  50. }
  51. }
  52. return resultat;
  53. }
  54. public Contact GetConseillerGeneralByRNE(string codeRNE)
  55. {
  56. Contact resultat = null;
  57. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  58. {
  59. try
  60. {
  61. connexion.Open();
  62. using (SqlCommand command = connexion.CreateCommand())
  63. {
  64. //command.CommandText = "SELECT * FROM Contact WHERE id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
  65. command.CommandText = "SELECT * FROM Contact, Fonction WHERE (IdFonction = Fonction.Id) and Contact.id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
  66. command.Parameters.AddWithValue("@RNE", codeRNE);
  67. using (SqlDataReader dr = command.ExecuteReader())
  68. {
  69. if (dr.Read())
  70. {
  71. resultat = new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Libelle"].ToString(), dr["TypeContact"].ToString());
  72. }
  73. }
  74. }
  75. }
  76. catch
  77. {
  78. throw;
  79. }
  80. finally
  81. {
  82. if (connexion.State == ConnectionState.Open)
  83. connexion.Close();
  84. }
  85. return resultat;
  86. }
  87. }
  88. }
  89. }