EntrepotLogement.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 EntrepotLogement : EntrepotBase, IEntrepotLogement
  11. {
  12. public Logement GetByCodeRNE(string codeRNE)
  13. {
  14. Logement resultat = new Logement();
  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 FonctionLocataire FROM Logement INNER JOIN Logement_Contact ON (Logement.Id = Logement_Contact.IdLogement) WHERE (Logement.CodeRNE= @RNE)";
  23. command.CommandText = "SELECT FonctionOccupantReel FROM Logement WHERE (Logement.CodeRNE= @RNE)";
  24. command.Parameters.AddWithValue("@RNE", codeRNE);
  25. using (SqlDataReader dr = command.ExecuteReader())
  26. {
  27. int NbrAgents = 0;
  28. int NbrLogements = 0;
  29. while (dr.Read())
  30. {
  31. NbrLogements = NbrLogements + 1 ;
  32. if (dr["FonctionOccupantReel"].ToString().Contains("ATC"))
  33. // if (dr["FonctionLocataire"].ToString().Contains("ATC"))
  34. NbrAgents=NbrAgents + 1 ;
  35. }
  36. resultat.NbrLogements = Convert.ToInt16(NbrLogements.ToString());
  37. resultat.NbrAgentsLoges = Convert.ToInt16(NbrAgents.ToString());
  38. }
  39. }
  40. }
  41. catch
  42. {
  43. throw;
  44. }
  45. finally
  46. {
  47. if (connexion.State == ConnectionState.Open)
  48. connexion.Close();
  49. }
  50. }
  51. return resultat;
  52. }
  53. }
  54. }