EntrepotCanton.cs 4.5 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 EntrepotCanton : EntrepotBase, IEntrepotCanton
  11. {
  12. public IList<Canton> GetByCodeRNE(string codeRNE)
  13. {
  14. IList<Canton> resultat = new List<Canton>();
  15. string libelleCanton = " ";
  16. string CodeCanton = " ";
  17. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  18. {
  19. try
  20. {
  21. connexion.Open();
  22. using (SqlCommand command = connexion.CreateCommand())
  23. {
  24. // command.CommandText = "SELECT Libellé, Etablissement.CodeRNE FROM Canton INNER JOIN Etablissement ON Canton.Id = Etablissement.IdCanton WHERE Etablissement.CodeRNE = @RNE ";
  25. command.CommandText = "SELECT Libellé, Etablissement.CodeRNE, Canton.Id FROM Canton INNER JOIN Etablissement ON Canton.Id = Etablissement.IdCanton WHERE Etablissement.CodeRNE = @RNE ";
  26. command.Parameters.AddWithValue("@RNE", codeRNE);
  27. using (SqlDataReader dr = command.ExecuteReader())
  28. {
  29. if (dr.Read())
  30. {
  31. libelleCanton = dr["Libellé"].ToString();
  32. CodeCanton = dr["Id"].ToString();
  33. }
  34. using (SqlConnection connexion1 = new SqlConnection(this.ChaineDeConnexion))
  35. {
  36. try
  37. {
  38. connexion1.Open();
  39. using (SqlCommand command1 = connexion1.CreateCommand())
  40. {
  41. //command1.CommandText = "SELECT Contact.Nom, Contact.Prenom FROM Contact INNER JOIN ON ElusCanton ON ElusCanton.IdContact = Contact.Id WHERE ElusCanton.IdCanton = @IdCanton";
  42. command1.CommandText = "SELECT Contact.Civilite, Contact.Nom, Contact.Prenom, Contact.IdFonction FROM Contact INNER JOIN ElusCanton ON ElusCanton.IdContact = Contact.Id WHERE ElusCanton.IdCanton = @IdCanton ORDER BY Contact.Civilite";
  43. command1.Parameters.AddWithValue("@IdCanton", CodeCanton);
  44. using (SqlDataReader dr1 = command1.ExecuteReader())
  45. {
  46. while (dr1.Read())
  47. {
  48. resultat.Add(new Canton(libelleCanton, dr1["Civilite"].ToString(), dr1["Nom"].ToString(), dr1["Prenom"].ToString(), dr1["IdFonction"].ToString()));
  49. }
  50. }
  51. }
  52. }
  53. catch (Exception erreurInterne)
  54. {
  55. throw new Exception(" " + erreurInterne);
  56. }
  57. finally
  58. {
  59. if (connexion1.State == ConnectionState.Open)
  60. connexion1.Close();
  61. }
  62. }
  63. }
  64. }
  65. }
  66. catch (Exception erreurInterne)
  67. {
  68. throw new Exception(" " + erreurInterne);
  69. }
  70. finally
  71. {
  72. if (connexion.State == ConnectionState.Open)
  73. connexion.Close();
  74. }
  75. }
  76. return resultat;
  77. }
  78. }
  79. }