<%@ Page Language="C#" ContentType="text/html" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Register TagPrefix="My" TagName="MyHead" Src="head.ascx" %>
<%@ Register TagPrefix="My" TagName="MyFoot" Src="foot.ascx" %>
<%@ Register TagPrefix="My" TagName="MyMessage" Src="message.ascx" %>

 <!-- #INCLUDE file="../inc/Function.aspx" -->
 
<script runat="server">
     String strSQL;
	 String UserName;
     String strConn = ConfigurationSettings.AppSettings["ConnectionString"];
	 string AdvUserName; 
     const int Record_Per_Page=20; //每页的记录数
         int nPagecount; //总页数
         int nRecCount; //定义总记录数
         int nPage; //定义当前页
		 DataSet ds=new DataSet();
         SqlDataAdapter da = new SqlDataAdapter();
		  private double runningTotal2 = 0;
		  private double runningTotal3 = 0;
		  private double runningTotal4 = 0;
 protected void Page_Load(Object Src, EventArgs E)
{
    //------判断用户是否登录---
     if(Session["Login_UserName"]==null || Session["IsLogin"]==null || Session["Userclass"]==null || Session["Login_UserName"]=="" || Session["IsLogin"].ToString().ToLower()!="true" )
   {   
      Response.Write("<script language=javascript>alert ('登录超时');document.location='../ ';<");
	  Response.Write("/script>");
	  Response.End();
    }
   AdvUserName=Session["Login_UserName"].ToString();
  //-------------------------

  
  CreateDataSetObject();
  if (!IsPostBack)
  {
	 nPage=0;
	 CmdDataBind();
	 Page_nPage.Text=(nPage+1).ToString();
	 Page_nRecCount.Text=nPagecount.ToString();
	 IsFirstLastPage();	  
   }
}


protected void CreateDataSetObject()
 { 
     strSQL="Select * From FinanceAdv where UserName='"+AdvUserName+"'";
 	  da = new SqlDataAdapter(strSQL,strConn);
	  //da.SelectCommand.CommandType=CommandType.Text; 
	 da.Fill(ds,"FinanceAdv");
	 //DataGrid1.DataSource=ds;
	 //DataGrid1.DataBind();
	 //Response.Write(strSQL);
	 
	 nRecCount=ds.Tables[0].Rows.Count;
	 if(nRecCount%Record_Per_Page==0)
	 {
	  nPagecount=nRecCount/Record_Per_Page;
	  }else
	   {
	   nPagecount=nRecCount/Record_Per_Page+1;
	   }
  }


protected void MyDataGrid_Delete(Object Src, DataGridCommandEventArgs E)

{
  int ProductID =(int)DataGrid1.DataKeys[(int)E.Item.ItemIndex]; 
   
 }
  


//分页
 private void Page_Click(Object Src, EventArgs E)
  {
   string commangArg=((LinkButton)Src).CommandArgument;
   if(!IsNum(ispages.Text))
    {
	 nPage=0;
	 }
	 else
	 {
     nPage=Convert.ToInt32(ispages.Text);
	 }
   switch(commangArg)
    {
	 case "First": //如果点首页
	  {
	  nPage=0;
	  break;
	  }
	  case "Prev": //上一页
	  {
	   nPage=(int)Math.Max(0,nPage-1);
	   break;
	   }
	  case "Next":  //下一页
	  {
	   nPage=(int)Math.Min(nPagecount-1,nPage+1);
	   break;
	   }
       case "Last": //尾页
	    {
		 nPage=nPagecount-1;
		 break;
		 }
		default:{break;};  
	 }
	 
	// Response.Write(nPagecount+" "+nPage);
	 IsFirstLastPage();
	 Page_nPage.Text=(nPage+1).ToString();
	 Page_nRecCount.Text=nPagecount.ToString();
	 CmdDataBind();
   }
   
 // 分页按妞是否可见
 private void IsFirstLastPage()
  {
   if (nPagecount>1)
    {
	 if(nPagecount!=1)
	  {
	    if(nPage==0){PagePrev.Enabled=false;PageFirst.Enabled=false;}
		else{PagePrev.Enabled=true;PageFirst.Enabled=true;}
	    if(nPage==nPagecount-1){PageNext.Enabled=false; PageLast.Enabled=false;}
		else{PageNext.Enabled=true; PageLast.Enabled=true;}
		
	   }
	   else
	   {
	    PagePrev.Enabled=false; PageNext.Enabled=false;
	   }
	 }
   else
   {
    PageFirst.Enabled=false; PagePrev.Enabled=false; PageNext.Enabled=false; PageLast.Enabled=false;
    }
   }
  
 protected void CmdDataBind()
  {
    ds.Clear();
    da.Fill(ds,nPage*Record_Per_Page,Record_Per_Page,"FinanceAdv");
    DataGrid1.DataSource=ds;
	DataGrid1.DataBind(); 
	ispages.Text=nPage.ToString();
	//Console.WriteLine(ds.Tables["FinanceAdv"].Rows[1]);
	
	//DataGrid1.Tables[0].Rows[1].Page_Del.Enabled=false;	
   }
   
  
 //绑定后执行的操作 
