using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using NBear.Common;

public partial class _UserInfo : System.Web.UI.Page
{
    protected static Aspxcn.ServiceImpls.MessageService cmd = new Aspxcn.ServiceImpls.MessageService();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!Request.QueryString.HasKeys())
            {
                LoadGuestUserInfo("无此用户");
            }
            else
            {
                if (Request.QueryString["user"].ToString().IndexOf("访客") >= 0)
                {

                    LoadGuestUserInfo(Request.QueryString["user"].ToString());
                }
                else
                {
                    LoadRegUserInfo(Request.QueryString["user"].ToString());
                }
            }

        }
    }

    private void LoadRegUserInfo(string RegUserName)
    {
        try
        {
            Response.Expires = -1;
            MembershipUser user = Membership.GetUser(RegUserName);
            if(user!=null)
            {
                if (User.Identity.Name!="")
                {
                    sendMsg.Enabled = true;
                    sendMsg.OnClientClick = "showModalDialog('msg.aspx?user=" + Server.UrlEncode(RegUserName) + "','msg','dialogWidth:600pt;dialogHeight:350pt;status:0');";
                }
                else
                {
                    sendMsg.Enabled = false;
                }
                UserName.Text = RegUserName;
                userEmail.Text = "点击发送Email";
                userEmail.OnClientClick = "window.open('mailto:" + user.Email.ToString() + "')";
                regTime.Text = user.CreationDate.ToString("yyyy/MM/dd HH:mm");
                if (user.Comment == "admin")
                {
                    userType.Text = "管理员";
                }
                else
                {
                    userType.Text = "注册用户";
                }

                lastLogin.Text = user.LastLoginDate.ToString("yyyy/MM/dd HH:mm");
                UserPost.Text = cmd.GetUserPost(RegUserName).ToString();
                if (user.IsOnline)
                {
                    IsOnline.Text = "是";
                }
                else
                {
                    IsOnline.Text = "否";
                }
                
                ProfileCommon userProfile = Profile.GetProfile(RegUserName);
                homePage.Text = Server.HtmlEncode(userProfile.homepage);
                homePage.NavigateUrl = Server.HtmlEncode(userProfile.homepage);
                msn.Text = Server.HtmlEncode(userProfile.msn);
                qq.Text = Server.HtmlEncode(userProfile.qq);
                
                if (homePage.Text!=""||msn.Text!=""||qq.Text!="")
                {
                    Membership.UpdateUser(user);
                }
            }
            else
            {
                sendMsg.Enabled = false;
                UserName.Text = "无此用户";
            }
        }
        catch
        {
        }
    }

    private void LoadGuestUserInfo(string userName)
    {
        try
        {
            UserName.Text = userName;
            if (Request.QueryString["mail"] != null)
            {
                if (Request.QueryString["mail"].ToString() != "")
                {
                    userEmail.Text = "点击发送Email";
                    userEmail.OnClientClick = "window.open('mailto:" + Request.QueryString["mail"].ToString() + "')";
                }
                else
                {
                    userEmail.Text = "不明";
                }
            }
            else
            {
                userEmail.Text = "不明";
            }
            regTime.Text = "不明";
            userType.Text = "访客";
            IsOnline.Text = "不明";
            UserPost.Text = "不明";
            lastLogin.Text = "不明";
            homePage.Text = "不明";
            qq.Text = "不明";
            msn.Text = "不明";
            sendMsg.Enabled = false;
        }
        catch
        {

        }
    }
}
