using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 JuSNS.Home;
using JuSNS.Model;
using JuSNS.Common;

namespace JuSNS.Web.home.space
{
    public partial class Edit_link : JuSNS.UI.Page.UserPage
    {
        public static string GetTiShiDivStr = string.Empty;
        Space sp = new Space();
        public string path = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.GetHeadPath(this.UserID)))
            {
                path = this.GetHeadPath(this.UserID);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["f"]))
            {
                GetTiShiDivStr = "<div class=\"msg-warn\">您是第一次登陆本系统，请您完善基本资料。以方便未来的朋友认识您！特别是您的头像！</div>";
            }
            else
            {
                GetTiShiDivStr = string.Empty;
            }
            getLXInfo(this.UserID);

            try
            {
                string type = Request.QueryString["Type"];
                if (type == "Edit")
                {
                    Submit();
                }
                else if (type == "Privacy")
                {
                    UpdatePrivacy();
                }
            }
            catch { }
        }

        #region 读取会员联系信息
        public void getLXInfo(int UserId)
        {
            DataTable dtt = sp.getUserInfo(UserId, 11);
            if (dtt != null && dtt.Rows.Count > 0)
            {
                this.spanEmail.InnerHtml = dtt.Rows[0]["Email"].ToString();
                this.msn.Value = dtt.Rows[0]["MSN"].ToString();
                this.gtalk.Value = dtt.Rows[0]["GTalk"].ToString();
                this.qq.Value = dtt.Rows[0]["QQ"].ToString();
                this.skype.Value = dtt.Rows[0]["Skype"].ToString();
                this.mobile.Value = dtt.Rows[0]["Mobile"].ToString();
                this.landphone.Value = dtt.Rows[0]["Tel"].ToString();
                this.address.Value = dtt.Rows[0]["Addr"].ToString();
                this.website.Value = dtt.Rows[0]["WebSite"].ToString();

                this.spMsn.InnerHtml = getPrivacy(dtt.Rows[0]["MSNPrivacy"].ToString());
                this.spEmail.InnerHtml = getPrivacy(dtt.Rows[0]["EmailPrivacy"].ToString());
                this.spGtalk.InnerHtml = getPrivacy(dtt.Rows[0]["GTalkPrivacy"].ToString());
                this.spqq.InnerHtml = getPrivacy(dtt.Rows[0]["QQPrivacy"].ToString());
                this.spSkype.InnerHtml = getPrivacy(dtt.Rows[0]["SkypePrivacy"].ToString());
                this.spMobile.InnerHtml = getPrivacy(dtt.Rows[0]["MobilePrivacy"].ToString());
                this.spLandphone.InnerHtml = getPrivacy(dtt.Rows[0]["TelPrivacy"].ToString());
                this.spAddress.InnerHtml = getPrivacy(dtt.Rows[0]["AddrPrivacy"].ToString());
                this.spWebsite.InnerHtml = getPrivacy(dtt.Rows[0]["WebSitePrivacy"].ToString());
            }
            dtt.Clear(); dtt.Dispose();
        }
        #endregion

        #region 可见度
        public string getPrivacy(string k)
        {
            int s = int.Parse(k);
            if (s == (int)EnumPrivacy.ForWholeSite)
            {
                return "全站用户可见";
            }
            else if (s == (int)EnumPrivacy.ForNetWorkAndFriends)
            {
                return "相同网络用户及好友可见";
            }
            else if (s == (int)EnumPrivacy.ForFriends)
            {
                return "仅好友可见";
            }
            else if (s == (int)EnumPrivacy.ForOwner)
            {
                return "仅自己可见";
            }
            else
            {
                return string.Empty;
            }
        }
        #endregion

        #region 更新会员信息
        public void Submit()
        {
            UserBasicInfo uf = new UserBasicInfo();
            uf.UserID = this.UserID;
            uf.MSN = Request.QueryString["msn"];
            uf.GTalk = Request.QueryString["gtalk"];
            uf.QQ = Request.QueryString["qq"];
            uf.Skype = Request.QueryString["skype"];
            uf.Mobile = Request.QueryString["mobile"];
            uf.Tel = Request.QueryString["landphone"];
            uf.Addr = Request.QueryString["address"];
            uf.WebSite = Request.QueryString["website"];

            if (sp.UpdateUserInfo(uf, this.UserID, 1) == 1)
            {
                Response.Write("修改成功！");
                Response.End();
            }
        }
        #endregion

        #region 设置会员信息可见度
        public void UpdatePrivacy()
        {
            int str_Privacy = int.Parse(Request.QueryString["Privacy"]);
            string strName = Request.QueryString["strName"];
            if (sp.UpdatePrivacy(strName, str_Privacy, this.UserID) >0)
            {
                Response.Write("设置成功！");
                Response.End();
            }
        }
        #endregion

    }
}
