<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Config" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.XML" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server" type="text/C#">

    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息
    bool isLoadPage = true;  //定义页面是否加载

    protected void Page_Load(object sender, EventArgs e)
    {
        if (KSCMS.S("action") == "delbind")
        {
            isLoadPage = false;
            doDelBind();
            return;
        }
    }
   private void doDelBind()
    {
        string id = KSCMS.S("id");
        if (string.IsNullOrEmpty(id))
        {
           Msg.Alert("出错啦!");
            return;
        }
        id = id.ToLower();
        switch (id)
        {
            case "qq":
                DataFactoryUser.ExecuteNonQuery("UPDATE KS_User Set QQOpenID='',QQToken='' Where UserID=" + __user.UserID);
                break;
            case "weixin":
                DataFactoryUser.ExecuteNonQuery("UPDATE KS_User Set weixinopenid='',unionid='',Isweixinunbind=1,isapi=1 Where UserID=" + __user.UserID);
                break;
            case "sina":
                DataFactoryUser.ExecuteNonQuery("UPDATE KS_User Set SinaID='',SinaToken='' Where UserID=" + __user.UserID);
                break;
            case "alipay":
                DataFactoryUser.ExecuteNonQuery("UPDATE KS_User Set AlipayID='' Where UserID=" + __user.UserID);
                break;

        }
        UserManage.CleanUserCache(__user.UserID);
        Msg.Alert("恭喜，解除绑定成功!", BasicField.GetUserUrl("Basic/ApiBind"));
        return;

    }

     public string GetBindStatus(string id)
    {
        StringBuilder sb = new StringBuilder();

        switch (id.ToLower())
        {
            case "qq":
                if (!string.IsNullOrEmpty(__user.QQOpenID))
                {
                    sb.AppendFormat(@"<span title='qq登录已绑定'><img src='/sysimg/default/icon_qq.png' align='absmiddle' alt='qq登录已绑定'/>QQ登录已绑定</span>,<a href='{0}' style='color:#ff6600;text-decoration:underline'>解除绑定</a>&nbsp;&nbsp;",BasicField.GetUserUrl("basic/apibind","action-delbind&id=qq"));
                }
                else
                {
                    sb.AppendFormat(@"<span title='qq登录未绑定'><img src='/sysimg/default/icon_qq_no.png' align='absmiddle' alt='qq登录未绑定'/>QQ登录未绑定</span>,<a  href='{0}' target=""_blank"" style='color:green;font-weight:bold;text-decoration:underline'>立即绑定</a>&nbsp;&nbsp;", Kesion.BLL.BaseFun.GetRewriteUrl("qqlogin"));
                }
                break;
            case "weixin":
                if (!string.IsNullOrEmpty(__user.WeiXinOpenID))
                {
                    sb.AppendFormat(@"<span title='微信登录已绑定'><img src='/sysimg/default/icon_weixin.png' align='absmiddle' alt='微信登录已绑定'/>微信登录已绑定</span>,<a href='{0}' style='color:#ff6600;text-decoration:underline'>解除绑定</a>&nbsp;&nbsp;",BasicField.GetUserUrl("basic/apibind","action-delbind,id-weixin"));
                }
                else
                {
                    sb.AppendFormat(@"<span title='微信登录未绑定'><img src='/sysimg/default/icon_weixin_no.png' align='absmiddle' alt='微信登录未绑定'/>微信登录未绑定</span>,<a  href='{0}' target=""_blank"" style='color:green;font-weight:bold;text-decoration:underline'>立即绑定</a>&nbsp;&nbsp;", Kesion.BLL.BaseFun.GetRewriteUrl("weixinlogin"));
                }
                break;
            case "sina":
                if (!string.IsNullOrEmpty(__user.SinaID))
                {
                    sb.AppendFormat(@"<span title='新浪微博登录已绑定'><img src='/sysimg/default/icon_sina.png' align='absmiddle' alt='新浪微博登录已绑定'/>新浪微博登录已绑定</span>,<a href='{0}' style='color:#ff6600;text-decoration:underline'>解除绑定</a>&nbsp;&nbsp;",BasicField.GetUserUrl("basic/apibind","action-delbind&id=sina"));
                }
                else
                {
                    sb.AppendFormat(@"<span title='新浪微博登录未绑定'><img src='/sysimg/default/icon_sina_no.png' align='absmiddle' alt='新浪微博登录未绑定'/>新浪微博登录未绑定</span>,<a href='{0}' target=""_blank"" style='color:green;font-weight:bold;text-decoration:underline'>立即绑定</a>&nbsp;&nbsp;",Kesion.BLL.BaseFun.GetRewriteUrl("sinalogin"));
                }
                break;
            case "alipay":
                if (!string.IsNullOrEmpty(__user.AlipayID))
                {
                    sb.AppendFormat(@"<span title='支付宝快捷登录已绑定'><img src='/sysimg/default/icon_alipay.png' align='absmiddle' alt='支付宝快捷登录已绑定'/>支付宝快捷登录已绑定</span>,<a href='{0}' style='color:#ff6600;text-decoration:underline'>解除绑定</a>&nbsp;&nbsp;",BasicField.GetUserUrl("basic/apibind","action-delbind&id=alipay"));
                }
                else
                {
                    sb.AppendFormat(@"<span title='支付宝快捷登录未绑定'><img src='/sysimg/default/icon_alipay_no.png' align='absmiddle' alt='支付宝快捷登录未绑定'/>支付宝快捷登录未绑定</span>,<a href='{0}' target=""_blank"" style='color:green;font-weight:bold;text-decoration:underline'>立即绑定</a>&nbsp;&nbsp;",Kesion.BLL.BaseFun.GetRewriteUrl("alipaylogin"));
                }
                break;
        }
        return sb.ToString();
    }
