EntrepotMCG.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 EntrepotMCG : EntrepotBase, IEntrepotMCG
  11. {
  12. public MCG GetByCodeRNE(string codeRNE)
  13. {
  14. MCG resultat = null;
  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 Nom, Prenom, Ville FROM Etablissement INNER JOIN Mcg ON (Etablissement.IdMCG = Mcg.Id) INNER JOIN Contact ON (Mcg.IdContact = Contact.Id) WHERE Etablissement.CodeRNE = @RNE AND Fonction = 'Directeur MCG'";
  23. //command.CommandText = "Select Nom, Prenom, Ville FROM Etablissement INNER JOIN Mcg ON (Etablissement.IdMCG = Mcg.Id) INNER JOIN Contact ON (Mcg.IdContact = Contact.Id) WHERE Etablissement.CodeRNE = @RNE AND Fonction = 'Directeur MCG'";
  24. command.CommandText = "SELECT Etablissement.CodeRNE, Ville, Civilite, Nom, Prenom FROM Etablissement INNER JOIN (Mcg INNER JOIN Contact ON Mcg.IdContact = Contact.Id) ON Etablissement.IdMCG = Mcg.Id INNER JOIN Fonction ON (Contact.IdFonction = Fonction.Id) WHERE Etablissement.CodeRNE = @RNE and Fonction.Libelle='Directeur MCG';";
  25. command.Parameters.AddWithValue("@RNE", codeRNE);
  26. using (SqlDataReader dr = command.ExecuteReader())
  27. {
  28. if (dr.Read())
  29. {
  30. using (SqlConnection connexion1 = new SqlConnection(this.ChaineDeConnexion))
  31. {
  32. try
  33. {
  34. connexion1.Open();
  35. using (SqlCommand command1 = connexion1.CreateCommand())
  36. {
  37. command1.CommandText = "SELECT Contact.Nom, Contact.Prenom, Etablissement.CodeRNE FROM Etablissement INNER JOIN Mcg ON Etablissement.IdMCG = Mcg.Id INNER JOIN Contact ON Mcg.IdReferentPEP = Contact.Id WHERE Etablissement.CodeRNE = @RNE";
  38. command1.Parameters.AddWithValue("@RNE", codeRNE);
  39. using (SqlDataReader dr1 = command1.ExecuteReader())
  40. {
  41. if (dr1.Read())
  42. {
  43. resultat = new MCG(dr["Ville"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr1["Nom"].ToString(), dr1["Prenom"].ToString());
  44. }
  45. }
  46. }
  47. }
  48. catch (Exception erreurInterne)
  49. {
  50. throw new Exception(" " + erreurInterne);
  51. }
  52. finally
  53. {
  54. if (connexion1.State == ConnectionState.Open)
  55. connexion1.Close();
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. catch (Exception erreurInterne)
  63. {
  64. throw new Exception(" " + erreurInterne);
  65. }
  66. finally
  67. {
  68. if (connexion.State == ConnectionState.Open)
  69. connexion.Close();
  70. }
  71. }
  72. return resultat;
  73. }
  74. }
  75. }