<%@ 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 userName='" + __user.UserName + "'";
        if (!IsPostBack)
        {
            InNum = Utils.StrToInt(DataFactoryUser.GetOnlyValue("select count(1) from KS_LogMoney" + param + " and InComeOrPayOut=1"));
            OutNum = Utils.StrToInt(DataFactoryUser.GetOnlyValue("select count(1) from KS_LogMoney" + param + " and InComeOrPayOut=2"));
        }
    }

    public string GetMoney(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 GetNowMoney(double point)
    {
        return string.Format("{0:n2}", point);
    }

</script>
<%
    if (!isLoadPage) return;
%>
  <div class="r_tybox t_tybox nomar clearfix">
    <div class="r_title tytitle  pd0">
	<h4 class="float-none disting_show">账户明细</h4>
      
    </div>
    <div class="top-sort clearfix">
       
        <div class="top-sort-option fl">
          <a href='<%=BasicField.GetUserUrl("basic/logmoney") %>'>所有记录（<%=InNum+OutNum %>）</a> 
          <a href='<%=BasicField.GetUserUrl("basic/logmoney","IncomeOrPayOut-1") %>'>收入记录（<%=InNum %>）</a> 
          <a href='<%=BasicField.GetUserUrl("basic/logmoney","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 align="center">用户</td>
        	<td align="center">消费时间</td>
            <td align="center" width="110"> 收入(<%=MyCache.GetCurrencyUnit %>) </td>
            <td align="center">支出(<%=MyCache.GetCurrencyUnit %>) </td>
            <td align="center">摘要</td>
	        <td align="center">余额(<%=MyCache.GetCurrencyUnit %>)</td>
	        <td align="center" width="300">备注</td>
        </tr>
   <%
       if (Utils.StrToInt(KSCMS.S("IncomeOrPayOut")) >0)
       {
           param += " and InComeOrPayOut=" + Utils.StrToInt(KSCMS.S("IncomeOrPayOut"));
       }

       using (DataTable dt = DataFactoryUser.GetPage("*", "[KS_LogMoney]"+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["PayTime"].ToString())) + @"
                      </td>
                      <td class=""splittd"" align=""center"">" + GetMoney(Convert.ToDouble(dr["money"].ToString()), Convert.ToInt16(dr["InComeorPayout"].ToString()), 1) + @"</td>
                      <td class=""splittd"" align=""center"">"+
                     GetMoney(Convert.ToDouble(dr["money"].ToString()), Convert.ToInt16(dr["InComeorPayout"].ToString()), 2) + @"
                      </td>
                      <td class=""splittd"" align=""center"" nowrap>" +
                    GetOpType(Convert.ToInt16(dr["InComeorPayout"].ToString())) + @"
                      </td>
                      <td class=""splittd"" align=""center""><strong class=black-color>" +
                     GetNowMoney(Convert.ToDouble(dr["currMoney"].ToString())) + @"</span>
                      </td>
                      <td class=""tag_left"">" +
                     dr["remark"].ToString() + @"
                      </td>
                  </tr>");

               }
           }else
           {
               KSCMS.W(@" <tr class=""tdbg "">
                <td class=""splittd"" style=""border:0px;"" colspan=""10"">
                  <div class=""empty"">没有消费记录！<div>
                  <style>.cz_btn{display:none;}</style>
                </td>
           </tr> ");
           }
       }

        %>
    </table>

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