</script>
<%
    if (!isLoadPage) return;
%>
 
	<div class="r_tybox t_tybox nomar">
        <div class="r_title tytitle pd0"><h4>第三方绑定</h4>
         <div class="tabs">	
    			<ul class="clearfix">
                    <li ><a href="<%=BasicField.GetUserUrl("basic/editinfo") %>">我的资料</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("basic/userface") %>">上传头像</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("basic/editpass") %>">修改密码</a></li>
                    <% if (__user.GroupID==3) {%>
                    <li ><a href="<%=BasicField.GetUserUrl("school/userepintroduce") %>">机构介绍</a></li>
                    <li ><a href="<%=BasicField.GetUserUrl("school/userepbank") %>">银行账户</a></li>
                    <% } 
                    %>
                    <li><a href="<%=BasicField.GetUserUrl("basic/editquestion") %>">修改安全问题</a></li>
                    <li class='puton'><a href="<%=BasicField.GetUserUrl("basic/mobilebind") %>">第三方绑定</a></li>
                    <li ><a href="<%=BasicField.GetUserUrl("Shop/MyAddress") %>">收货人地址</a></li>
                  
    			</ul>
        </div>
       
    </div>
     <div class="top-sort clearfix">
           <div class="top-sort-tab ">	
                <ul>
                    <li><a href="<%=BasicField.GetUserUrl("basic/mobilebind") %>">手机绑定</a></li>
                    <li class='puton'><a href="<%=BasicField.GetUserUrl("basic/apibind") %>">第三方绑定</a></li>
                </ul>
            </div>
    </div>
		
    <div class="r_padbox nopadtop">        
    
     <table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
      <tr class="title">
        	<td width="50" align="center">序号</td>
        	<td width="150" align="center"> 第三方网站</td>
            <td style="text-align:left"> 绑定状态 </td>
        </tr>
         <%
             XmlDocument xmldoc = new XmlDocument();
             xmldoc.Load(Server.MapPath(KSCMS.GetInstallDir() + "config/AccountAPI.config"));
             string FieldsXML = XmlObject.XMLToString(ref xmldoc);



             DataSet ds = XmlObject.StringToDataSet(FieldsXML);
             DataTable dt = ds.Tables[0];
             DataView dv = dt.DefaultView;
             dv.RowFilter = "enable='true'"; //过滤没有启用的接口
             dt = dv.ToTable();
             if (dt.Rows.Count<= 0)
             {
                 KSCMS.W(@"<tr class=""tdbg"">
                         <td class=""splittd"" style=""text-align:center"" colspan=""10"">站没有开通任何账号通接口！</td>
                   </tr>");
             }
             else
             {
                 var i = 1;
                 foreach(DataRow dr in dt.Rows)
                 {

                     KSCMS.W(@"<tr class=""tdbg"">");
                     KSCMS.W(@" <td height=""70"" class=""splittd"" align=""center"">" + i + "、</td>");
                     KSCMS.W(@"   <td class=""splittd"" align=""center""><img src=""/sysimg/default/" + dr["id"].ToString() + @".png"" /></td>");
                     KSCMS.W(@"   <td class=""zhttd"">");
                     KSCMS.W(GetBindStatus(dr["id"].ToString()));
                     KSCMS.W(@"             </td>
                              </tr>");
                     i++;
                 }
             }

          %>
   
    </table>
    
    </div>
     </div>
