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 EntrepotRestauration : EntrepotBase, IEntrepotRestauration { public Restauration GetByRNEAndAnnee(string codeRNE, int annee) { Restauration resultat = null; using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion)) { try { connexion.Open(); using (SqlCommand command = connexion.CreateCommand()) { command.CommandText = "SELECT * FROM Restauration WHERE CodeRNE = @RNE AND Annee = @Annee"; command.Parameters.AddWithValue("@RNE", codeRNE); command.Parameters.AddWithValue("@Annee", annee); using (SqlDataReader dr = command.ExecuteReader()) { if (dr.Read()) { resultat = new Restauration(Convert.ToInt16(dr["Annee"].ToString()),dr["CodeRNE"].ToString(),Convert.ToInt16(dr["NbJourRestauration"].ToString()), Convert.ToInt32(dr["NbRepasAnnuel"]),Convert.ToBoolean(dr["Production"].ToString()),dr["DélégationSP"].ToString(),dr["Heberge"].ToString(),dr["EstHebergePar"].ToString(),dr["Telerestaure"].ToString(),dr["EstTelerestaurePar"].ToString()); //resultat = new Restauration(Convert.ToInt16(dr["Annee"].ToString()), dr["CodeRNE"].ToString(), Convert.ToInt16(dr["NbDemiPensionnaire"].ToString()), Convert.ToInt32(dr["NbRepasAnnuel"]), Convert.ToBoolean(dr["Production"].ToString()), dr["DélégationSP"].ToString(), dr["Heberge"].ToString(), dr["EstHebergePar"].ToString(), dr["Telerestaure"].ToString(), dr["EstTelerestaurePar"].ToString()); } } } } catch (Exception erreurInterne) { throw new Exception(" " + erreurInterne); } finally { if (connexion.State == ConnectionState.Open) connexion.Close(); } return resultat ; } } } }