Celine.meneu 16 年之前
父節點
當前提交
bc113d8c5a

+ 18 - 10
CG67.FicheCollege.root/CG67.FicheCollege/Core/CG67.FicheCollege.Entrepot/EntrepotLogement.cs

@@ -20,20 +20,27 @@ namespace CG67.FicheCollege.Entrepot
                     connexion.Open();
                     using (SqlCommand command = connexion.CreateCommand())
                     {
-                        command.CommandText = "SELECT count(Logement.Id) as NbrLogements, Contact.Fonction FROM Logement LEFT JOIN Logement_Contact ON (Logement.Id = Logement_Contact.IdLogement) LEFT JOIN Contact ON (Logement_Contact.IdContact = Contact.Id) WHERE Logement.CodeRNE = @RNE AND Logement_Contact.DateSortie is NULL AND Contact.CodeRNE  = @RNE Group BY Contact.Fonction";
+                        command.CommandText = "SELECT FonctionLocataire FROM Logement INNER JOIN Logement_Contact ON (Logement.Id = Logement_Contact.IdLogement) WHERE (Logement.CodeRNE= @RNE)";
                         command.Parameters.AddWithValue("@RNE", codeRNE);
                         using (SqlDataReader dr = command.ExecuteReader())
                         {
+                            int NbrAgents = 0;
+                            int NbrLogements = 0;
                             while (dr.Read())
-                            {
-                                resultat.NbrLogements += Convert.ToInt16(dr["NbrLogements"].ToString());
-                                // Si la fonction est de type ATC* (maintenance, entretien, etc...) on ajoute le nombre de logements au nombre d'agents logés (cf. requete)
-                                if (dr["Fonction"].ToString().StartsWith ("ATC"))
-                                    resultat.NbrAgentsLoges += Convert.ToInt16(dr["NbrLogements"].ToString());
+                           {
+                               NbrLogements = NbrLogements + 1 ;
+                       
+                              if (dr["FonctionLocataire"].ToString().Contains("ATC"))
+                                  NbrAgents=NbrAgents + 1 ;
                             }
-                        }
-                    }
-                }
+
+                            resultat.NbrLogements = Convert.ToInt16(NbrAgents.ToString());
+                              resultat.NbrAgentsLoges = Convert.ToInt16(NbrAgents.ToString());
+                           
+                            }
+                          }
+                   }
+                
                 catch 
                 {
                     throw;
@@ -46,5 +53,6 @@ namespace CG67.FicheCollege.Entrepot
             }
             return resultat;
         }
+        }
     }
-}
+