コード例 #1
0
        /// <summary>
        /// Creates a car range from a data reader
        /// </summary>
        /// <param name="dataReader">The data reader</param>
        /// <returns>CarRange representation of the data</returns>
        private CarRange GetRangeFromDataReader(SqlDataReader dataReader)
        {
            CarRange range = new CarRange();

            range.Id = DataUtil.GetInt32(dataReader, "CARRanId");
            range._manufacturerId   = DataUtil.GetInt32(dataReader, "CARManId");
            range.Name              = DataUtil.GetString(dataReader, "Range", null);
            range.NameWithYears     = DataUtil.GetString(dataReader, "RangeYear", null);
            range.IntroducedYear    = DataUtil.GetInt32(dataReader, "RangeIntroduced");
            range.DiscontinuedYear  = DataUtil.GetInt32(dataReader, "RangeDiscontinued", Int32.MaxValue);
            range.CarCheckProductId = DataUtil.GetInt32(dataReader, "CarCheckProductId");
            range.CarCheckSnippet   = DataUtil.GetString(dataReader, "CheckSnippet");
            range.PopularityRank    = DataUtil.GetInt32(dataReader, "PopularityRank");
            range.Popularity        = DataUtil.GetDouble(dataReader, "Popularity");

            return(range);
        }
コード例 #2
0
        /// <summary>
        /// Calls Ran_Select_ById or Ran_S_AllInManById to create a range
        /// </summary>
        /// <param name="id">The range id</param>
        /// <param name="hintManufacturer">Precache all ranges from this manufacturer if the requested range is not already cached</param>
        /// <returns>A car range</returns>
        private ICarRange GetRangeFromId(int id, bool hintManufacturer)
        {
            if (id == 0)
            {
                return(null);
            }

            CarRange result    = null;
            Sproc    procedure = new Sproc("Ran_Select_ById", DatabaseName);

            if (hintManufacturer)
            {
                procedure.Name = "Ran_S_AllInManById";
                procedure.Parameters.Add("@CARRanId", SqlDbType.Int).Value = id;
            }
            else
            {
                procedure.Parameters.Add("@Id", SqlDbType.Int).Value = id;
            }

            using (SqlDataReader dataReader = procedure.ExecuteReader())
            {
                if (dataReader != null && dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        CarRange range = this.GetRangeFromDataReader(dataReader);
                        if (range.Id == id)
                        {
                            result = range;
                        }
                    }
                }
            }

            return(result);
        }
コード例 #3
0
 /// <summary>
 /// Backs the base.Range property
 /// </summary>
 /// <returns></returns>
 protected override IRange GetRange()
 {
     return(CarRange.FromId(RangeId));
 }