<%
'================================================
' By Kangk.L
'Date 2006-04-07
'Program Name Kangk PageAc
'Class Name Cls_PageAc
'
'
'---------Property Let--------
'ListHtml 列表循环模板:字符型,HTML代码和替换标签<必需>
' (替换标签说明:用","号分隔的每个字段名FieldStr前后加"$")
'Pages 当前页码:长整型,如果为空,则为0
'PageSize 每页列表数:长整型<必需>
'TableStr SQL语句数据表名:字符型<必需>
'FieldStr SQL语句数据字段:字符型<必需> (用","号分隔)
'FieldLen 数据字段字符长度:字符型<必需> (数字用","号分隔,必须与数据字段数目相等,0值则长度不变化)
'WhereStr SQL语句Where条件:字符型,如果长度<3或为空,则为空
'OrderMode SQL语句排序方法:数字型,0为"Asc",非0为"Desc",如果为空,则为"Asc"
'KeyField SQL语句主键名:字符型,如果为空,则为"Id"
'TextFromHtml 是否过滤HTML代码:数字型 (0或1,默认为0,0:不过滤 1:过滤)
'RedWord 获得需加红关键字,如为空,则不加红
'RedWordControl 获得加红关键字控制,如为空,则不加红色(由","号分隔的0或1,如不为空,则必须与数据字段数目相等,0:加红 1:不加红)
'
'--------Property Get--------
'RecCount 记录总数
'PageNum 分页总数
'
'--------Function--------
'PageAcContent 内容列表主体显示
'PageAcName 分页辨识名称
'================================================
'Response.Cookies("PageAc")("PageNum") = ""
'Response.Cookies("PageAc")("PageAcName") = ""
'Response.Cookies("PageAc")("RecCount") = ""
Class Cls_PageAc
Private strPageAcName
Private lngEndId,TempListHtml,TempListHtmlStr
Private Rs,SqlStr
Private strFieldStr,strFieldLen,strTableStr,strWhereStr,strKeyField,strRedWord,strRedWordControl
Private intOrderMode,lngPages,lngRecCount,lngPageNum,intPageSize,intTextFromHtml
Private i,j,n
Private arrFieldStr,arrFieldLen,arrRsHtml,arrRedWord,arrRedWordControl
'####内容列表主体显示
Public Function PageAcContent()
'response.Write(Request.Cookies("PageAc")("PageNum"))
SqlStr = "Select "&strFieldStr&" From "&strTableStr&" "&strWhereStr&" Order By "&strKeyField&" "&intOrderMode&""
'SqlStr = "Select * from test"
'response.Write(SqlStr)
Set Rs = Server.CreateObject("Adodb.Recordset")
Rs.Open SqlStr,Conn,1,1
If Not (Rs.Eof And Rs.Bof) Then
Rs.AbsolutePosition = (lngPages-1) * intPageSize + 1
For i = 1 To intPageSize
If Rs.Eof Or Rs.Bof Then Exit For
arrFieldStr = Split(strFieldStr,",")
arrFieldLen = Split(strFieldLen,",")
arrRsHtml = Split(strFieldLen,",")
arrRedWordControl = Split(strRedWordControl,",")
TempListHtmlStr = TempListHtml
For j = LBound(arrFieldStr) To UBound(arrFieldStr)
'response.Write(arrFieldLen(j)&"<br>")
If intTextFromHtml = 1 Then
arrRsHtml(j) = GetTextFromHtml(Rs(arrFieldStr(j)))
Else
arrRsHtml(j) = Rs(arrFieldStr(j))
End If
arrFieldLen(j) = Cint(arrFieldLen(j))
If arrFieldLen(j) = 0 Then
arrRsHtml(j) = arrRsHtml(j)
Else
arrRsHtml(j) = KeepLen(arrRsHtml(j),arrFieldLen(j))
End If
If strRedWord <> "" And strRedWordControl <> "" Then
If arrRedWordControl(j) <> 0 Then
arrRedWord = Split(strRedWord," ")
For n = LBound(arrRedWord) To UBound(arrRedWord)
If Instr("<span style=color:#f00></span>",arrRedWord(n)) > 0 Then Exit For
arrRsHtml(j) = Replace(arrRsHtml(j),arrRedWord(n),"<span style=color:#f00>"&arrRedWord(n)&"</span>",1)
Next
End If
End If
TempListHtmlStr = Replace(TempListHtmlStr,"$"&arrFieldStr(j)&"$",arrRsHtml(j))
'lngEndId = Rs("Id")
Next
'Response.Write(i)
'Response.Write(rs("id"))
Response.Write(TempListHtmlStr)
Rs.MoveNext
Next
Else
Response.Write("没有资源记录!")
End If
Rs.Close
Set Rs = Nothing
End Function
'####记录总数
Public Property Get RecCount()
If Request.Cookies("PageAc")("PageAcName") <> PageAcName() Or Request.Cookies("PageAc")("RecCount") = "" Then
lngRecCount = Conn.Execute("Select Count("&strKeyField&") From "&strTableStr&" "&strWhereStr&"",0,1)(0)
Response.Cookies("PageAc")("PageAcName") = PageAcName()
Response.Cookies("PageAc")("RecCount") = CLng(lngRecCount)
RecCount = CLng(lngRecCount)
Else
lngRecCount = CLng(Request.Cookies("PageAc")("RecCount"))
RecCount = lngRecCount
End If
End ProPerty
'####分页总数
Public Property Get PageNum()
lngPageNum = lngRecCount / intPageSize
If lngPageNum > CLng(lngPageNum) Then
lngPageNum = CLng(lngPageNum) + 1
Else
lngPageNum = CLng(lngPageNum)
End If
Response.Cookies("PageAc")("PageNum") = CLng(lngPageNum)
PageNum = lngPageNum
End ProPerty
'####取得循环模板
Public ProPerty Let ListHtml(Str)
TempListHtml = Str
End ProPerty
'####取得当前Pages数
Public ProPerty Let Pages(Num)
lngPages = CLng(Num)
If lngPages < 1 Then lngPages = 1
End ProPerty
'####取得PageSize数
Public ProPerty Let PageSize(Num)
intPageSize = CInt(Num)
End ProPerty
'####取得Table字符
Public ProPerty Let TableStr(Str)
strTableStr = Str
End ProPerty
'####取得field字符
Public ProPerty Let FieldStr(Str)
strFieldStr = Str
'If Trim(strFieldStr) = "" Then strFieldStr = "*"
End ProPerty
'####取得field字符长度
Public ProPerty Let FieldLen(Str)
strFieldLen = Str
End ProPerty
'####取得Where条件字符
Public ProPerty Let WhereStr(Str)
If Len(Trim(Str)) >= 3 Then
strWhereStr = "Where "&Trim(Str)
Else
strWhereStr = ""
End If
End ProPerty
'####取得Order方式
Public ProPerty Let OrderMode(Num)
If CInt(Num) = 0 Then
intOrderMode = "Asc"
Else
intOrderMode = "Desc"
End If
End ProPerty
'####取得主键字段
Public ProPerty Let KeyField(Str)
strKeyField = Trim(Str)
If strKeyField = "" Then strKeyField = "Id"
End ProPerty
'####是否过滤HTML代码
Public ProPerty Let TextFromHtml(Num)
intTextFromHtml = Cint(Num)
If intTextFromHtml <> 1 Then intTextFromHtml = 0
End ProPerty
'####取得加红关键字
Public ProPerty Let RedWord(Str)
strRedWord = Str
End ProPerty
'####取得加红关键字控制
Public ProPerty Let RedWordControl(Str)
strRedWordControl = Str
End ProPerty
'####分页辨识名称
Private Function PageAcName()
strPageAcName = Server.UrlEnCode(strTableStr) & Server.UrlEnCode(strWhereStr) & Server.UrlEnCode(intOrderMode)
PageAcName = strPageAcName & "Kangk"
End Function
'####截取字符指定长度
Private Function KeepLen(Str,Lens)
If len(str)>Lens Then
KeepLen=Left(Str,Lens) & "..."
Else
KeepLen=Str
End if
End Function
Public Function GetTextFromHtml(strHtml)
Dim strPatrn
strpatrn="<.*?>"
Dim regEx
Set regEx = New RegExp
regEx.Pattern = strPatrn
regEx.IgnoreCase = True
regEx.Global = True
GetTextFromHtml = regEx.Replace(strHtml,"")
End Function
End Class
'#################################################
'面页跳转链接函数
'传入:类ID,当前页码,记录总数,分页总数,显示页码数
'#################################################
Function PLink(cId,Pages,PCount,PNum,ShowNum)
Dim tmpHtml
Dim i,PageStart,PageEnd
Dim ShowP,ShowS
ShowP = ShowNum '显示页码数
ShowS = CInt((ShowP-1)/2)
tmpHtml = ""
tmpHtml = "共 <b>"&PCount&"</b> 条 / <b>"&PNum&"</b> 页 "
tmpHtml = tmpHtml & " 当前是 <b>"&Pages&"</b> 页 "
tmpHtml = tmpHtml & " <a href=""?cId="&cId&"&Pages=1"">最前页</a>"
tmpHtml = tmpHtml & " <a href=""?cId="&cId&"&Pages="&Pages-1&""">上一页</a>"
If Pages < ShowS Then
PageStart = 1
PageEnd = ShowP
ElseIf Pages > PNum - ShowP Then
PageStart = PNum - ShowP
PageEnd = PNum
Else
PageStart = Pages - ShowS
PageEnd = Pages + ShowS
End If
For i = PageStart to PageEnd
If i > PNum Then Exit For
If i = Pages Then
tmpHtml = tmpHtml & " <a href=""?cId="&cId&"&Pages="&i&"""><font color=""#FF0000""><b>"&i&"</b></font></a> "
Else
tmpHtml = tmpHtml & " <a href=""?cId="&cId&"&Pages="&i&"""><b>"&i&"</b></a>"
End If
Next
tmpHtml = tmpHtml & " <a href=""?cId="&cId&"&Pages="&Pages+1&""">下一页</a>"
tmpHtml = tmpHtml & " <a href=""?cId="&cId&"&Pages="&PNum&""">最后页</a>"
tmpHtml = tmpHtml & " 转到:"
tmpHtml = tmpHtml & "<input name=""Pages"" type=""text"" id=""Pages"" style=""width:18px; height:14px; border:1px solid #cccccc;"" /><input name=""Submit"" type=""submit"" id=""Submit"" value=""GO"" style=""width:18px; height:18px; border:1px solid #cccccc;"" onclick=""window.location='?cId="&cId&"&Pages='+Pages.value"" />"
PLink = tmpHtml
End Function
%>