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

📄 communityutility.cs

📁 C#邮件代码库,用于邮件发送
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace ASPNET.StarterKit.Communities {

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


    //*********************************************************************
    //
    // CommunityUtility Class
    //
    // Contains static utility methods for working with communities. 
    //
    //*********************************************************************

    public class CommunityUtility {



        //*********************************************************************
        //
        // ClearCommunityCache Method
        //
        // Removes all communities from the Cache 
        //
        //*********************************************************************
    
        public static void ClearCommunityCache() {
            HttpContext.Current.Cache.Remove( "Communities" );
        }




        //*********************************************************************
        //
        // GetCommunityInfo Method
        //
        // Returns the current community by 
        // examining the subdomain, domain and IP. 
        //
        //*********************************************************************
    
        public static CommunityInfo GetCommunityInfo() {
        
            // Calculate Domain and Subdomain
            string domain;
            string subDomain="*";

            HttpContext Context = HttpContext.Current;
            string host = Context.Request.Url.Host.ToLower();
        
            string[] segs = host.Split( '.' );

            switch (segs.Length) {
                case 2:
                    domain = segs[0] + "." + segs[1];
                    break;
                case 3:
                    domain = segs[1] + "." + segs[2];
                    subDomain = segs[0];
                    break;     
                default: 
                    domain = host;
                    break;        
            }


            // Retrieve IP
            string ip = Context.Request.ServerVariables["Local_Addr"]; 
            
            // Find matching communities
            string strMatch = String.Format("(community_domain='{0}' OR community_domain='*') AND (community_subDomain='{1}' OR community_subDomain='*')", domain, subDomain);
            DataRow[] drowMatches = GetAllCommunities().Tables[0].Select( strMatch );
            if (drowMatches.Length == 0)
                return null;

			if (drowMatches.Length == 1) 
                return new CommunityInfo(drowMatches[0]);

			if ((string)drowMatches[0]["Community_subDomain"] != "*")
				return new CommunityInfo(drowMatches[0]);
			else
				return new CommunityInfo(drowMatches[1]);
			
		}     
    

		public static CommunityInfo GetCommunity(int communityID)
		{
			DataRow[] matches = GetAllCommunities().Tables[0].Select( "Community_ID=" + communityID.ToString() );
			return new CommunityInfo(matches[0]);
		}



        //*********************************************************************
        //
        // GetAllCommunities Method
        //
        // Returns a list of all communities from cache, if that
        // fails, the method goes to the database. 
        //
        //*********************************************************************
    
        public static DataSet GetAllCommunities() {
            HttpContext Context = HttpContext.Current;
            DataSet dstCommunities = (DataSet)Context.Cache[ "Communities" ];
            if (dstCommunities == null) {
                dstCommunities = GetAllCommunitiesFromDB();
                Context.Cache[ "Communities" ] = dstCommunities;
            }
            return dstCommunities;
        }


        //*********************************************************************
        //
        // GetAllCommunitiesFromDB Method
        //
        // Returns a list of all communities from the database. 
        //
        //*********************************************************************
            
        private static DataSet GetAllCommunitiesFromDB() {
            SqlDataAdapter dadCommunities = new SqlDataAdapter( "Community_CommunitiesGetAllCommunities", CommunityGlobals.ConnectionString );
            dadCommunities.SelectCommand.CommandType = CommandType.StoredProcedure;
            DataSet dstCommunities = new DataSet();
            dadCommunities.Fill( dstCommunities );
            return dstCommunities;  
        }


		//*********************************************************************
		//
		// GetAllCommunitiesSorted Method
		//
		// Returns a list of all communities from cache, if that
		// fails, the method goes to the database. 
		//
		//*********************************************************************
    
		public static DataView GetAllCommunitiesSorted() 
		{
			DataView dv = GetAllCommunities().Tables[0].DefaultView;
			dv.Sort = "Community_sortOrder";
			return dv;
		}





		//*********************************************************************
		//
		// MoveCommunityUp Method
		//
		// Adds a new community to the database. 
		//
		//*********************************************************************
    
		public static void MoveCommunityUp(int communityID) 
		{
			SqlConnection conPortal = new SqlConnection( CommunityGlobals.ConnectionString );
			SqlCommand cmdAdd = new SqlCommand( "Community_CommunitiesMoveUp", conPortal );
			cmdAdd.CommandType = CommandType.StoredProcedure;
			cmdAdd.Parameters.Add( "@communityID", communityID );
			conPortal.Open();
			cmdAdd.ExecuteNonQuery();
			conPortal.Close();
		}

		//*********************************************************************
		//
		// MoveCommunityDown Method
		//
		// Adds a new community to the database. 
		//
		//*********************************************************************
    
		public static void MoveCommunityDown(int communityID) 
		{
			SqlConnection conPortal = new SqlConnection( CommunityGlobals.ConnectionString );
			SqlCommand cmdAdd = new SqlCommand( "Community_CommunitiesMoveDown", conPortal );
			cmdAdd.CommandType = CommandType.StoredProcedure;
			cmdAdd.Parameters.Add( "@communityID", communityID );
			conPortal.Open();
			cmdAdd.ExecuteNonQuery();
			conPortal.Close();
		}



        //*********************************************************************
        //
        // AddCommunity Method
        //
        // Adds a new community to the database. 
        //
        //*********************************************************************
    
        public static int AddCommunity(string name, string primaryDomain, string domain, string subDomain, string smtpServer, int databaseQuota, bool isDisplayed) {
            SqlConnection conPortal = new SqlConnection( CommunityGlobals.ConnectionString );
            SqlCommand cmdAdd = new SqlCommand( "Community_CommunitiesAddCommunity", conPortal );
            cmdAdd.CommandType = CommandType.StoredProcedure;
            cmdAdd.Parameters.Add( "@RETURN_VALUE", SqlDbType.Int ).Direction = ParameterDirection.ReturnValue;
            cmdAdd.Parameters.Add( "@name", name );
			cmdAdd.Parameters.Add( "@primaryDomain", primaryDomain );

⌨️ 快捷键说明

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