public override MyAirportAGM.Entities.BagageDefinition GetBagage(string codeIata) { using (SqlConnection cnx = new SqlConnection(strcnx)) { SqlCommand cmd = new SqlCommand(commandGetBagage, cnx); cmd.Parameters.AddWithValue("@code", codeIata); cnx.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { BagageDefinition bag = null; if (sdr.Read()) #region cache { bag = new BagageDefinition(); bag.IdBagage = sdr.GetInt32(0); bag.Compagnie = sdr["compagnie"].ToString(); bag.Ligne = Convert.ToInt32(sdr["ligne"]); bag.JourExploitation = sdr.GetInt16(sdr.GetOrdinal("jour_exploitation")); bag.Itineraire = sdr.GetString(sdr.GetOrdinal("ESCALE")); bag.ClasseBagage = sdr["classe"] is DBNull ? 'Y' : Convert.ToChar(sdr["classe"]); bag.CodeIata = sdr.GetString(sdr.GetOrdinal("CODE_IATA")); bag.Continuation = sdr[sdr.GetOrdinal("continuation")].ToString() == "Y" ? true : false; bag.Rush = sdr.GetFieldValue<bool>(sdr.GetOrdinal("Rush")); } if (sdr.Read()) { throw new ApplicationException("Trop de résultats retournés !"); } #endregion return bag; } } }
public override List<MyAirportAGM.Entities.BagageDefinition> GetBagageList(string codeIata) { using (SqlConnection cnx = new SqlConnection(strcnx)) { SqlCommand cmd = new SqlCommand(commandGetBagage, cnx); cmd.Parameters.AddWithValue("@code", codeIata); cnx.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { List<BagageDefinition> listeBags = new List<BagageDefinition>(); BagageDefinition bag = null; //au moins un bagage a été trouvé while (sdr.Read()) #region cache { bag = new BagageDefinition(); bag.IdBagage = sdr.GetInt32(0); bag.Compagnie = sdr["compagnie"].ToString(); bag.Ligne = Convert.ToInt32(sdr["ligne"]); bag.JourExploitation = sdr.GetInt16(sdr.GetOrdinal("jour_exploitation")); bag.Itineraire = sdr.GetString(sdr.GetOrdinal("ESCALE")); bag.ClasseBagage = sdr["classe"] is DBNull ? 'Y' : Convert.ToChar(sdr["classe"]); bag.CodeIata = sdr.GetString(sdr.GetOrdinal("CODE_IATA")); bag.Continuation = sdr[sdr.GetOrdinal("continuation")].ToString() == "Y" ? true : false; bag.Rush = sdr.GetFieldValue<bool>(sdr.GetOrdinal("Rush")); listeBags.Add(bag); } #endregion return listeBags; } } }