Пример #1
0
 /// <summary>
 /// Returns the term count of news items in a specific category, 
 /// optionally limited to interesting/uninteresting items.
 /// </summary>
 /// <param name="category">
 /// The category to which the news items must belong.
 /// </param>
 /// <param name="interesting">
 /// The interest status on the news items to count.
 /// </param>
 /// <returns>
 /// The number of terms in the given category.
 /// </returns>
 public abstract int GetTermCountInCategory(Category category, 
     InterestStatus interesting);
Пример #2
0
 public Interest(int interestID, string name, InterestStatus interestStatus)
 {
     InterestID     = interestID;
     Name           = name;
     InterestStatus = interestStatus;
 }
Пример #3
0
        /// <summary>
        /// Returns the term count of news items in a specific category, optionally
        /// limited to interesting/uninteresting items.
        /// </summary>
        /// <param name="category">
        /// The category to which the news items must belong.
        /// </param>
        /// <param name="interesting">
        /// The interest status on the news items to count.
        /// </param>
        /// <returns>
        /// The number of terms in the given category.
        /// </returns>
        public override int GetTermCountInCategory(Category category, InterestStatus interesting)
        {
            // Check that the database is open.
            if (!DatabaseConnection.State.Equals(ConnectionState.Open))
            {
                throw new InvalidOperationException(
                    "The Archivist must be open before calling this method. " +
                    "Call the Open() method.");
            }

            // Get sum of news term_count from category.
            SqlCeCommand cmd = DatabaseConnection.CreateCommand();
            cmd.CommandText = "SELECT COALESCE(SUM(term_count), 0) FROM news WHERE " +
                "category_id = ?";
            if (interesting == InterestStatus.Interesting)
            {
                cmd.CommandText += " AND user_found_interesting = 1";
            }
            else if (interesting == InterestStatus.Uninteresting)
            {
                cmd.CommandText += " AND user_found_interesting = 0";
            }
            cmd.Parameters.Add(new SqlCeParameter("cat_id", SqlDbType.Int));
            cmd.Parameters["cat_id"].Value = category.Id;
            // Execute and fetch sum.
            SqlCeDataReader rdr = cmd.ExecuteReader();
            int count = 0;
            if (rdr.Read())
            {
                count = rdr.GetInt32(0);
            }
            rdr.Close();

            return count;
        }