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

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

    int recordcount, pagecount;
    int CurrPage = new BasicField().GetCurrPage;
    int PageSize = 10;

    private string param = " Where 1=1";
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    private string GetType(int NumType)
    {

        string TypeName = string.Empty;
        switch (NumType)
        {
            case 1:
                TypeName = "元";
                break;
            case 2:
                TypeName = MyCache.GetCacheConfig(49);
                break;
            case 3:
                if (Utils.StrToInt(MyCache.GetCacheConfig(92)) == 1)
                {
                    if (string.IsNullOrEmpty(MyCache.GetCacheConfig(91)))
                    {
                        TypeName =MyCache.GetCacheConfig(91);
                    }
                    else
                    {
                        TypeName = "积分";
                    }
                }
                else
                {
                    TypeName = "积分";
                }
                break;
        }
        return TypeName;
    }


</script>
<%
    if (!isLoadPage) return;
%> 

<div class="t_tybox nomar">
    <div class="r_title tytitle pd0 ">
        <h4 class="ty-none">我的签到</h4>
        <div class="tabs">	
            <ul class="clearfix">
               <li<%=KSCMS.S("flag")==""?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("Other/SignInList") %>">我的签到记录</a></li>
               <li<%=KSCMS.S("flag")=="1"?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("Other/SignInList","flag-1") %>">签到排名</a></li>
            </ul>
        </div> 
    </div>      
     <%
         StringBuilder sb = new StringBuilder();
         if (string.IsNullOrEmpty(KSCMS.S("flag")))
         {
             param += " and username='" + (new TemporaryVar()).UserName + "'";
             using (DataTable dt = DataFactory.GetPage("*", "[KS_SignIn]" + param, "id", "order by AddDate desc", CurrPage, PageSize, out recordcount, out pagecount))
             {
                 if (dt.Rows.Count > 0)
                 {
                     foreach (DataRow dr in dt.Rows)
                     {
                         sb.Append(@" <tr class=""tdbg"">
          <td class=""splittd"" align=""center"" nowrap>" + (Utils.IsValidMobile(dr["UserName"].ToString()) ? Regex.Replace(dr["UserName"].ToString(), "(\\d{3})\\d{4}(\\d{4})", "$1****$2") : dr["UserName"].ToString()) + @"</td>
          <td class=""splittd"" align=""center"" nowrap>" + dr["num"].ToString() + "&nbsp;" + GetType(Utils.StrToInt(dr["numtype"].ToString())) + @"</td>
          <td class=""splittd"" align=""center"" nowrap>" + Convert.ToDateTime(dr["AddDate"].ToString()).ToShortDateString() + @"</td>
          <td class=""splittd"" align=""center"" nowrap>" + dr["UserIP"].ToString() + @"</td>
        
      </tr>  ");
                     }

                 }
                 else
                 {
                     sb.Append(@"<tr class=""tr-nobor"">
                                    <td class=""splittd"" style=""text-align:center"" colspan=""10"">
                                      <div class=""empty"">没有签到记录！</div>
                                    </td>
                               </tr><style>.cz_btn{display:none;}</style>");
                 }
             }
     %>
    
    <table id="tablist2" width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="border">
        <tr align="center" class="title">
        	<td>用户名</td>
        	<td>领取数量</td>
        	<td>签到时间</td>
            <td>IP地址</td>        	
        </tr>
       <%=sb.ToString() %>
      </table>
<%}
    else
    {
        param += " group by username";
        if (DataFactory.Exists("KS_SignIn", "1=1"))
        {
            PageSize = 100;
            using (DataTable dt = DataFactory.GetPage("username, count(id) countnum ", "[KS_SignIn]" + param, "id", "order by countnum desc",CurrPage, PageSize, out recordcount, out pagecount))
            {

                if (dt.Rows.Count > 0)
                {
                    int i = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        sb.Append(@" <tr class=""tdbg"">
          <td class=""splittd"" align=""center"" nowrap>" + (i+1) + @"</td>
          <td class=""splittd"" align=""center"" nowrap>" + (Utils.IsValidMobile(dr["UserName"].ToString()) ? Regex.Replace(dr["UserName"].ToString(), "(\\d{3})\\d{4}(\\d{4})", "$1****$2") : dr["UserName"].ToString()) + @"</td>
          <td class=""splittd"" align=""center"" nowrap>" + dr["countnum"].ToString() + @"</td>
          <td class=""splittd"" align=""center"" nowrap>" + ( Kesion.BLL.DataFactory.Exists("KS_SignIn","username='"+dr["username"].ToString()+"' and year(adddate)="+DateTime.Now.Year+" and month(adddate)="+DateTime.Now.Month+" and day(adddate)="+DateTime.Now.Day)?"已签到":"未签到") + @"</td>
        
      </tr>  ");
                        i++;
                    }

                }
                else
                {
                    sb.Append(@" <tr class=""tr-nobor"">
                                    <td class=""splittd"" style=""text-align:center"" colspan=""10"">
                                      <div class=""empty"">没有签到记录！</div>
                                    </td>
                               </tr><style>.cz_btn{ display:none;}</style>");
                }
            }
        }
        %>


    <table id="tablist2" width="100%" border="0" align="center" cellpadding="0" cellspacing="0"  class="border">
        <tr align="center" class="title">
        	<td>排名</td>
        	<td>用户名</td>
        	<td>签到次数</td>
            <td>今天签到状态</td>        	
        </tr>
   
       <%=sb.ToString() %>
    </table>
	<%
        }
        if (pagecount > 1)
        {
            #region 分页
            string PageStr = "[KS:PageStr1]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(@"<div class=""fy_box"">"+PageStr+"</div>");
            #endregion
        }
     %>
    <div class="clear"></div>
</div>