<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@Page Debug=True %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>
<html>
<head>
	<script language="VB" runat="server">
	dim NowPageCount as integer
	dim Source as SqlConnection 
	dim d as string="SELECT Staff.*, MonthPay.* FROM MonthPay INNER JOIN Staff ON MonthPay.SID = Staff.SID Order by Staff.SID"
	sub Page_load(sender as object,e as EventArgs)
		Source = Ctype(Session("NowEmpSQL"),SqlConnection)
		if IsPostBack=false then
			bindNew(true)
		end if
	end sub
	sub bindNew(tag as Boolean) '结合至DataGrid
		if tag=true then
			Dim DS as DataSet = new DataSet()
			Dim NComm as SqlDataAdapter = new SqlDataAdapter(d, Source)
			NComm.Fill(DS, "staffPay")
			Session("NowDS")=DS '声明为Session
			staffPay.DataSource=DS.Tables("staffPay").DefaultView
			staffPay.DataBind()
		else
			Dim DS as DataSet =Ctype(Session("NowDS"),DataSet)
			Dim dv as DataView =DS.Tables("staffPay").DefaultView
			staffPay.DataSource=dv
			staffPay.DataBind()
		end if
		NowPageCount=staffPay.PageCount
		CurrentPage.Text = "第" & Convert.ToInt32(staffPay.CurrentPageIndex + 1).ToString() & "页，共" & staffPay.PageCount & "页"
	end sub
	sub ChangePage(sender as object,e as DataGridPageChangedEventArgs )
		staffPay.CurrentPageIndex = e.NewPageIndex '设定目前页次
		bindNew(false)
	end sub
	sub PagerChange(sender as object,e as CommandEventArgs)
		if e.CommandArgument = "next" Then '下页
			bindNew(false)
			if staffPay.CurrentPageIndex < NowPageCount - 1 then
				staffPay.CurrentPageIndex = staffPay.CurrentPageIndex + 1
			end if
			bindNew(false)
		elseif e.CommandArgument = "prev" then '前页
			if staffPay.CurrentPageIndex > 0 then
				staffPay.CurrentPageIndex = staffPay.CurrentPageIndex - 1
			end if
			bindNew(false)
		elseif e.CommandArgument = "last" then '末页
			bindNew(false)
			staffPay.CurrentPageIndex = staffPay.PageCount - 1
			bindNew(false)
		elseif e.CommandArgument = "fir" then '首页
			staffPay.CurrentPageIndex = 0
			bindNew(false)
		end if
	end sub
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form runat="server" >
      <asp:LinkButton id="MoveFirst" runat="server"
        Text="首页"
        CommandArgument="fir"
        ForeColor="navy"
        Font-Name="verdana" Font-size="8pt"
        OnCommand="PagerChange"
        />
      &nbsp;
      <asp:LinkButton id="MovePrev" runat="server"
        Text="上页"
        CommandArgument="prev"
        ForeColor="navy"
        Font-Name="verdana" Font-size="8pt"
        OnCommand="PagerChange"
        />
      &nbsp;
      <asp:LinkButton id="MoveNext" runat="server"
        Text="下页"
        CommandArgument="next"
        ForeColor="navy"
        Font-Name="verdana" Font-size="8pt"
        OnCommand="PagerChange"
        />
      &nbsp;
      <asp:LinkButton id="MoveLast" runat="server"
        Text="末页"
        CommandArgument="last"
        ForeColor="navy"
        Font-Name="verdana" Font-size="8pt"
        OnCommand="PagerChange"
        />   <asp:label id="CurrentPage" runat="server" />
      <ASP:DataGrid id="staffPay" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="9pt"
        HeaderStyle-BackColor="LightYellow"
	HeaderStyle-HorizontalAlign="Center"
	AutoGenerateColumns="FALSE"
	SelectedItemStyle-BackColor="#FFFFC0"
        AllowPaging="True"
        pagesize="6"
PagerStyle-HorizontalAlign="Right"
PagerStyle-PageButtonCount="3"
        PagerStyle-Mode="NumericPages"
        OnPageIndexChanged="ChangePage"
>
      <Columns>
	<asp:BoundColumn HeaderText="StaffID" DataField="SID" ItemStyle-Wrap="false"  />
	<asp:BoundColumn HeaderText="Name" DataField="cname" />
	<asp:BoundColumn HeaderText="YearMonth" DataField="YearMonth" />
	<asp:BoundColumn HeaderText="应发工资" DataField="PayTotalDe" DataFormatString="{0:n}"/>
        <asp:BoundColumn HeaderText="扣款合计" DataFormatString="{0:n}" DataField="MinusTotal" ItemStyle-HorizontalAlign="right"/>
        <asp:BoundColumn HeaderText="福利金" DataFormatString="{0:n}" DataField="WellFare" ItemStyle-HorizontalAlign="right"/>
	<asp:TemplateColumn HeaderText="Pay" >
		<ItemTemplate>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "Pay","{0:c}") %> id="Pay"/>
		</ItemTemplate>
	</asp:TemplateColumn>
	</Columns>
</ASP:DataGrid>
</form>