📄 public_function.asp
字号:
<%
'*************************************************************
'公共声明区
'*************************************************************
'为记录集的翻页声明的常量、变量
Const PAGESIZE=15 '每页的记录数
Dim m_intPageSum '总页数
Dim m_intCurrentPage '当前页码
Dim m_intRecordCount '记录总数
m_intPageSum = 1
m_intCurrentPage = 1
m_intRecordCount = 0
'*************************************************************
'名称:PublicFunction
'
'中文含义:公共函数
'
'描述:
' 该文件包含所有的公共函数
'*************************************************************
'
'函数定义列表:
'
'函数定义 描述
'---------------------------------------------------------------------------------------
'Function ReGoTo(List,Page) 重新定位记录集
'
'Sub Show_Page 显示并确定分页栏状态
'
'Function AutoGetNo(MapName) 自动获取唯一序列号
'
'Function SelectValue(m_DictName) 原始状态显示词典的下拉菜单
'
'Function ReSelectValue(m_ValueName,m_DictName) 根据所选项,显示词典的下拉菜单
'
'Function GetDictValue(m_ValueName,m_DictName) 仅返回词典中的对应值
'
'Function AutoGetName(m_ClassId) 动态显示学生姓名的下拉菜单
'
'---------------------------------------------------------------------------------------
'*************************************************************
'公共函数区
'*************************************************************
'*************************************************************
'功能:重新定位记录集
'参数:
' List;Recordset;需重新定位的记录集
' Page;Integer;页码
'返回值:Recordset;重新定位后的记录集
'*************************************************************
Function ReGoTo(List,Page)
'm_intCurrentPage = 1
List.PageSize = PAGESIZE
m_intPageSum = List.PageCount
m_intRecordCount=List.RecordCount
If not List.EOF Then
'确定当前页码
If Page <> "" Then
If isnumeric(Page) Then
If cint(Page)>=1 and cint(Page)<=m_intPageSum Then
m_intCurrentPage=cint(Page)
End If
End If
End If
List.AbsolutePage = m_intCurrentPage '重新定位记录集
End If
Set ReGoTo=List
End Function
' ***********************************************************************
' 作者:suysh
' 功能:显示分页状态栏
' 条件:需要事先定义并赋值以下四个参数
' int PAGESIZE 每页显示记录数
' int m_intCurrentPage 当前页号
' int m_intPageSum 总页数
' int m_intRecordCount 总记录数
' ***********************************************************************
Sub Show_Page
Response.Write "<script language='javascript'>"+chr(10)
Response.Write "<!--"+chr(10)
Response.Write "function CheckPageNO(){"+chr(10)
Response.Write "if ( isNaN( document.PageForm.txtPageNO.value)){"+chr(10)
Response.Write " alert('页码不是数字,请输入数字!');"+chr(10)
Response.Write "document.PageForm.txtPageNo.focus();"+chr(10)
Response.Write "return false;}" +chr(10)
Response.Write "else if (parseInt(document.PageForm.txtPageNO.value)<1 || parseInt(document.PageForm.txtPageNO.value)>" & m_intPageSum & "){"+chr(10)
Response.Write "alert('页码无效,请输入有效页码!');"+chr(10)
Response.Write "document.PageForm.txtPageNo.focus();"+chr(10)
Response.Write "return false;}" +chr(10)
Response.Write "else {document.PageForm.txtPageNO.value=parseInt( document.PageForm.txtPageNO.value,10);"+chr(10)
Response.Write "document.PageForm.submit();}}"+chr(10)
Response.Write "-->"+chr(10)
Response.Write "</script>"
dim scriptname
scriptname=Request.ServerVariables("script_name")
Response.Write "<table align=center width=100% height=19 cellspacing=3>"
Response.Write "<FORM action='"+ scriptname +"' method=post name=PageForm><TBODY><TR>"
Response.Write "<TD noWrap vAlign=center><img src='Images/multipage_icon.gif' border='0'> <font color='#000099'>分页</font> "
if m_intPageSum=1 or m_intPageSum=0 Then
Response.Write "首页 前页 后页 尾页 "
elseif m_intCurrentPage=1 Then
Response.Write "首页 前页 "
Response.Write "<A href='" & scriptname & "?txtPageNO=" & (m_intCurrentPage+1) & "'>后页</A> "
Response.Write "<A href='" & scriptname & "?txtPageNO=" & m_intPageSum & "'>尾页</A> "
elseif cint(m_intCurrentPage)=cint(m_intPageSum) Then
Response.Write "<A href='" & scriptname & "?txtPageNO=1'>首页</A> "
Response.Write "<A href='" & scriptname & "?txtPageNO=" & (m_intCurrentPage-1) & "'>前页</A> "
Response.Write "后页 尾页 "
else
Response.Write "<A href='" & scriptname & "?txtPageNO=1'>首页</A> "
Response.Write "<A href='" & scriptname & "?txtPageNO=" & (m_intCurrentPage-1) & "'>前页</A> "
Response.Write "<A href='" & scriptname & "?txtPageNO=" & (m_intCurrentPage+1) & "'>后页</A> "
Response.Write "<A href='" & scriptname & "?txtPageNO=" & m_intPageSum & "'>尾页</A> "
end if
Response.write "<font color='#000099'>页次:" & m_intCurrentPage & "/" & m_intPageSum & " 页</font> "
Response.write "<font color=#ff3300>" & PAGESIZE & "</font><font color='#000099'> 条/页 共 <font color=#ff3300>" & m_intRecordCount & "</font> 条纪录</FONT></SPAN></TD>"
Response.Write "<TD noWrap vAlign=center><DIV align=right>"
Response.write "<P><font color='#000099'>转到:</font>"
Response.write "<INPUT class=Input maxLength=10 name=txtPageNO size=4 value=" & m_intCurrentPage & ">"
Response.Write "<INPUT class=button id=button1 type=button value='确定' onclick='javascript:return CheckPageNO();'> "
Response.write "</P></DIV></TD></TR></TBODY></FORM></TABLE>"
' Response.Write m_intCurrentPage & "<br>"
' Response.Write m_intPageSum & "<br>"
End Sub
'***********************************************************************
'功能:自动获取唯一序列号
'返回值:Int
'参数:
' MapName 需要获得唯一序列号的数据表名
'***********************************************************************
Function AutoGetNo(MapName)
Dim m_No,Sql
Dim m_FirTempNo,m_SecTempNo 'm_FirTempNo 第一个临时数据
'm_SecTempNo 第二个临时数据
Set m_No=Server.CreateObject("adodb.recordset")
Sql="SELECT * FROM "&MapName
m_No.Open Sql,conn,3,3
If m_No.EOF Then
AutoGetNo=1 '若初始没有记录,则序列号定义为1
Else
if m_No.Fields(0).Value<>1 Then
AutoGetNo=1 '若序列号为1的不存在,则新的序列号定义为1
else
do while not m_No.EOF
m_FirTempNo=m_No.Fields(0).Value
m_No.MoveNext
if not m_No.EOF then
m_SecTempNo=m_No.Fields(0).Value
if m_SecTempNo - m_FirTempNo>1 then
AutoGetNo=m_FirTempNo+1
exit do
end if
else
AutoGetNo=m_FirTempNo+1
end if
loop
end If
End If
End function
'*********************************************************************
'功能:原始状态显示词典的下拉菜单
'返回值:HTML文本
'参数:m_DictName 所选择的词典名称
'*********************************************************************
Function SelectValue(m_DictName)
dim SelectOption
SelectOption=""
Set Rs=conn.Execute ("SELECT * FROM "& m_DictName)
Do While Not Rs.EOF
IF Rs.Fields(0).Value<>"" THEN
SelectOption=SelectOption & "<OPTION value=" & Rs.Fields(0).value &">" & Rs.Fields(1).value & "</OPTION>" & Chr(10)
END IF
RS.MoveNext
Loop
RS.Close
SelectValue=SelectOption
END Function
'*********************************************************************
'功能:根据所选项,显示词典的下拉菜单
'返回值:HTML文本
'参数:m_ValueName 已选中的项目名
' m_DictName 所选择的词典名称
'*********************************************************************
Function ReSelectValue(m_ValueName,m_DictName)
dim SelectOption
SelectOption=""
Set Rs=conn.Execute ("SELECT * FROM "& m_DictName)
Do While Not Rs.EOF
IF Rs.Fields(0).Value<>"" THEN
if cstr(m_ValueName)<>cstr(Rs.Fields(0).value) then
SelectOption=SelectOption & "<OPTION value=" & Rs.Fields(0).value &">" & Rs.Fields(1).value & "</OPTION>" & Chr(10)
else
SelectOption=SelectOption & "<OPTION value=" & Rs.Fields(0).value &" selected>" & Rs.Fields(1).value & "</OPTION>" & Chr(10)
end if
END IF
RS.MoveNext
Loop
RS.Close
ReSelectValue=SelectOption
END Function
'*********************************************************************
'功能:仅返回词典中的对应值
'返回值:String
'参数:m_ValueName 已选中的项目名称
' m_DicName 所选择的词典名称
'*********************************************************************
Function GetDictValue(m_ValueName,m_DictName)
Set Rs=conn.Execute ("SELECT * FROM "& m_DictName)
Do While Not Rs.EOF
IF Rs.Fields(0).Value<>"" THEN
if m_ValueName=Rs.Fields(0).value then
GetDictValue=Trim(Rs.Fields(1))
end if
END IF
RS.MoveNext
Loop
RS.Close
END Function
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -