Пример #1
0
        /*
         #####################################################################
         # Q8
         #              mostPopular._Brand
         #              mostPopular._Quantity
         #####################################################################
         */
        public static Most_Popular GetMostPopular()
        {
            Most_Popular mostPopular = new Most_Popular();


            return(mostPopular);
        }
Пример #2
0
        /*
         #####################################################################
         # Q8
         #              mostPopular._Brand
         #              mostPopular._Quantity
         #####################################################################
         */
        public static Most_Popular GetMostPopular()
        {
            Most_Popular mostPopular = new Most_Popular();

            if (Connect())
            {
                using (SqlCommand sqlCommand = new SqlCommand("Q8", _Connection))
                {
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.CommandText = "sp_GetMostPopular";

                    SqlDataReader reader;
                    try
                    {
                        reader = sqlCommand.ExecuteReader();
                    }
                    catch (Exception ex)
                    {
                        return(null);
                    }
                    while (reader.Read())
                    {
                        mostPopular           = new Most_Popular();
                        mostPopular._Brand    = Convert.ToString(reader[0]);
                        mostPopular._Quantity = Convert.ToInt32(reader[1]);
                    }
                    reader.Close();
                }
            }

            return(mostPopular);
        }
        /*
         #####################################################################
         # Q8
         #              mostPopular._Brand
         #              mostPopular._Quantity
         #####################################################################
         */
        public static Most_Popular GetMostPopular()
        {
            string Q8Query = " select top 1 it.BRAND, sum(i.QUANTITY) as sold  from item it " +
                             " inner join INCLUDES i on " +
                             " it.ITEMCODE= i.ITEMCODE " +
                             " group by it.BRAND " +
                             " order by sold desc, it.BRAND asc ";

            Most_Popular mostPopular = new Most_Popular();

            if (Connect())
            {
                //we are going to call query called Q8
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.CommandText = Q8Query;
                    sqlCommand.Connection  = _Connection;
                    SqlDataReader reader;
                    try
                    {
                        reader = sqlCommand.ExecuteReader();
                    }
                    catch (Exception ex)
                    {
                        return(null);
                    }
                    //Converting query results to PersonPhoneAddress objects
                    while (reader.Read())
                    {
                        mostPopular._Brand    = Convert.ToString(reader[0]);
                        mostPopular._Quantity = Convert.ToInt32(reader[1]);
                    }
                    reader.Close();
                }
            }
            return(mostPopular);
        }