EntrepotLogement.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.Parameters.AddWithValue("@RNE", codeRNE);
  24. using (SqlDataReader dr = command.ExecuteReader())
  25. {
  26. int NbrAgents = 0;
  27. int NbrLogements = 0;
  28. while (dr.Read())
  29. {
  30. NbrLogements = NbrLogements + 1 ;
  31. if (dr["FonctionLocataire"].ToString().Contains("ATC"))
  32. NbrAgents=NbrAgents + 1 ;
  33. }
  34. resultat.NbrLogements = Convert.ToInt16(NbrAgents.ToString());
  35. resultat.NbrAgentsLoges = Convert.ToInt16(NbrAgents.ToString());
  36. }
  37. }
  38. }
  39. catch
  40. {
  41. throw;
  42. }
  43. finally
  44. {
  45. if (connexion.State == ConnectionState.Open)
  46. connexion.Close();
  47. }
  48. }
  49. return resultat;
  50. }
  51. }
  52. }