⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topicutility.cs

📁 ASP开发网站的 关于网站的设计和说明 还有SQL的程序 数据库
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Web;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;


    //*********************************************************************
    //
    // TopicUtility Class
    //
    // Contains static utility methods used by the Topics module. 
    //
    //*********************************************************************

    public class TopicUtility {


        //*********************************************************************
        //
        // ClearCache Method
        //
        // Removes all cached topics from the cache for this community. 
        //
        //*********************************************************************
    
        public static void ClearCache() {
            HttpContext.Current.Cache.Remove( CommunityGlobals.CacheKey("Topics") );
        }

    
        //*********************************************************************
        //
        // GetLatestTopics Method
        //
        // Gets topics of the latest content listed and caches the list. 
        //
        //*********************************************************************
    
        public static ArrayList GetLatestTopics(int cacheDuration) {
            HttpContext Context = HttpContext.Current;
            ArrayList colTopics = (ArrayList)Context.Cache[ CommunityGlobals.CacheKey("LatestTopics") ];
            if (colTopics == null) {
                colTopics = GetLatestTopicsFromDB();
                Context.Cache.Insert( CommunityGlobals.CacheKey("LatestTopics"), colTopics, null, 
                    DateTime.Now.AddMinutes(cacheDuration), System.Web.Caching.Cache.NoSlidingExpiration);
            }
            return colTopics;
        }

    
        //*********************************************************************
        //
        // GetLatestTopicsFromDB Method
        //
        // Gets the latest topics from the database. 
        //
        //*********************************************************************
    
        public static ArrayList GetLatestTopicsFromDB() {
            TopicInfo objTopicInfo = null;
            ArrayList colTopics = new ArrayList();
            Hashtable hashTopics = new Hashtable();
    
            SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
            SqlCommand cmdGetTopics = new SqlCommand( "Community_TopicsGetLatestTopics", conPortal);
            cmdGetTopics.CommandType = CommandType.StoredProcedure;
            cmdGetTopics.Parameters.Add( "@communityID", CommunityGlobals.CommunityID);
            
            
            conPortal.Open();
            SqlDataReader dr = cmdGetTopics.ExecuteReader();
            while (dr.Read()) {
                objTopicInfo = PopulateTopicInfoFromSqlDataReader(dr);
                if (!hashTopics.Contains(objTopicInfo.Name)) {
                    colTopics.Add(objTopicInfo);
                    hashTopics[objTopicInfo.Name] = "1";
                }
            }            
            conPortal.Close();
    
            return colTopics;
        }
    
    
        //*********************************************************************
        //
        // GetAllTopics Method
        //
        // Gets a list of all the topics for this community. 
        //
        //*********************************************************************
    
        public static ArrayList GetAllTopics() {
            HttpContext Context = HttpContext.Current;
            ArrayList colTopics = (ArrayList)Context.Cache[ CommunityGlobals.CacheKey("Topics") ];
            if (colTopics == null)
            {
                colTopics = GetAllTopicsFromDB();
                Context.Cache[ CommunityGlobals.CacheKey("Topics") ] = colTopics;
            }
            return colTopics;
        }
        
        //*********************************************************************
        //
        // GetAllTopicsFromDB Method
        //
        // Gets a list of all the topics for this community from the database. 
        //
        //*********************************************************************
        
        public static ArrayList GetAllTopicsFromDB() {
            SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
            SqlCommand cmdGetTopics = new SqlCommand( "Community_TopicsGetTopics", conPortal);
            cmdGetTopics.CommandType = CommandType.StoredProcedure;
            cmdGetTopics.Parameters.Add( "@communityID", CommunityGlobals.CommunityID);
            
            ArrayList colTopics = new ArrayList();
            conPortal.Open();
            SqlDataReader dr = cmdGetTopics.ExecuteReader();
            while (dr.Read())
                colTopics.Add(PopulateTopicInfoFromSqlDataReader(dr));
            conPortal.Close();
            return colTopics;
        }
        

        //*********************************************************************
        //
        // PopulateTopicInfoFromSqlDataReader Method
        //
        // Creates TopicInfo object from a SqlDataReader. 
        //
        //*********************************************************************
        
        private static TopicInfo PopulateTopicInfoFromSqlDataReader(SqlDataReader dr) {
            TopicInfo objTopicInfo = new TopicInfo();
            
            objTopicInfo.ID = (int)dr["Topic_ID"];
            objTopicInfo.Name = (string)dr["Topic_Name"];
            objTopicInfo.Description = (string)dr["Topic_Description"];
            if (dr["Topic_Image"] != DBNull.Value)
                objTopicInfo.Image = (string)dr["Topic_Image"];
            
            return objTopicInfo;
        }
        

        //*********************************************************************
        //
        // GetTopicFromName Method
        //
        // Gets a TopicInfo object given a topic name. 
        //
        //*********************************************************************
        
        public static TopicInfo GetTopicFromName(string topicName) {
            ArrayList colTopics = GetAllTopics();
            foreach (TopicInfo objTopicInfo in colTopics)
                if (objTopicInfo.Name == topicName)
                    return objTopicInfo;
            return null;
        }
        

        //*********************************************************************
        //
        // GetTopicFromID Method
        //
        // Gets a TopicInfo object given a topic ID. 
        //
        //*********************************************************************
                
        public static TopicInfo GetTopicFromID(int topicID) {
            ArrayList colTopics = GetAllTopics();
            foreach (TopicInfo objTopicInfo in colTopics)
                if (objTopicInfo.ID == topicID)
                    return objTopicInfo;
            return null;
        }
        


        //*********************************************************************
        //
        // GetTopicContent Method
        //
        // Gets a list of content under a particular topic. 
        //
        //*********************************************************************
        
        public static ArrayList GetTopicContent(string username, int topicID, int pageSize, int pageIndex, string sortOrder) {
            SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
            SqlCommand cmdGetTopics = new SqlCommand( "Community_TopicsGetContent", conPortal);
            cmdGetTopics.CommandType = CommandType.StoredProcedure;
            
        
            cmdGetTopics.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdGetTopics.Parameters.Add("@username", username);
            cmdGetTopics.Parameters.Add("@topicID", topicID);
			cmdGetTopics.Parameters.Add("@pageSize", pageSize);
			cmdGetTopics.Parameters.Add("@pageIndex", pageIndex);
            
            ArrayList colTopicContent = new ArrayList();
            conPortal.Open();
            SqlDataReader dr = cmdGetTopics.ExecuteReader();
            while (dr.Read())
                colTopicContent.Add(new ContentInfo(dr));
            conPortal.Close();
                return colTopicContent;
        }



        //*********************************************************************
        //
        // GetTotalRecords Method
        //
        // Gets total content pages under a topic. 
        //
        //*********************************************************************
        
        public static int GetTotalRecords(int topicID) {
            SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
            SqlCommand cmd = new SqlCommand( "Community_TopicsGetTotalRecords", conPortal);
            cmd.CommandType = CommandType.StoredProcedure;
            
            cmd.Parameters.Add( "@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            cmd.Parameters.Add( "@communityID", CommunityGlobals.CommunityID);
            cmd.Parameters.Add( "@topicID", topicID);

            conPortal.Open();
            cmd.ExecuteNonQuery();
            int result = (int)cmd.Parameters["@RETURN_VALUE"].Value;
            conPortal.Close();
            
            return result;
        }
    


        //*********************************************************************
        //
        // GetRelatedByTopic Method
        //
        // Gets content under the same content. 
        //
        //*********************************************************************

        public static ArrayList GetRelatedByTopic(int topicID, int excludeContentPageID) {
            ArrayList colTopicContent = new ArrayList();

            SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
            SqlCommand cmdGetTopics = new SqlCommand( "Community_TopicsGetRelated", conPortal);
            cmdGetTopics.CommandType = CommandType.StoredProcedure;
            
        
            cmdGetTopics.Parameters.Add( "@communityID", CommunityGlobals.CommunityID);
            cmdGetTopics.Parameters.Add( "@topicID", topicID);
            cmdGetTopics.Parameters.Add( "@excludeContentPageID", excludeContentPageID);
            
            conPortal.Open();
            SqlDataReader dr = cmdGetTopics.ExecuteReader();
            while (dr.Read())
                colTopicContent.Add(new ContentInfo(dr));
            conPortal.Close();
            return colTopicContent;
        }


    
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -