<%@ 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;  //定义页面是否加载

    public static int InNum = 0;
    public static int OutNum = 0;
    string param = string.Empty;

    int recordcount, pagecount;
    int CurrPage = new BasicField().GetCurrPage;
    int PageSize = 10;
    protected void Page_Load(object sender, EventArgs e)
    {
        param = " WHERE userId=" + __user.UserID;
        if (!IsPostBack)
        {
                InNum = Utils.StrToInt(DataFactoryUser.GetOnlyValue("select count(1) from KS_LogPoint" + param + " and InOrOutFlag=1"));
                OutNum = Utils.StrToInt(DataFactoryUser.GetOnlyValue("select count(1) from KS_LogPoint" + param + " and InOrOutFlag=2"));
        }
    }

    public string GetPoint(double point,int inoroutflag,int type)
        {
            if (type == inoroutflag)
            {
                return string.Format("{0:n2}", point);
            }
            else
            {
                return "-";
            }
        }

        public string GetOpType(int type)
        {
            if (type == 1)
                return "<span class=green-color>收入</span>";
            else
                return "<span class=red-color>支出</span>";

        }
        public string GetNowPoint(double point)
        {
            return string.Format("{0:n2}", point);
        }
        

</script>
<%
    if (!isLoadPage) return;
%>
  <div class="r_tybox nomar t_tybox">
      <div class="r_title tytitle pd0"><h4 class="float-none disting_show"><%=MyCache.GetCacheConfig(49) %>明细</h4>
         

      </div>
      <div class="top-sort clearfix">
        
        <div class="top-sort-option fl">
          <a href='<%=BasicField.GetUserUrl("basic/consumer") %>'>所有记录（<%=InNum+OutNum %>）</a>
          <a href='<%=BasicField.GetUserUrl("basic/consumer","IncomeOrPayOut-1") %>'>收入记录（<%=InNum %>）</a>
          <a href='<%=BasicField.GetUserUrl("basic/consumer","IncomeOrPayOut-2") %>'>支出记录（<%=OutNum %>）</a>
        </div>
      </div>

        <table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
           <tr align="center" class="title">
              <td width="60" align="center">用户</td>
              <td align="center">消费时间</td>
              <td align="center" nowrap> 收入(<%=MyCache.GetCacheConfig(50) %>) </td>
              <td align="center" nowrap> 支出(<%=MyCache.GetCacheConfig(50) %>) </td>
              <td align="center">摘要</td>
              <td align="center" nowrap>余额(<%=MyCache.GetCacheConfig(50) %>)</td>
              <td align="center">备注</td>
            </tr>
       <%
           if (Utils.StrToInt(KSCMS.S("IncomeOrPayOut")) >0)
           {
               param += " and Inoroutflag=" + Utils.StrToInt(KSCMS.S("IncomeOrPayOut"));
           }

           using (DataTable dt = DataFactoryUser.GetPage("*", "[KS_LogPoint]"+param, "id", "order by id desc", CurrPage, PageSize, out recordcount, out pagecount))
           {
               if (dt.Rows.Count > 0)
               {
                   foreach(DataRow dr in dt.Rows)
                   {
                       KSCMS.W(@"<tr class=""tdbg"">
                          <td class=""splittd"" align=""center"">" + dr["UserName"].ToString() + @"</td>
                          <td class=""splittd"" style=""text-align:center"">" +
                        Utils.FormatHumanizedTime(Convert.ToDateTime(dr["AddDate"].ToString())) + @"
                          </td>
                          <td class=""splittd"" align=""center"">" + GetPoint(Convert.ToDouble(dr["point"].ToString()), Convert.ToInt16(dr["Inoroutflag"].ToString()), 1) + @"</td>
                          <td class=""splittd"" align=""center"">"+
                         GetPoint(Convert.ToDouble(dr["point"].ToString()), Convert.ToInt16(dr["Inoroutflag"].ToString()), 2) + @"
                          </td>
                          <td class=""splittd"" align=""center"">" +
                        GetOpType(Convert.ToInt16(dr["Inoroutflag"].ToString())) + @"
                          </td>
                          <td class=""splittd"" align=""center""><strong class=black-color>" +
                         GetNowPoint(Convert.ToDouble(dr["nowpoint"].ToString())) + @"</strong>
                          </td>
                          <td class=""splittd"" style=""width:180px;word-break:break-all;color:#999;"">" +
                         dr["remark"].ToString() + @"
                          </td>
                      </tr>");

                   }
               }else
               {
                   KSCMS.W(@" <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>
        <div class="fy_box">
           <%
                #region 分页
                string PageStr = "[KS:PageStr1]";
                BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
                KSCMS.W(PageStr);
                #endregion
             %>
         </div>
         <div class="clear"></div>

</div>

<script>
  var url = location.href.replace(location.origin,'');
  $('.top-sort-option').find('a').each(function(){
    var href = $(this).attr('href');
    if(href==url){
      $(this).addClass('on');
    }
  });

</script>