<%
'================================================
' 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
%>