EntrepotMCG.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 WHERE Etablissement.CodeRNE = @RNE and Contact.Fonction='Directeur MCG';";
  25. command.Parameters.AddWithValue("@RNE", codeRNE);
  26. using (SqlDataReader dr = command.ExecuteReader())
  27. {
  28. if (dr.Read())
  29. {
  30. resultat = new MCG(dr["Ville"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString());
  31. }
  32. }
  33. }
  34. }
  35. catch (Exception erreurInterne)
  36. {
  37. throw new Exception(" " + erreurInterne);
  38. }
  39. finally
  40. {
  41. if (connexion.State == ConnectionState.Open)
  42. connexion.Close();
  43. }
  44. }
  45. return resultat;
  46. }
  47. }
  48. }