<%
Option Explicit
'===================================================
public function MyNowNumber()
MyNowNumber=year(now)& month(NOw) & day(NOw) & hour(NOw) & Minute(Now) & Second(Now)
end function
public function sDataGrid(SqlStr,ConnStr,PageSize,PageNum,beginField,EndField,IDField,HttpStr,PageInfo)'以表格形式显示数据
on error resume next
dim conn,rs
'if isnumeric(pageSize)then rs.pageSize=pageSize
set conn=server.CreateObject ("adodb.connection")
set rs=server.CreateObject ("adodb.recordset")
Conn.open Connstr
rs.Open sqlstr,conn,1,3
if err.number<>0 then
Response.Write writeinfo("<BR>DataGrid函数在运行出现了错误!<BR>错描述:" & err.Description & "<BR>")
DataGrid="Err"
exit function
end if
if rs.RecordCount<1 then
Response.Write "<font size='-1' color='#FF0000'> 没有数据...</font>"
DataGrid=0
exit function
end if
'------------对参数据进行处理----------------------
'----------确定如何显示字段-----------------
if not Isnumeric(beginField) or beginField<0 then
beginField=0'确保开始显示的位置在合理范围内
else
if beginField>rs.Fields.Count-1 then beginField=rs.Fields.Count-1'保证到少显示一个字段
if beginField<0 then beginField=0
end if
if not Isnumeric(EndField) then EndField=rs.Fields.Count-1
if EndField>rs.Fields.Count-1 then EndField=rs.Fields.Count-1
if EndField<=beginField or EndField<0 then EndField=beginField'保证到少显示一个字段
'----------复选框、修改链接的处理在成生表格时同步完成--------------
'---------分页处理------------------
if Ucase(Trim(PageSize))="MAX" then
PageSize=rs.RecordCount
rs.pageSize=rs.RecordCount
PageNum=1
else
if not Isnumeric(PageSize) or PageSize<1 then PageSize=10
if PageSize>rs.recordcount then pageSize=rs.recordcount
rs.pageSize=pageSize
'---------页号处理----------------
if Trim(Ucase(pageNum))="MAX" then PageNum=rs.PageCount
if not Isnumeric(PageNum) then PageNum=1
if PageNum<1 then PageNum=1
if cint(PageNum-rs.PageCount)>0 then PageNum=rs.PageCount
end if
Rs.AbsolutePage=PageNum
if err.number<>0 then
dbinfo="数据库连接错误"
DataGrid=0
exit function
else
if rs.RecordCount<1 then
Response.Write "没有找到记录"
DataGrid=0
exit function
else
if Ucase(trim(PageInfo))<>"NULL" then '确定是显示页号信息
Response.Write "<font size='-1' color='#666666'>第<font color='#FF0000'>" & PageNum & "</font>页,共<font color='#FF0000'>" & rs.PageCount & "</font>页"
end if
'写入表头
Response.Write "<table width='100%' border='0' cellspacing='1' cellpadding='0' bgcolor='#999999'>"
Response.Write "<tr bgcolor='#CCCCCC'>"
Response.Write "<td width='1%' align='center'><b><font color='#666666' size='-1'>序</font></b></td>"
dim i
for i=beginField to EndField
Response.Write "<td align='center'><b><font color='#666666' size='-1'>" & rs.Fields(i).Name & "</font></b></td>"
next
if Isnumeric(IDfield) then '复选框及修改链接处理
if IDField>=0 and (IDField - rs.fields.count<=0) then
Response.Write "<td width='1%' align='center'><b><font color='#666666' size='-1'>删</font></b></td>"
if trim(httpstr)<>"0" then Response.Write "<td width='1%'><b><font color='#666666' size='-1'>修</font></b></td>"
end if
end if
Response.Write "</tr>"
'写入字段信息
dim RecordNum,FieldNum
for RecordNum=0 to PageSize-1 '?????????????????
Response.Write "<tr bgcolor='#FFFFFF'>"
Response.Write "<td><font size='-1'>" & RecordNum +1+(PageNum-1)*PageSize & "</font></td>"
for FieldNum=beginField to EndField '写入字段值
'response.write "<input type='text' name='textfield' value='" & Trim(rs.Fields(FieldNum).Value) & "'>"
'if Trim(rs.Fields(FieldNum).Value)="" or Isnull(rs.Fields(FieldNum).Value) then
' Response.Write "<td> </td>"
' else
Response.Write "<td><font size='-1'><input type='text' name='textfield' style=' border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px' value='" & Trim(rs.Fields(FieldNum).Value) & "'></font></td>"
'end if
next
if Isnumeric(IDfield) then '复选框处理
if IDField>=0 or (IDField - rs.fields.count<=0) then
Response.Write "<td><input type='checkbox' name='IDfield' value='"& rs.Fields(IDfield).Value &"'></td>"
if trim(httpstr)<>"0" then Response.Write "<td><font size='-1'><a href='" & httpstr & "?IDField="& rs.Fields(IDfield).Value &"'>改</a></font></td>"
end if
end if
Response.Write "</tr>"
rs.MoveNext
if rs.eof then exit for '最后不到一整页时,也跳出
next
Response.Write "</table>"
end if
end if
rs.Close
conn.Close
set rs=nothing
set conn=nothing
Err.Clear
DataGrid=PageNum
end function
public function DataGrid(SqlStr,ConnStr,PageSize,PageNum,beginField,EndField,IDField,HttpStr,PageInfo)'以表格形式显示数据