| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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 ((String.Compare(dr["Fonction"].ToString().Substring(0, 3), "ATC")) == 0)
- resultat.NbrAgentsLoges += Convert.ToInt16(dr["NbrLogements"].ToString());
- }
- }
- }
- }
- catch (Exception erreurInterne)
- {
- throw new Exception(" " + erreurInterne);
- }
- finally
- {
- if (connexion.State == ConnectionState.Open)
- connexion.Close();
- }
- }
- return resultat;
- }
- }
- }
|