ASP控制每页打印行数的方法
在日常工作中,打印文档经常要使用,但是网页打印起来大部分都是不能控制的,这里分享一个用 ASP控制每页打印行数的方法。也许对你有一点点的启发哦!<%
pagenum=55′指定打印行数
%>
<HTML>
<HEAD>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<TITLE>销售利润明细报表打印</TITLE>
<style type=”text/css”>
td {font-size:9pt; color:#000000}
A{text-decoration:none}
A:hover{color:#FF0000;text-decoration:derline}
.break{page-break-before:always}
</style>
</HEAD>
<script language=”javascript”>
window.print()
</script>
<BODY style=”border:none” topmargin=”0″ leftmargin=”6″ onload=”javascrpt:pagesetup_default();”>
<script language=”VbScript”>
dim hkey_root,hkey_path,hkey_key
hkey_root=”HKEY_CURRENT_USER”
hkey_path=”\Software\Microsoft\Internet Explorer\PageSetup”
function pagesetup_default()
on error resume next
Set RegWsh = CreateObject(“WScript.Shell”)
hkey_key=”\header”
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,”&b页&p/&P”
hkey_key=”\footer”
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,”"
end function
</script>
<%
kdname1=trim(request(“kdname1″))
kdname2=trim(request(“kdname2″))
keyword1=trim(request(“keyword1″))
keyword2=trim(request(“keyword2″))
if keyword1<>”" then
today=keyword1
else
if kdname1=”" then
today=year(date())&”-”&month(date())
else
today=kdname1&”至”&kdname2
end if
end if
%>
<table border=”0″ cellspacing=”0″ cellpadding=”0″ align=”center” width=”740″ height=”30″>
<tr>
<td align=”center”>销售利润汇总报表</td>
</tr>
</table>
<%
strSQL=”select autoid,sellautoid,productxili,productname,productsize,productnum,productdan,productjia,chaoshi,tiaoma,youhui,fukuan,moncount1,gongshang,lirun1,username,indate,fudate from sell where officename=’”&trim(request.cookies(“Myoffice”))&”‘ and monthjie=’0′ and (year(indate)=year(getdate()) and month(indate)=month(getdate())) and zhuofei is null order by autoid desc”
set rs1=server.createobject(“adodb.recordset”)
rs1.open strSQL,conn,1,1
%>
<table border=”1″ cellspacing=”0″ cellpadding=”0″ align=”center” style=”border-collapse: collapse” bordercolor=”#000000″ width=”740″>
<tr>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”70″ >销售单号</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”168″ >商品名称(规格)</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”121″ >客户</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”30″ >数量</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”24″ >单位</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”50″ >销售价</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”23″ >折%</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”52″ >进货价</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”55″ >小计</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”45″ >利润</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”25″ >付款</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”61″ >销售日期</td>
</tr>
</table>
<%
moncount2=0
moncount5=0
Do while not rs1.eof
%>
<table border=”1″ cellpadding=”0″ cellspacing=”0″ width=”740″ align=”center” style=”border-collapse:collapse; font-size:10pt;color:#000000″ bordercolor=”#000000″>
<%
for i=1 to pagenum
if not rs1.eof then
if trim(rs1(“fukuan”))=”欠款” then
moncount6=Csng(rs1(“lirun1″))
moncount5=moncount5+moncount6
else
moncount3=Csng(rs1(“lirun1″))
moncount2=moncount2+moncount3
end if
%>
<tr>
<td height=”18″ width=”70″> <%=rs1(“sellautoid”)%></td>
<td height=”18″ width=”168″><%=Decode(rs1(“productname”))%> <%=rs1(“productsize”)%></td>
<td height=”18″ width=”121″><%=left(rs1(“gongshang”),9)%></td>
<td height=”18″ width=”30″ align=”center”><%=rs1(“productnum”)%></td>
<td height=”18″ width=”24″ align=”center”><%=rs1(“productdan”)%></td>
<td height=”18″ width=”50″ align=”right”><%=formatNumber(rs1(“chaoshi”),varnum,-1)%></td>
<td height=”18″ width=”23″ align=”center”><%=rs1(“youhui”)%></td>
<td height=”18″ width=”52″ align=”right”><%=formatNumber(rs1(“productjia”),varnum,-1)%></td>
<td height=”18″ width=”55″ align=”right”><%=formatNumber(rs1(“moncount1″),varnum,-1)%></td>
<td height=”18″ width=”45″ align=”right”><%=formatNumber(rs1(“lirun1″),varnum,-1)%></td>
<td align=”center” height=”18″ width=”25″><%if trim(rs1(“fukuan”))=”欠款” then%><font color=blue><%=rs1(“fukuan”)%></font><%else%><%=rs1(“fukuan”)%><%end if%></td>
<td height=”18″ width=”61″><%=rs1(“indate”)%></td>
</tr>
<%
rs1.movenext
end if
next
%>
</table>
<%
if not rs1.eof and i=pagenum+1 then ‘添加分页标记
%>
<div class=”break”> </div>
<table border=”0″ cellpadding=”0″ cellspacing=”0″ width=”740″ height=”12″ align=”center”><tr><td height=”12″></td></tr></table>
<table border=”1″ cellspacing=”0″ cellpadding=”0″ align=”center” width=”740″ style=”border-collapse: collapse” bordercolor=”#000000″>
<tr>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”70″ >销售单号</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”168″ >商品名称(规格)</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”121″ >客户</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”30″ >数量</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”24″ >单位</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”50″ >销售价</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”23″ >折%</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”52″ >进货价</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”55″ >小计</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”45″ >利润</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”25″ >付款</td>
<td align=”center” height=”20″ bgcolor=”#BDCBEE” width=”61″ >销售日期</td>
</tr>
<%
end if
loop
rs1.close
set rs1=nothing
%>
</table>
<table border=”1″ cellpadding=”0″ cellspacing=”0″ width=”740″ height=”20″ align=”center” style=”border-collapse: collapse” bordercolor=”#000000″>
<tr>
<td><font color=”#FF0000″><b>现金利润:</b></font><b><%=formatNumber(moncount2,varnum,-1)%></b> <%if moncount5<>”" then%><b><font color=”#FF0000″>欠款利润</font>:<%=formatNumber(moncount5,varnum,-1)%></b><%end if%> <%if moncount5<>”" then%><b><font color=”#FF0000″>毛利合计:</font><%=formatNumber(moncount5+moncount2,varnum,-1)%></b><%end if%></td>
</tr>
</table>
<%
end if
conn.close
set conn=nothing
%>
</BODY>
</HTML>
3个步骤来实现asp模块化分页
通过3个步骤来实现模块化分页,1、查询语句块,2、显示记录块,3、输出分页效果
1、查询语句块
<%
取得当前文件名
temp = Split(request.ServerVariables(“URL”), “/”)
fy = temp(UBound(temp))
set rs=server.createobject(“adodb.recordset”)
if not isempty(request(“page”)) then
pagecount=cint(request(“page”))
else
pagecount=1
end if
sql=”select 查询语句”
rs.open sql,conn,1,1
rs.pagesize=10 分页记录数
if pagecount>rs.pagecount or pagecount<=0 then
pagecount=1
end if
if rs.eof and rs.bof then%><div align=”center” class=”001″><br>
对不起,没有符合搜索条件的记录!<br>
</div>
2、显示记录块
<%
else
rs.AbsolutePage=pagecount
do while not rs.eof %>显示的记录
<% i=i+2
rs.movenext
if i>=rs.PageSize then exit do
loop
%>
3、输出分页效果
<table width=”778″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
<tr align=”center”>
<% if rs.pagecount=1 then %>
<td height=”35″ colspan=”4″ class=001><font color=”#000000″>共有[<font color="#ff0000"><%=rs.recordcount%></font>]条信息 当前显示第 <font color=”red”>1~<%=rs.recordcount%></font>条</font></td>
</tr>
<tr>
<%else%>
<td width=”19%” height=”35″ align=”center” valign=”middle” class=001><font color=”#000000″>
<% page_start=(pagecount-1)*rs.pagesize
if pagecount=1 then page_start=1
page_end=rs.pagesize*pagecount
if pagecount*rs.pagesize=>rs.recordcount then page_end=rs.recordcount end if%>
共有[<font color="#ff0000"><%=rs.recordcount%></font>]信息</font></td>
<td width=”58%” height=”30″ align=”center” class=”fy”><font color=”#000000″>
<%
if pagecount>5 and pagecount< rs.PageCount-5 and rs.pagecount>10 then
qizu=pagecount-4
min=pagecount+5
response.write “<a href=”&source&”?page=1&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&title=”&title&”&cityid=”&cityid&”><font color=’0000BE’>首页</font></a> ”
response.write “<a href=”&source&”?page=”+cstr(pagecount-1)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&title=”&title&”&cityid=”&cityid&”><font color=’0000BE’>上一页</font></a> ”
for ipage=qizu to min
if ipage<>pagecount then
response.write “<a href=”&source&”?page=”+cstr(ipage)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&cityid=”&cityid&”><font color=’0000BE’>”+cstr(ipage)+”</font></a> ”
else
response.write “<font color=’#FF0000′>”&ipage&”</font> “
end if
next
response.write “<a href=”&source&”?page=”+cstr(pagecount+1)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&title=”&title&”&cityid=”&cityid&”><font color=’0000BE’>下一页</font></a> ”
response.write “<a href=”&source&”?page=”+cstr(rs.PageCount)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&title=”&title&”&cityid=”&cityid&”><font color=’0000BE’>尾页</font></a>”
end if
if rs.PageCount<11 then
for ipage=1 to rs.PageCount
if ipage<>pagecount then
response.write “<a href=”&source&”?page=”+cstr(ipage)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&cityid=”&cityid&”><font color=’0000BE’>”+cstr(ipage)+”</font></a> ”
else
response.write “<font color=’#FF0000′>”&ipage&”</font> “
end if
next
end if
if pagecount < 6 and rs.PageCount>10 then
for ipage=1 to 10
if ipage<>pagecount then
response.write “<a href=”&source&”?page=”+cstr(ipage)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&cityid=”&cityid&”><font color=’0000BE’>”+cstr(ipage)+”</font></a> ”
else
response.write “<font color=’#FF0000′>”&ipage&”</font> “
end if
next
response.write “<a href=”&source&”?page=”+cstr(rs.PageCount)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&title=”&title&”&cityid=”&cityid&”><font color=’0000BE’>尾页</font></a>”
end if
if pagecount>rs.PageCount-6 and rs.PageCount>10 then
response.write “<a href=”&source&”?page=1&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&title=”&title&”&cityid=”&cityid&”><font color=’0000BE’>首页</font></a> ”
for ipage=rs.PageCount-9 to rs.PageCount
if ipage<>pagecount then
response.write “<a href=”&source&”?page=”+cstr(ipage)+”&sortid=”&sortid&”&typeid=”&typeid&”&qylb=”&qylb&”&cityid=”&cityid&”><font color=’0000BE’>”+cstr(ipage)+”</font></a> ”
else
response.write “<font color=’#FF0000′>”&ipage&”</font> “
end if
next
end if
%>
</font></td><form name=go2to form method=Post action=<%=fy%>>
<td width=”13%” align=”center” valign=”middle” class=”fy”>
<input type=’hidden’ name=’sortid’ value=”<%=sortid%>”><input type=’hidden’ name=’typeid’ value=”<%=typeid%>”><input type=’hidden’ name=’qylb’ value=”<%=qylb%>”><input type=’hidden’ name=’title’ value=”<%title%>”><input type=’hidden’ name=’cityid’ value=”<%=cityid%>”><font color=’000064′> 转到第<input type=’text’ name=’page’ size=2 maxLength=3>
页</font>
</td>
<td width=”10%” align=”center” valign=”middle” class=”fy”><input name=”image” type=’image’ onClick=check() value=’确 定’ src=’http://edu.chinaz.com/Get/Program/images/button_h.jpg’></td>
</form>
<tr>
<td height=”20″ colspan=”6″ valign=”bottom”><font color=”#000000″> </font></td>
</tr>
<% end if %>
<% end if %>
</table>