public void MyDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
  //Response.Write(e.Item.ItemType+" " + ListItemType.Item +"<br>");
  
　 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
　 {
　　 runningTotal2 += Double.Parse((e.Item.Cells[2].Text));
　　 runningTotal3 += Double.Parse((e.Item.Cells[3].Text));
　　 runningTotal4 += Double.Parse((e.Item.Cells[4].Text));
　　 e.Item.Cells[2].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[2].Text));
　　 e.Item.Cells[3].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[3].Text));
　　 e.Item.Cells[4].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[4].Text));
　 }
　 else if(e.Item.ItemType == ListItemType.Footer )
　 {
　　 e.Item.Cells[0].Text="统计";
　　 e.Item.Cells[2].Text = string.Format("{0:c}", runningTotal2);
　　 e.Item.Cells[3].Text = string.Format("{0:c}", runningTotal3);
　　 e.Item.Cells[4].Text = string.Format("{0:c}", runningTotal4);
　 }
}


</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>5507广告联盟 - 广告商管理后台 - 财务日志</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<my:MyHead runat="server"/>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0" class="table_3">
  <tr>
    <td width="20" height="15"><img src="../web/images/body_1.gif" /></td>
    <td width="926" background="../web/images/body_2.gif"></td>
    <td width="20"><img src="../web/images/body_3.gif" width="20" height="15" /></td>
  </tr>
</table>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="15" background="../web/images/body_7.gif" bgcolor="#FFFFFF"><p>&nbsp;</p>
        <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="953" valign="top" bgcolor="#FFFFFF"><table width="950" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="140" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="30"><table width="98%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%"><div align="center"><img src="../images/adv_list.gif" width="25" height="25" /></div></td>
                <td width="30%"><strong>财务日志</strong></td>
                <td width="64%">&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30">
              
			  <asp:DataGrid 
			   AutoGenerateColumns="false"
			   AllowSorting="True"
			   PageSize="20"
			   BackColor="#ffffff"
			   BorderColor="#dddddd" 
			   BorderWidth="1" 
			   Height="25" 
			   ID="DataGrid1" 
			   runat="server" 
			   ShowFooter="true" 
			   ShowHeader="true" 
			   HeaderStyle-Height="25"
			   FooterStyle-Height="25"
			   
			   FooterStyle-BackColor="#F3F3F3"
			   HeaderStyle-BackColor="#F3F3F3"
			   HeaderStyle-HorizontalAlign="Center"
			   FooterStyle-HorizontalAlign="Center"
			   DataKeyField="id"
			   Width="970" 
			   gridline="Both"
			   AlternatingItemStyle-BackColor="#F7F7F7"
			   OnItemDataBound="MyDataGrid_ItemDataBound"
				>
                <columns>
			  <asp:boundcolumn datafield="id" ItemStyle-Width="40" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="NO"/>
			  <asp:boundcolumn datafield="AffairsType" ItemStyle-Width="40" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="类别"/>
			  
			  <asp:boundcolumn datafield="TotalEnter" ItemStyle-Width="100" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="入账总金额"/>
			  
			  <asp:boundcolumn datafield="TotaGoto" ItemStyle-Width="100" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="出账总额" />
			  
			  <asp:boundcolumn datafield="Commission" ItemStyle-Width="100" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="佣金/手续费"/>
			  
			  <asp:boundcolumn datafield="Surplusamount" ItemStyle-Width="100" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="账户余额" DataFormatString="{0:c}" />
			  <asp:boundcolumn datafield="Remarks" ItemStyle-Width="300" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="备注说明" />
			  
          <asp:TemplateColumn ItemStyle-Width="60" ItemStyle-HorizontalAlign="Center" HeaderText="时间">
                <ItemTemplate>
					<%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem,"AddTime")).ToString("d") %>				                </ItemTemplate>			   		 
			</asp:TemplateColumn>
			  
                </columns>
				
              </asp:DataGrid>
			  <form runat="server">
			  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><div align="center">
                      <asp:LinkButton ID="PageFirst" OnClick="Page_Click" Text="首页" runat="server" CommandArgument="First"/>              
                    |
                    <asp:LinkButton ID="PagePrev" OnClick="Page_Click" Text="上一页" runat="server" CommandArgument="Prev"/>
                    |
                    <asp:LinkButton ID="PageNext" OnClick="Page_Click" Text="下一页" runat="server" CommandArgument="Next"/>
                    |
                    <asp:LinkButton ID="PageLast" OnClick="Page_Click" Text="尾页" runat="server" CommandArgument="Last"/>
                    <asp:Label ID="CountPage" runat="server" />
                    转到:
                    <asp:TextBox AutoPostBack="true" Columns="2" ID="ispages" runat="server" />
                    页 第
                    <asp:Label ID="Page_nPage" runat="server" ForeColor="Red"></asp:Label>
                    页/共
                    <asp:Label ID="Page_nRecCount" ForeColor="Red" runat="server"></asp:Label>
                    页</div></td>
                </tr>
              </table>
			  </form>
			  
              </td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
          </tr>
        </table></td>
        </tr>
    </table></td>
    <td width="15" background="../web/images/body_8.gif" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
</table>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20"><img src="../web/images/body_4.gif" width="20" /></td>
    <td width="926" background="../web/images/body_5.gif">&nbsp;</td>
    <td width="20"><div align="right"><img src="../web/images/body_6.gif" width="20" height="20" /></div></td>
  </tr>
</table>

<my:MyFoot runat="server"/>

</body>
</html>
