using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using CG67.FicheCollege.Domaine; using CG67.FicheCollege.Interface; namespace CG67.FicheCollege.Entrepot { public class EntrepotLogement : EntrepotBase, IEntrepotLogement { public Logement GetByCodeRNE(string codeRNE) { Logement resultat = new Logement(); using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion)) { try { 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.Parameters.AddWithValue("@RNE", codeRNE); using (SqlDataReader dr = command.ExecuteReader()) { 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()); } } } } catch { throw; } finally { if (connexion.State == ConnectionState.Open) connexion.Close(); } } return resultat; } } }