EntrepotContact.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. Contact cg1 = GetConseillerGeneralSuppleantByRNE(codeRNE);
  19. if (cg1 != null)
  20. resultat.Add(cg1);
  21. return resultat;
  22. }
  23. public IList<Contact> GetByCodeRNE(string codeRNE)
  24. {
  25. IList<Contact> resultat = new List<Contact>();
  26. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  27. {
  28. try
  29. {
  30. connexion.Open();
  31. using (SqlCommand command = connexion.CreateCommand())
  32. {
  33. // command.CommandText = "SELECT * FROM Contact WHERE CodeRNE = @RNE";
  34. command.CommandText = "SELECT * FROM Contact INNER JOIN Fonction ON Contact.IdFonction = Fonction.Id WHERE (CodeRNE = @RNE)";
  35. command.Parameters.AddWithValue("@RNE", codeRNE);
  36. using (SqlDataReader dr = command.ExecuteReader())
  37. {
  38. while (dr.Read())
  39. {
  40. resultat.Add(new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Libelle"].ToString(), dr["TypeContact"].ToString(), dr["Email"].ToString()));
  41. }
  42. }
  43. }
  44. }
  45. catch
  46. {
  47. throw;
  48. }
  49. finally
  50. {
  51. if (connexion.State == ConnectionState.Open)
  52. connexion.Close();
  53. }
  54. }
  55. return resultat;
  56. }
  57. public Contact GetConseillerGeneralByRNE(string codeRNE)
  58. {
  59. Contact resultat = null;
  60. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  61. {
  62. try
  63. {
  64. connexion.Open();
  65. using (SqlCommand command = connexion.CreateCommand())
  66. {
  67. //command.CommandText = "SELECT * FROM Contact WHERE id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
  68. command.CommandText = "SELECT * FROM Contact, Fonction WHERE (IdFonction = Fonction.Id) and Contact.id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
  69. command.Parameters.AddWithValue("@RNE", codeRNE);
  70. using (SqlDataReader dr = command.ExecuteReader())
  71. {
  72. if (dr.Read())
  73. {
  74. resultat = new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Libelle"].ToString(), dr["TypeContact"].ToString(), dr["Email"].ToString());
  75. }
  76. }
  77. }
  78. }
  79. catch
  80. {
  81. throw;
  82. }
  83. finally
  84. {
  85. if (connexion.State == ConnectionState.Open)
  86. connexion.Close();
  87. }
  88. return resultat;
  89. }
  90. }
  91. public Contact GetConseillerGeneralSuppleantByRNE(string codeRNE)
  92. {
  93. Contact resultat = null;
  94. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  95. {
  96. try
  97. {
  98. connexion.Open();
  99. using (SqlCommand command = connexion.CreateCommand())
  100. {
  101. //command.CommandText = "SELECT * FROM Contact WHERE id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
  102. command.CommandText = "SELECT * FROM Contact, Fonction WHERE (IdFonction = Fonction.Id) and Contact.id = (select IdSuppleant from etablissement where codeRNE=@RNE)";
  103. command.Parameters.AddWithValue("@RNE", codeRNE);
  104. string sup="suppleant";
  105. using (SqlDataReader dr = command.ExecuteReader())
  106. {
  107. if (dr.Read())
  108. {
  109. resultat = new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), sup, dr["TypeContact"].ToString(), dr["Email"].ToString());
  110. }
  111. }
  112. }
  113. }
  114. catch
  115. {
  116. throw;
  117. }
  118. finally
  119. {
  120. if (connexion.State == ConnectionState.Open)
  121. connexion.Close();
  122. }
  123. return resultat;
  124. }
  125. }
  126. }
  127. }