/****************************************************************/ // GetThreadsUserMostRecentlyParticipatedIn // /// <summary> /// Returns a collection of threads that the user has recently partipated in. /// </summary> // /****************************************************************/ public ThreadCollection GetThreadsUserMostRecentlyParticipatedIn(string username, int count) { // Create Instance of Connection and Command Object SqlConnection myConnection = new SqlConnection(Globals.DatabaseConnectionString); SqlCommand myCommand = new SqlCommand("dbo.forums_GetTopicsUserMostRecentlyParticipatedIn", myConnection); ThreadCollection threads; // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC //myCommand.Parameters.Add("@Username", SqlDbType.NVarChar, 50).Value = username; myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = int.Parse(username); myCommand.Parameters.Add("@Count", SqlDbType.Int).Value = count; // Execute the command myConnection.Open(); SqlDataReader dr = myCommand.ExecuteReader(); threads = new ThreadCollection(); while (dr.Read()) { threads.Add(PopulateThreadFromSqlDataReader(dr)); } dr.Close(); myConnection.Close(); // Only return the posts specified through paging return threads; }
/// <summary> /// Get all threads /// </summary> /// <param name="SortBy">Colomn number to sort by</param> /// <param name="SortOrder">0 - ASC, 1 - DESC</param> public ThreadCollection GetAllThreads(int forumID, int pageSize, int pageIndex, DateTime endDate, string username, bool unreadThreadsOnly, int SortBy, int SortOrder) { // Create Instance of Connection and Command Object SqlConnection myConnection = new SqlConnection(Globals.DatabaseConnectionString); SqlCommand myCommand = new SqlCommand("dbo.forums_GetAllTopicsPaged", myConnection); ThreadCollection threads; // Ensure DateTime is min value for SQL if (endDate == DateTime.MinValue) endDate = (DateTime) System.Data.SqlTypes.SqlDateTime.MinValue; // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC myCommand.Parameters.Add("@ForumId", SqlDbType.Int, 4).Value = forumID; myCommand.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = pageSize; myCommand.Parameters.Add("@PageIndex", SqlDbType.Int, 4).Value = pageIndex; myCommand.Parameters.Add("@DateFilter", SqlDbType.DateTime).Value = endDate; myCommand.Parameters.Add("@SortBy", SqlDbType.Int).Value = SortBy; myCommand.Parameters.Add("@SortOrder", SqlDbType.Int).Value = SortOrder; // Only pass username if it's not null if (username == null) myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = System.DBNull.Value; else myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = int.Parse(username); //myCommand.Parameters.Add("@Username", SqlDbType.NVarChar, 50).Value = username; myCommand.Parameters.Add("@UnReadTopicsOnly", SqlDbType.Bit).Value = unreadThreadsOnly; // Execute the command myConnection.Open(); SqlDataReader dr = myCommand.ExecuteReader(); threads = new ThreadCollection(); while (dr.Read()) { threads.Add(PopulateThreadFromSqlDataReader(dr)); } dr.Close(); myConnection.Close(); // Only return the posts specified through paging return threads; }