Ejemplo n.º 1
0
        /// <summary>Gets the unique owner car statistics.</summary>
        /// <param name="ownerKey">The owner key.</param>
        /// <returns>A list of statistics for the unique cars owned.</returns>
        public List <OwnerCarsStatistic> GetUniqueOwnerCarStatistics(string ownerKey)
        {
            List <OwnerCarsStatistic> ownerCarsStatistics = new List <OwnerCarsStatistic>();

            var cmd = new NpgsqlCommand();

            cmd.Connection  = npgsqlConnection;
            cmd.CommandText = "SELECT carcategory, count(DISTINCT owccarkey) FROM " + tableName + " "
                              + "INNER JOIN CARS on carkey = owccarkey "
                              + "WHERE owcownkey = @ownerkey "
                              + "GROUP BY carcategory  ORDER BY carcategory ";

            cmd.Parameters.AddWithValue("ownerkey", ownerKey);
            cmd.Prepare();

            NpgsqlDataReader dataReader = cmd.ExecuteReader();

            while (dataReader.Read())
            {
                OwnerCarsStatistic ownerCarStatistic = RecordToUniqueOwnerCarStatistic(dataReader);

                ownerCarsStatistics.Add(ownerCarStatistic);
            }

            dataReader.Close();

            cmd.Dispose();

            return(ownerCarsStatistics);
        }
Ejemplo n.º 2
0
        private OwnerCarsStatistic RecordToUniqueOwnerCarStatistic(NpgsqlDataReader dataReader)
        {
            OwnerCarsStatistic ownerCarsStatistic = new OwnerCarsStatistic();

            ownerCarsStatistic.Category        = CarCategory.GetCategoryByDBValue(dataReader.GetString(0));
            ownerCarsStatistic.uniqueCarsOwned = dataReader.GetInt32(1);

            return(ownerCarsStatistic);
        }