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

📄 showprofile.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;


    //*********************************************************************
    //
    // ShowProfile Class
    //
    // Represents the Show Profile page. Displays a user profile.
    // If the current user is the profile user, shows an edit link
    // so that the user can edit their profile.
    //
    //*********************************************************************

    public class ShowProfile : SkinnedCommunityControl {
    
        string _skinFileName = "Users_ShowProfile.ascx";
        
        Label lblFullName;
        Panel pnlAnonymous;
        Panel pnlAuthenticated;
        Panel pnlNoProfile;
        HyperLink lnkLogin;
        Label lblDateJoined;
        Label lblLastLogin;
        HyperLink lnkWebsite;
        Label lblLocation;
        Label lblOccupation;
        Label lblInterests;
        HyperLink lnkEmail;
        Label lblMSN;
        Label lblAIM;
        Label lblYahoo;
        Label lblICQ;
        HyperLink lnkEditProfile;


        //*********************************************************************
        //
        // ShowProfile Constructor
        //
        // Calls the base SkinnedCommunityControl constructor
        // and assigns the default page skin.
        //
        //*********************************************************************

		public ShowProfile() : base() {
            // Assign a default skin file name
            if (SkinFileName == null)
                SkinFileName = _skinFileName;
        }
        
        
        //*********************************************************************
        //
        // SkinType Property
        //
        // Specifies the skins directory where this page's skin file is located.
        //
        //*********************************************************************
        
        override protected string SkinType {
            get { return "ContentSkins"; }
        }


        //*********************************************************************
        //
        // InitializeSkin Method
        //
        // Retrieves all the controls from the Page Skin
        //
        //*********************************************************************

        override protected void InitializeSkin(Control skin) {
            // Find full name label
            lblFullName = (Label)GetControl(skin, "lblFullName");
            
            // Find anonymous panel
            pnlAnonymous = (Panel)GetControl(skin, "pnlAnonymous");
            
            // Find authenticated panel
            pnlAuthenticated = (Panel)GetControl(skin, "pnlAuthenticated");
            
            // Find no profile panel
            pnlNoProfile = (Panel)GetControl(skin, "pnlNoProfile");
            
            // Find login link
            lnkLogin = (HyperLink)GetControl(skin, "lnkLogin");
            
            // Find date created label
            lblDateJoined = (Label)GetControl(skin, "lblDateJoined");

            // Find last login label
            lblLastLogin = (Label)GetControl(skin, "lblLastLogin");

            // Find Website link
            lnkWebsite = (HyperLink)GetControl(skin, "lnkWebsite");
            
            // Find location label
            lblLocation = (Label)GetControl(skin, "lblLocation");
            
            // Find occupation label
            lblOccupation = (Label)GetControl(skin, "lblOccupation");
            
            // Find interests label
            lblInterests = (Label)GetControl(skin, "lblInterests");
            
            // Find email link
            lnkEmail = (HyperLink)GetControl(skin, "lnkEmail");
            
            // Find msn messenger label
            lblMSN = (Label)GetControl(skin, "lblMSN");
        
            // Find aim label
            lblAIM = (Label)GetControl(skin, "lblAIM");
            
            // Find icq label
            lblICQ = (Label)GetControl(skin, "lblICQ");
            
            // Find yahoo label
            lblYahoo = (Label)GetControl(skin, "lblYahoo");
        
            // Find edit profile link
            lnkEditProfile = (HyperLink)GetControl(skin, "lnkEditProfile");
        } 
        
        
        //*********************************************************************
        //
        // OnLoad Method
        //
        // Assigns values to the controls from the page skin.
        //
        //*********************************************************************

        override protected void OnLoad(EventArgs e) {
            string profileUsername;
           
            if (!Page.IsPostBack) {
                EnsureChildControls();            
                
                // Who's profile?
                // If no profile is specified in query string, show current user 
                if (Context.Request.QueryString["user"] != null)
                    profileUsername = Context.Request.QueryString["user"];
                else
                    if (objUserInfo.IsAuthenticated)
                        profileUsername = objUserInfo.Username;
                    else {
                        ShowNoProfile();
                        return;
                    }
                
                // Get profile information
                ProfileInfo profile = UserUtility.GetProfile(profileUsername);
                if (profile == null) {
                    ShowNoProfile();
                    return;
                }
            

                // Hide display panels
                if (objUserInfo.IsAuthenticated) {
                    pnlNoProfile.Visible = false;
                    pnlAnonymous.Visible = false;
                    pnlAuthenticated.Visible = true;
                } else {
                    pnlNoProfile.Visible = false;
                    pnlAnonymous.Visible = true;
                    pnlAuthenticated.Visible = false;
                    lnkLogin.NavigateUrl = CommunityGlobals.CalculatePath(String.Format("Users_Login.aspx?ReturnUrl={0}", Context.Server.UrlEncode(Context.Request.RawUrl)));
                }


                // Display profile full name               
                lblFullName.Text = String.Format("{0} {1}", profile.FirstName, profile.LastName);
                
                
                // Display additional info to authenticated
                if (objUserInfo.IsAuthenticated) {
                    lblDateJoined.Text = profile.DateCreated.ToString("D");
                    lblLastLogin.Text = profile.LastLogin.ToString("D");
                    if (profile.Url == String.Empty)
                        lnkWebsite.Text = "-----";
                    else {
                        lnkWebsite.Text = profile.Url;
                        lnkWebsite.NavigateUrl = profile.Url;
                    }
                
                    // Display location
                    if (profile.Location == String.Empty)
                        lblLocation.Text = "-----";
                    else
                        lblLocation.Text = profile.Location;
                    
                    // Display occupation
                    if (profile.Occupation == String.Empty)
                        lblOccupation.Text = "-----";
                    else
                        lblOccupation.Text = profile.Occupation;
                    
                    // Display Interests
                    if (profile.Interests == String.Empty)
                        lblInterests.Text = "-----";
                    else
                        lblInterests.Text = profile.Interests;
                    
                    // Display email
                    if (profile.FakeEmail == String.Empty)
                        lnkEmail.Text = "-----";
                    else {
                        lnkEmail.Text = profile.FakeEmail;
                        lnkEmail.NavigateUrl = profile.FakeEmail;
                    }
                    
                    // Display MSN
                    if (profile.MSN == String.Empty)
                        lblMSN.Text = "-----";
                    else
                        lblMSN.Text = profile.MSN;
 
                    // Display AIM
                    if (profile.AIM == String.Empty)
                        lblAIM.Text = "-----";
                    else
                        lblAIM.Text = profile.AIM;
 
                    // Display ICQ
                    if (profile.ICQ == String.Empty)
                        lblICQ.Text = "-----";
                    else
                        lblICQ.Text = profile.ICQ;
 
                    // Display Yahoo
                    if (profile.Yahoo == String.Empty)
                        lblYahoo.Text = "-----";
                    else
                        lblYahoo.Text = profile.Yahoo;
 
                    
                    // Display Edit Profile link
                    if (objUserInfo.Username.ToLower() == profile.Username.ToLower())
                        lnkEditProfile.NavigateUrl = CommunityGlobals.CalculatePath("Users_EditProfile.aspx");
                    else
                        lnkEditProfile.Visible = false;
    
                    }
 
            }        
        }


        //*********************************************************************
        //
        // ShowNoProfile Method
        //
        // This method is called when no profile is available. It
        // displays the NoProfile panel and hides the other panels
        // in the skin.
        //
        //*********************************************************************

        void ShowNoProfile() {
            pnlAnonymous.Visible = false;
            pnlAuthenticated.Visible = false;
            pnlNoProfile.Visible = true;
        }


    }
}

⌨️ 快捷键说明

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