📄 recordlist_bak.inc
字号:
<%
'************************************************************************************************
' 文件名: recordlist.inc
' Copyright(c) 2001-2002 上海阿尔卡特网络支援系统有限公司
' 创建人 : 周秋舫
' 日 期 : 2002-05-08
' 修改历史:
' ****年**月**日 ****** 修改内容:**************************************************
' 功能描述 : 用于分页处理的常用函数
' TableHeaderField(sFileName, sField, sFieldName, sFormParams, sSorting, sSorted) : 可以排序的列头
' PrepareListData(conn, sql, sSortFields, sDelimiter)
' TotalRecords(conn, sql) : 计算sql语句返回的记录数
' Paginate(sFileName, sFormParams, sSortParams, iCurrentPage, iTotalPages) : 分页函数
' WhiteRows(sFirstRowInfo, sOtherRowInfo, iStart, iRecordsPerPage) : 画若干空行
' 版 本 :
'************************************************************************************************
'************************************************************************************************
' 函数名 : TableHeaderField
' 输 入 : sFileName, sDbField, sFieldName, sFormParams, sSorting, sSorted
' sFileName ---- 字符串变量,链接文件名
' sField ---- 字符串变量,数据库字段名
' sFieldName ---- 字符串变量,数据库字段的中文描述
' sFormParams ---- 字符串变量,页面传递的参数
' sSorting ---- 字符串变量,点击后排序的数据库字段
' sSorted ---- 字符串变量,上次排序的数据库字段
' 输 出 : TableHeaderField,函数名作为返回值,类型为字符串
' 功能描述: 表格的Header字段,点击后所有记录按此升序或降序重新排列
' 调用模块:
' 作 者 : 周秋舫
' 日 期 : 2002-05-08
' 版 本 :
'************************************************************************************************
Function TableHeaderField(sFileName, sField, sFieldName, sFormParams, sSorting, sSorted)
Dim sSortImage
if sSorting = sField and sSorted = sField then
sSortImage = "<img border=0 src='../images/sort_asc.gif'>" ' 升序图标
elseif sSorting = sField then
sSortImage = "<img border=0 src='../images/sort_desc.gif'>" ' 降序图标
else
sSortImage = "<img border=0 src='../images/sort_blank.gif'>" ' 空白图标
end if
TableHeaderField = "<a style='color:black;font-weight:600;font-family:verdana,Courier,Arial,Helvetica,sans-serif,宋体;font-size:11px' " & _
"href='" & sFileName & "?" & sFormParams & "Sorting=" & sField & "&Sorted=" & sSorted & "&'>" & sFieldName & "</a>" & "<img border=0 height=0 width=2>" & sSortImage
End Function
'************************************************************************************************
' 函数名 : PrepareListData
' 输 入 : sql_statement : 选取数据库记录的SQL语句
' sSortFields : 需要排序的字段名称
' sDelimiter : 指定排序字段之间的分隔符
' 输 出 : (无)
' 功能描述: 准备分页数据,包括排序变量
' 调用模块:
' 作 者 : 周秋舫
' 日 期 : 2002-06-02
' 版 本 :
'************************************************************************************************
Sub PrepareListData(conn, sql, sSortFields, sDelimiter)
dim sSQL : sSQL = sql
dim arrayFields
dim bFlag, i
dim sSorting
'--------------------------------------
' 获取总的记录数,以便分页
'--------------------------------------
iTotalRecords = TotalRecords(conn, sSQL)
if iTotalRecords = 0 then
' 一条记录都找不到
end if
'--------------------------------------
' 计算总页数,当前页码
'--------------------------------------
if iTotalRecords mod iRecordsPerPage = 0 then
iTotalPages = int(iTotalRecords / iRecordsPerPage)
else
iTotalPages = int(iTotalRecords / iRecordsPerPage) + 1
end if
if iTotalPages = 0 then iTotalPages = 1
iCurrentPage = GetParam("Page")
if IsEmpty(iCurrentPage) then
iCurrentPage = 1
end if
if Not isNumeric(iCurrentPage) then
iCurrentPage = 1
end if
iCurrentPage = CLng(iCurrentPage) ' 转化成整数再与iTotalPages比较,否则就是比较出来的结果是不正确的
if iCurrentPage > iTotalPages then
iCurrentPage = iTotalPages
end if
'--------------------------------------
' 排序列、排序方向、排序参数
'--------------------------------------
arrayFields = Split(sSortFields, sDelimiter) '' 分隔排序字段
bFlag = false
for i = LBound(arrayFields) to UBound(arrayFields)
if sSorting = arrayFields(i) then
bFlag = true '' 标志找到了匹配的排序字段
exit for
end if
next
if IsEmpty(sSorting) then
sSorting = ""
elseif bFlag = false then
sSorting = "" '' 如果没有找到匹配的排序字段,则不排序
else
if sSorting = sSorted then ' 这一列是上次排序的列,则将iSorted的值置空""(降序排列),否则置iSort的值(升序排列)
sDirection = " desc"
sSortParams = "Sorting=" & sSorting & "&Sorted=" & sSorted & "&"
sSorted = ""
else
sDirection = " asc"
sSortParams = "Sorting=" & sSorting & "&Sorted=" & "&"
sSorted = sSorting
end if
end if
if sSorting <> "" then
sOrderby = " order by " & sSorting & sDirection
end if
End Sub
'************************************************************************************************
' 函数名 : TotalRecords
' 输 入 : sql ---- sql语句
' 输 出 : TotalRecords函数名作为返回值,类型为整数
' 功能描述: 根据给定的SQL语句转换为select count(*) from...的形式,并执行该sql语句,取得结果返回
' 调用模块:
' 作 者 : 周秋舫
' 日 期 : 2002-05-09
' 版 本 :
'************************************************************************************************
Function TotalRecords(conn, sql)
on error resume next
Dim sError : sError = ""
Dim rs
Dim iTmpI : iTmpI = 0
Dim iTmpJ : iTmpJ = 0
Dim sCountSQL : sCountSQL = ""
Dim iCount : iCount = 0
'------------------------------------------
' 变换SQL语句为select count(*) from ... 形式
'------------------------------------------
iTmpI = instr(lcase(sql), "select")
iTmpJ = instr(lcase(sql), " from ")
if iTmpI >= 1 and iTmpJ >= 1 then
sCountSQL = replace(sql, left(sql, iTmpJ+5), "select count(*) from ")
iTmpI = instr(lcase(sCountSQL), "order by")
if iTmpI > 1 then sCountSQL = left(sCountSQL, iTmpI - 1)
' 执行查询语句
''response.write "变换前:" & sql & "<br><br>"
''response.write "变换后:" & sCountSQL & "<br><br>"
iCount = CLng(conn.Execute(sCountSQL).fields(0).value)
sError = oCn.ProcessError
end if
''response.write "记录总数:" & iCount & "<br>"
TotalRecords = iCount
on error goto 0
End Function
'************************************************************************************************
' 函数名 : Paginate
' 输 入 : sFileName, sFormParams, sSortParams, iCurrentPage, iTotalPages
' sFileName -- 字符串变量,链接文件名
' sFormParams -- 页面传递的参量
' sSortParams -- 页面传递的排序参量
' iCurrentPage -- 当前页码
' iTotalPages -- 总页数
' 输 出 : Paginate
' Paginate -- 函数名作为返回值,类型为字符串
' 功能描述: 根据当前页码和总页数信息组合生成页码信息即,“首页 前页 当前页/总页数 后页 尾页”
' 调用模块:
' 作 者 : 周秋舫
' 日 期 : 2002-05-08
' 版 本 :
'************************************************************************************************
Function Paginate(sFileName, sFormParams, sSortParams, iCurrentPage, iTotalPages)
Dim iPrevPage, iNextPage
Dim sFirstPage, sPrevPage, sNextPage, sLastPage
if iTotalPages = 0 then iTotalPages = 1
if iCurrentPage = 0 then iCurrentPage = 1
'-----------------------------------------------------------
' 前一页,不可能小于0
'-----------------------------------------------------------
iPrevPage = iCurrentPage - 1
if iPrevPage <= 0 then iPrevPage = 1
'-----------------------------------------------------------
' 后一页,不可能大于总页数
'-----------------------------------------------------------
iNextPage = iCurrentPage + 1
if iNextPage > iTotalPages then iNextPage = iTotalPages
'-----------------------------------------------------------
' 如果当前是第一页,则不需要首页和前页链接
'-----------------------------------------------------------
if iCurrentPage = 1 then
sFirstPage = "首页"
sPrevPage = "前页"
else
sFirstPage = "<a href='" & sFileName & "?" & sFormParams & sSortParams & "Page=1'>首页</a>"
sPrevPage = "<a href='" & sFileName & "?" & sFormParams & sSortParams & "Page=" & iPrevPage & "'>前页</a>"
end if
'-----------------------------------------------------------
' 如果当前是最后一页,则不需要后页和尾页链接
'-----------------------------------------------------------
if iCurrentPage = iTotalPages then
sLastPage = "尾页"
sNextPage = "后页"
else
sLastPage = "<a href='" & sFileName & "?" & sFormParams & sSortParams & "Page=" & iTotalPages & "'>尾页</a>"
sNextPage = "<a href='" & sFileName & "?" & sFormParams & sSortParams & "Page=" & iNextPage & "'>后页</a>"
end if
'' 直接选中一页进行跳转
dim sJumpSelectOptions, j
for j = 1 to iTotalPages
if j = iCurrentPage then
sJumpSelectOptions = sJumpSelectOptions & "<option value=""" & j & """ selected>第" & j & "页</option>" & vbLF
else
sJumpSelectOptions = sJumpSelectOptions & "<option value=""" & j & """>第" & j & "页</option>" & vbLF
end if
next
'-----------------------------------------------------------
' 分页信息组合:首页 前页 当前页/总页数 后页 尾页
'-----------------------------------------------------------
' Paginate = " 每页 " & iRecordsPerPage & " 条记录,共 " & iTotalRecords & " 条记录" & _
' " " & _
' "跳转至<select onchange=""javascript:window.location.href='" & sFileName & "?" & sFormParams & sSortParams & "page=' + this.options[this.selectedIndex].value + '&" & "';"">" & sJumpSelectOptions & "</select>" & _
' " " & _
Paginate = " 每页 " & iRecordsPerPage & " 条记录,共 " & iTotalRecords & " 条记录" & _
sFirstPage & " " & sPrevPage & _
" ( 第<span style=""color:red"">" & iCurrentPage & "</span>页/共" & iTotalPages & _
"页 ) " & sNextPage & " " & sLastPage
End Function
'************************************************************************************************
' 函数名 : WhiteRows
' 输 入 :
' sFirstRowInfo -- 如果一行也没有,显示的内容
' sOtherRowInfo -- 其它行显示的内容
' iCurrentRows -- 当前已经有多少行,整型
' piRowsPerPage -- 每页显示的行数,整型
' 输 出 : WhiteRows -- 函数名作为返回值,类型为字符串
' 功能描述: 从起始行画若干空行,使总行数到达每页行数,这样可以保持每页显示的行数是一致的
' 调用模块:
' 作 者 : 周秋舫
' 日 期 : 2002-05-29
' 版 本 :
'************************************************************************************************
Function WhiteRows(piCols, piStart, piRecordsPerPage)
dim i, j, sTemp, iCols, iStart, iRecordsPerPage
iCols = piCols
iStart = piStart
iRecordsPerPage = piRecordsPerPage
'' 如果起始行已经等于或超过每页总行数,则返回空字串
'' 如果从第一行开始就是空行,则显示(哎呀,一条记录也没有找到!)
'' 否则,就从起始行开始填补空行
if iStart > iRecordsPerPage then
sTemp = ""
else
sTemp = "<tr bgcolor=white>"
for i = 1 to iCols
sTemp = sTemp & "<td> </td>"
next
sTemp = sTemp & "</tr>"
end if
for j = iStart + 1 to iRecordsPerPage step 1
sTemp = sTemp & "<tr bgcolor=white>"
for i = 1 to iCols
sTemp = sTemp & "<td> </td>"
next
sTemp = sTemp & "</tr>"
next
WhiteRows = sTemp
End Function
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -