您的位置:首页 > 编程语言 > ASP

ASP高级类kktPage——将ASP查询分页封装起来(1)

2009-04-20 08:29 375 查看

0、前言:

这是04年编写的ASP类,实现了对查询分页、数据列表的封装,它与ASP模板类kktTemplate数据库类clsDB是同一时期的作品,因此它需要数据库类以完成数据获取,支持模板类以完成内容的生成和输出。kktPage类集成了模板类数据库类集成度很高,这主要源于作者在Win32程序编写方面的习惯,在当年很多人还诟病ASP的执行效率而裹步不前时,这种封装方式显得相当另类,也惹来不少非议,不知道在.Net流行的今天大家对它是什么看法。

ASP模板类kktTemplate请参阅http://blog.csdn.net/nhconch/archive/2004/07/10/38683.aspx

ASP数据库类请参阅http://blog.csdn.net/nhconch/archive/2004/07/16/42869.aspx

ASP变量名-值变换请参阅:http://blog.csdn.net/nhconch/archive/2004/07/07/36104.aspx



一、功能:

查询分页类有kktPage和kktPageEx,kktPageEx仅比kktPage多带了一个模板kktTemplate,其他并无差异,以下一并说明。

kktPage/kktPageEx目标就是完成的数据的分页列表显示,通过模板类数据库类的集成,以最少的代码实现需要的功能,例如通过执行以下程序段:

Dim Page
Set Page = New kktPageEx
Page.SQL.SQLCommand = "select * from Orders"
Page.PageInfo.MaxList = 8
if Request.Form("page") <> "" then Page.PageInfo.Page = CInt(Request.Form("page"))
page.PageInfo.HtmlFormat = "第{FirstItem}-{LastItem}条信息,共{ItemsCount}条信息,第{Page}/{PageCount}页,当前页面显示{ListCount}条信息,设定最大显示条数为:{MaxList}.<br>"
Page.Template.Setup "pagetest.tpl", "TplHandle", "OrderList", "EmptyInfo"
Page.Template.Columns.Add "OrderID", "OrderID", "ID", 0, ""
Page.Template.Columns.Add "运输商", "ShipName", "Title", 20, ""
Page.Template.Columns.Add "下单日期", "OrderDate", "DateTime", 0, "DateValue"
Page.Process
Page.Display
Set Page = Nothing


并结合模板:



<form name="Form" method="post" action="PageExTest.asp">

<table width="400" border="1" bordercolor="#000000">

<tr><td><div align="center">kktPage类测试</div></td></tr>

<tr><td>我的订单</td> </tr>

<!-- BEGIN OrderList -->

<tr><td><a href="viewdetail.asp?id={ID}">{Title} [{DateTime}]</a></td></tr>

<!-- END OrderList -->

<!-- BEGIN EmptyInfo -->

<tr><td>Sorry,没有查询到数据。</td></tr>

<!-- END EmptyInfo -->

</table>

{PageInfo} , {Buttons} {PageList}

</form>

便能得到以下结果:



kktPage类测试
我的订单
Toms Spezialitäten [1996-7-5]
Victuailles en stock [1996-7-8]
Ernst Handel [1996-7-17]
Ottilies Käseladen [1996-7-19]
Blondel père et fils [1996-7-25]
Frankenversand [1996-7-29]
White Clover Markets [1996-7-31]
Wartian Herkku [1996-8-1]
第1-8条信息,共830条信息,第1/104页,当前页面显示8条信息,设定最大显示条数为:8.
, [首页] [上页] [下页] [未页] 1 2 3 4 5 …


二、实现代码:

kktPage/kktPageEx类被分成三个文件:

kktPageInc——分页查询对象支持模块,kktPage/kktPageEx所依赖的控件库;

kktPage——查询分页基础类,不带模板功能

kktPageEx——带模板的查询分页类





1、kktpageinc.asp

<%%>
<mce:script runat=server language=jscript><!--
/*--------------------------------------------------------------*/
| CLASS NAME:  kktPageInc 分页查询对象支持模块                      |
| DESIGN BY :  彭国辉                                             |
| DATE:        2004-03-12                                        |
| SITE:        http://blog.csdn.net/nhconch                      |
| EMAIL:       kacarton@sohu.com                                 |
/*______________________________________________________________*/
/* < script runat=server language=vbscript >
function ToHtml(FmtStr, Values)
    dim RegEx, Matches, Result, i
    Set RegEx = new RegExp
    RegEx.Pattern = "/{(/w+)/}"
    RegEx.IgnoreCase = true
    RegEx.Global = true
    Set Matches = RegEx.Execute(FmtStr)
    Result = FmtStr
    i = 0
    For Each Match In Matches
        Result = Replace(Result, Match.Value, Values(i))    'VBScript的数组与JScript数组不一致
        i = i + 1
    Next
    set Matches = nothing
    set RegEx = nothing
    ToHtml = Result
End Function
< /script >  */
//将FmtStr中特定内容以实际值替代,主要用于各对象中输出HTML内容
//  FmtStr:待替代内容用{var_name}形式标记
//  Obj:调用的对象,替代内容将从此对象中取得
function ToHtml(FmtStr, Obj)
{
    var re = //{/w+/}/ig;
    var matches = FmtStr.match(re);
    var result = FmtStr;
    for (var i=0; i<matches.length; i++)
    {
        re.compile(matches[i], "gi");
        var value = eval("Obj."+matches[i].substring(1, matches[i].length-1));
        if (value==undefined) value=""; //{var_name}所代表的值不存在时,用空值替代
        result = result.replace(re, value);
    }
    return result;
}
//取子项功能,各对象共用函数
function GetSubItem(Index) { return this[Index]; }
//////////////////// Begin ImageList ////////////////////
/*************************************************************
图像列表
    属性:
        Count:总数
    方法:
        Add(img_str):添加图像,img_str: "path/filename.ext"
        Remove(Index):删除指定图像
        Clear():清除所有图像
        Items(Index):取子项内容,兼容VBScript
    事件:(无)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function ImageList_Component()
{
    this.Add    = AddImage;
    this.Remove = RemoveImage
    this.Clear  = ClearImage;
    this.Count  = 0;
    this.Items  = GetSubItem;  //for VBScript 取子项内容, Ex: imglist.Items(0)
}
function AddImage(Image) { this[this.Count++] = Image; }
function RemoveImage(Index)
{
    if (Index<0 || Index>=this.Count) return;
    var i = Index;
    while (i < this.Count) this[i] = this[++i];
    delete this[this.Count--];
}
function ClearImage() { while (this.Count>0) delete this[this.Count--];}
//以下为兼容VBScript而设
//建立ImageList_Component, Ex: set imglist = CreateImageList()
function CreateImageList() { return new ImageList_Component(); }
//////////////////// End ImageList ////////////////////
//////////////////// Begin Button ////////////////////
/*************************************************************
按钮对象
    属性:
        ImageIndex:图像索引号
        Enabled:   按钮有效性
    方法:(无)
    事件:(无)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function Button_Component(ImageIndex, Enabled)
{
    this.ImageIndex = ImageIndex;
    this.Enabled    = Enabled;
    //this.toString = Button_ToString;    //**重载toString函数**
}
//function Button_ToString() { return this.ImageIndex; }
//以下为兼容VBScript而设
function CreateButton(ImageIndex, Enabled) { return new Button_Component(ImageIndex, Enabled); }
//////////////////// End Button ////////////////////
//////////////////// Begin ButtonList ////////////////////
/*************************************************************
按钮组对象
    属性:
        Count:总数
    方法:
        Add(imgindex, enabled):添加按钮,Ex: btnlist(1, true);
        Items(Index):取子项内容,兼容VBScript
    事件:(无)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function ButtonList_Component()
{
    this.Add    = AddButton;
    this.Remove = RemoveButton;
    this.Clear  = ClearButton;
    this.Count  = 0;
    this.Items  = GetSubItem;
}
function AddButton(ImageIndex, Enabled) { this[this.Count++] = new Button_Component(ImageIndex, Enabled); }
function RemoveButton(Index)
{
    if (Index<0 || Index>=this.Count) return;
    var i = Index;
    while (i < this.Count) this[i] = this[++i];
    delete this[this.Count--];
}
function ClearButton() { while (this.Count>0) delete this[this.Count--];}
//以下为兼容VBScript而设
//建立ButtonList_Component, Ex: set btnlist = CreateButtonList()
function CreateButtonList() { return new ButtonList_Component(); }
//////////////////// End ButtonList ////////////////////
/*=======================以下与页面相关对象======================*/
//////////////////// Begin NavigateButtons ////////////////////
/*************************************************************
导航按钮组
    属性:
        FirstButton、PreviousButton、NextButton、LastButton:各按钮对象
        HtmlFormat:GetHtml返回的Html格式字符串
        EnabledImages、DisabledImages:按钮有效及无效时相应的图像列表
    方法:
        ToHtml:输出HTML格式内容
    事件:(无)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function NavigateButtons()
{
    this.FirstButton    = new Button_Component(0, false);
    this.PreviousButton = new Button_Component(1, false);
    this.NextButton     = new Button_Component(2, false);
    this.LastButton     = new Button_Component(3, false);
    this.EnabledImages  = new ImageList_Component();
    this.DisabledImages = new ImageList_Component();
    this.EnabledImages.Add("<input type=image src="/image/first.gif" mce_src="image/first.gif" onclick='page.selectedIndex=0;'>");
    this.EnabledImages.Add("<input type=image src="/image/pre.gif" mce_src="image/pre.gif" onclick='page.selectedIndex-=1;'>");
    this.EnabledImages.Add("<input type=image src="/image/next.gif" mce_src="image/next.gif" onclick='page.selectedIndex+=1;'>");
    this.EnabledImages.Add("<input type=image src="/image/last.gif" mce_src="image/last.gif" onclick='page.selectedIndex=page.options.length-1;'>");
    this.DisabledImages.Add("<img src="/image/first_d.gif" mce_src="image/first_d.gif" border =0>");
    this.DisabledImages.Add("<img src="/image/pre_d.gif" mce_src="image/pre_d.gif" border =0>");
    this.DisabledImages.Add("<img src="/image/next_d.gif" mce_src="image/next_d.gif" border =0>");
    this.DisabledImages.Add("<img src="/image/last_d.gif" mce_src="image/last_d.gif" border =0>");
    this.HtmlFormat = "{FirstButton} {PreviousButton} {NextButton} {LastButton}";
    this.ToHtml     = GetNavigateButtonsHtml;
    this.toString   = GetNavigateButtonsHtml;
}
function GetNavigateButtonsHtml()   //输入出HTML格式内容
{
    var re = //{/w+/}/ig;
    var matches = this.HtmlFormat.match(re);
    var result = this.HtmlFormat;
    var btn;
    for (var i=0; i<matches.length; i++)
    {   //matches[i] = "{var_aname}"
        re.compile(matches[i], "gi");
        btn = eval("this."+matches[i].substring(1, matches[i].length-1));
        if (btn == undefined) result = result.replace(re, "");
        else
        {
            var value = (btn.Enabled ? this.EnabledImages[btn.ImageIndex] : this.DisabledImages[btn.ImageIndex])
            result = result.replace(re, value);
        }
    }
    return result;
}
//以下为兼容VBScript而设
//建立NavigateButtons, Ex: set navbtns = CreateNavigateButtons()
function CreateNavigateButtons() { return new NavigateButtons(); }
//////////////////// End NavigateButtons ////////////////////
//////////////////// Begin PageInfo ////////////////////
/*************************************************************
页面相关信息
    属性:
        FirstItem、LastItem:当前页显示的第一条数据和最后一条数据在总数据中的顺序号
        ItemsCount:数据总数
        MaxList:每面显示的最大数目
        ListCount:当前页显示的数据数目
        Page:当前页号
        PageCount:总页数
    方法:
        ToHtml:输出HTML格式内容
    事件:(无)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function PageInfo()
{
    this.FirstItem  = 0;
    this.LastItem   = 0;
    this.ItemsCount = 0;
    this.MaxList    = 15;   //数据显示的最大行数
    this.ListCount  = 0;    //当前页面显示的数据行数
    this.Page       = 0;    //当前页号
    this.PageCount  = 0;
    this.HtmlFormat = "第{FirstItem}-{LastItem}条信息,共{ItemsCount}条信息";   //默认并不输出页码跳转下拉列表框
    this.ToHtml     = GetPageInfoHtml;
    this.toString   = GetPageInfoHtml;
    this.PageListFormat = "<SELECT id=page name=page onchange='this.form.submit();'><s"+"cript language=javascript>for (var i=1;i<={PageCount};i++) if (i=={Page}) document.writeln('<OPTION VALUE='+i+' selected>'+i); else document.writeln('<OPTION VALUE='+i+'>'+i);</s"+"cript></SELECT>"
    this.GetPageList = GetPageList;
}
function GetPageInfoHtml()  //输入出HTML格式内容
{
    return ToHtml(this.HtmlFormat, this);
}
function GetPageList() {return ToHtml(this.PageListFormat, this);}
//以下为兼容VBScript而设
//建立PageInfo, Ex: set pageinfo = CreatePageInfo()
function CreatePageInfo() { return new PageInfo(); }
//////////////////// End PageInfo ////////////////////
//////////////////// Begin Columns ////////////////////
/*************************************************************
数据列对象
    属性:
        Title、Field、MaxLength、Count(说明略)
    方法:
        Add、Remove(说明略)
    事件:(无)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function Column_Component(Title, Field, TagName, MaxLength, Func)
{
    this.Title      = Title;     //显示的标题
    this.Field      = Field;     //保存字段名
    this.TplTagName = TagName    //模板标记名
    this.MaxLength  = MaxLength; //显示的最大长度
    this.Function   = Func;      //调用的函数(主要用于实现类型转换)
    this.toString   = Column_ToString;
}
function Column_ToString() { return "Title:"+this.Title+",Field:"+this.Field+",TagName:"+this.TplTagName+",MaxLength:"+this.MaxLength+",Function:"+this.Function; }
function Columns()
{
    this.Count  = 0;
    this.Add    = AddColumn;
    this.Remove = RemoveColumn;
    this.Clear  = ClearColumn;
    this.Items  = GetSubItem;  //for VBScript 取子项内容, Ex: data.Items(0)
}
function AddColumn(Title, Field, TagName, MaxLength, Func) { this[this.Count++] = new Column_Component(Title, Field, TagName, MaxLength, Func); }
function RemoveColumn(Index)
{
    if (Index<0 || Index>=this.Count) return;
    var i = Index;
    while (i < this.Count) this[i] = this[++i];
    delete this[this.Count--];
}
function ClearColumn() { while (this.Count>0) delete this[this.Count--];}
//以下为兼容VBScript而设
//建立Columns, Ex: set Columns = CreateColumns()
function CreateColumns() { return new Columns(); }
//////////////////// End Columns ////////////////////
// --></mce:script>
<mce:script runat=server language=vbscript><!--
'==========================================================
' 内置于分页类中的数据库组件(需clsDB支持)
'==========================================================
Class SQL_Component
    Private m_SqlCmd, m_SqlCreateBySelf
    Public DB
    ' 构造函数
    Private Sub Class_Initialize
        Me.DB = Null
        m_SqlCmd = ""
        m_SqlCreateBySelf = False
    End Sub
    ' 析构函数
    Private Sub Class_Terminate
        If Not (IsNull(Me.DB) And m_SqlCreateBySelf) then Set Me.DB = Nothing
        m_SqlCmd = ""
    End Sub
    
    ' 操作数据库对象
'     Public Default Property Get SQL()
'         SQL = DB
'     End Property
'     Public Property Set DB(Byref Value)
'         If Not (IsNull(Me.DB) And m_SqlCreateBySelf) Then Set Me.DB = nothing : m_SqlCreateBySelf = false
'         set Me.DB = Value
'     End Property
    Public sub AssignTo(Byref Value)
        If Not (IsNull(Me.DB) And m_SqlCreateBySelf) Then Set Me.DB = nothing : m_SqlCreateBySelf = false
        set Me.DB = Value
    End sub
    
    ' 操作SQL查询命令
    Public Property Get SQLCommand()
        SQLCommand = m_SqlCmd
    End Property
    Public Property Let SQLCommand(Value)
        m_SqlCmd = Value
    End Property
        
    ' 查询数据库
    Public Function Process()
        If IsNull(Me.DB) Then Set Me.DB = New clsDB : m_SqlCreateBySelf = true
        Me.DB.Query(m_SqlCmd)
    End Function
End Class
'==========================================================
' 内置于分页类(kktPageEx)中的模板组件(需kktTemplate支持)
'==========================================================
Class TPL_Component
    Private m_Filename, m_Handle, m_Block, m_Block2, m_TplCreateBySelf
    Private m_ShowNavBar, m_PageInfoBlock, m_ButtonBlock, m_PageNavBlock
    Public TPL, Columns
    
    Private Sub Class_Initialize
        Me.TPL = Null
        set Columns = CreateColumns()
        m_TplCreateBySelf = False
        m_ShowNavBar      = true
        m_PageInfoBlock   = "PageInfo"
        m_ButtonBlock     = "Buttons"
        m_PageNavBlock    = "PageList"
    End Sub
    Private Sub Class_Terminate
        If Not (IsNull(Me.TPL) And m_TplCreateBySelf) then Set Me.TPL = Nothing
        Set Columns = Nothing
    End Sub
    
    Public sub AssignTo(Byref Value)
        If Not (IsNull(Me.TPL) And m_TplCreateBySelf) Then Set Me.TPL = nothing : m_TplCreateBySelf = false
        set Me.TPL = Value
    End Sub
    
    ' 模板文件,请参阅kktTemplate中set_file函数
    ' 仅当Tpl对象由本对象生成实例时使用
    Public Property Get FileName()
        FileName = m_Filename
    End Property
    Public Property Let FileName(Value)
        m_Filename = Value
    End Property
    
    ' 模板句柄,请参阅kktTemplate中set_file函数
    ' 仅当Tpl对象由本对象生成实例时使用
    Public Property Get Handle()
        Handle = m_Handle
    End Property
    Public Property Let Handle(Value)
        m_Handle = Value
    End Property
    
    ' 模板块的名称,请参阅kktTemplate中set_block函数
    Public Property Get Block()
        Block = m_Block
    End Property
    Public Property Let Block(Value)
        m_Block = Value
    End Property
    ' 模板块2的名称,数据为空时使用
    Public Property Get Block2()
        Block2 = m_Block2
    End Property
    Public Property Let Block2(Value)
        m_Block2 = Value
    End Property
    
    ' 设置模板相关变量
    Public Sub Setup(FileName, Handle, Block, Block2)
        m_Filename = FileName
        m_Handle   = Handle
        m_Block    = Block
        m_Block2   = Block2
    End Sub
    ' 是否输出导航条
    Public Property Get ShowNavigateBar()
        ShowNavigateBar = m_ShowNavBar
    End Property
    Public Property Let ShowNavigateBar(value)
        m_ShowNavBar = value
    End Property
    ' 显示页面信息的模板标记名称,页面信息参见PageInfo对象
    Public Property Get PageInfoBlock()
        PageInfoBlock = m_PageInfoBlock
    End Property
    Public Property Let PageInfoBlock(value)
        m_PageInfoBlock = value
    End Property
    ' 显示导航的模板标记名称,页面信息参见NavigateButtons对象
    Public Property Get ButtonBlock()
        ButtonBlock = m_ButtonBlock
    End Property
    Public Property Let ButtonBlock(value)
        m_ButtonBlock = value
    End Property
    ' 显示页面跳转列表的模板标记名称,页面信息参见PageInfo.GetPageListBox
    Public Property Get PageNavigateBlock()
        PageNavigateBlock = m_PageNavBlock
    End Property
    Public Property Let PageNavigateBlock(value)
        m_PageNavBlock = value
    End Property
    
    ' 设置导航条相关信息
    Public Sub SetNaviageBar(Visible, PageInfoBlock, ButtonBlock, PageNavigateBlock)
        m_ShowNavBar    = Visible
        m_PageInfoBlock = PageInfoBlock
        m_ButtonBlock   = ButtonBlock
        m_PageNavBlock  = PageNavigateBlock
    End Sub
    Public Function Process(ByRef DB, ByVal MaxList)
        Dim data1, data2, cnt
        If m_Filename="" Or m_Handle="" Or m_Block="" Or Columns.Count=0 Then Err.Raise 65535, "TPL_Component", "进行模板处理之前请先设置相关变量"
        If IsNull(Me.TPL) Then
            Set Me.TPL = New kktTemplate
            m_TplCreateBySelf = True
            Me.TPL.set_file m_Handle, m_FileName
        End If
        data1 = "tpl_data" & Right(CDbl(Now()), 8)
        data2 = "tpl_prompt" & Right(CDbl(Now()), 8)
        Me.TPL.Set_block m_Handle, m_Block, data1
        If m_Block2<>"" then
            Me.TPL.Set_block m_Handle, m_Block2, data2 
            If DB.Eof Then Me.TPL.parse data2, m_Block2, False
        End If
        cnt = 0
        While cnt<MaxList and Not DB.Eof
            For i=0 To Me.Columns.Count-1
                data2 = ""
                data2 = DB.Data(Me.Columns.Items(i).Field)
                If Me.Columns.Items(i).Function<>"" Then Execute("data2=" & Me.Columns.Items(i).Function & "(data2)")
                If Me.Columns.Items(i).MaxLength>0 And Len(data2)>Me.Columns.Items(i).MaxLength Then data2 = Left(data2, Me.Columns.Items(i).MaxLength-1) & "..."
                data2 = Server.HTMLEncode(data2)
                Me.TPL.Set_var Me.Columns.Items(i).TplTagName, data2, False
            Next
            Me.TPL.parse data1, m_Block, True
            DB.MoveNext
            cnt = cnt + 1
        Wend
    End Function
    
    Public sub BindNavigateInfo(byref Page, ByRef Btn)
        If IsNull(Me.TPL) Then
            Set Me.TPL = New kktTemplate
            m_TplCreateBySelf = True
            Me.TPL.set_file m_Handle, m_FileName
        End If
        Me.TPL.set_var m_PageInfoBlock, Page.ToHtml(), False
        Me.TPL.set_var m_PageNavBlock, Page.GetPageList(), false
        Me.TPL.set_var m_ButtonBlock, Btn.ToHtml(), False
    End Sub
    
    Public Sub Display()
        If isnull(Me.Tpl) Then Err.Raise 65535, "TPL_Component", "模板对象尚未创建"
        Me.TPL.parse "kktpage_tpl_out", m_Handle, False
        Me.TPL.p "kktpage_tpl_out"
    End Sub
End Class
// --></mce:script>


2、kktpage.asp

<%%>
<!--#INCLUDE file="kktpageinc.asp"-->
<%
'=======================================================================
' CLASS NAME:  kktPage 查询分页类
' DESIGN BY :  彭国辉
' DATE:        2004-03-12
' SITE:        http://blog.csdn.net/nhconch ' EMAIL:       kacarton#sohu.com
'=======================================================================
Class kktPage
    
    'Private m_PageInfo, m_Buttons, m_SQL
    Public PageInfo, Buttons, SQL
    
    ' 构造函数
    Private Sub Class_Initialize
        Set Me.PageInfo = CreatePageInfo()
        Set Me.Buttons = CreateNavigateButtons()
        set Me.SQL = New SQL_Component
    End Sub
    
    ' 析构函数
    Private Sub Class_Terminate
        Set Me.Buttons = Nothing
        Set Me.PageInfo = Nothing
        Set Me.SQL = nothing
    End Sub
    
    Public Property Get ClassName() ' 若使用Public Default Property Get方式声明,则过程中定义的属性为类的缺省属性
        ClassName = "kktPage"
    End Property
    
    Public Property Get Version()
        Version = "1.0"
    End Property
    
    Public Sub About()
        Response.Write("kktPage 查询分页类<br>" & vbCrLf &_
                       "程序设计:彭国辉 2004-03-12<br>" & vbCrLf &_
                       "个人网站:<a href="http://kacarton.yeah.net" mce_href="http://kacarton.yeah.net">http://kacarton.yeah.net</a><br>" & vbCrLf &_
                       "电子邮件:<a href="mailto:kacarton@sohu.com" mce_href="mailto:kacarton@sohu.com">kacarton@sohu.com</a><br>")
    End Sub
    
'     Public Property Get PageInfo()
'         PageInfo = m_PageInfo
'     End Property
' 
'     Public Property Get Buttons()
'         Buttons = m_Buttons
'     End Property
'     
'     Public Property Get SQL()
'         SQL = m_SQL '*****************
'     End Property
'     Public Property Let SQL(ByRef value)
'         m_SQL.SQL = value
'     End Property
    
    ' 查询数据库、生成相关信息
    Public sub Process()
        Me.SQL.Process
        If Me.SQL.DB.Eof Then
            ' 更新PageInfo
            Me.PageInfo.FirstItem  = 0
            Me.PageInfo.LastItem   = 0
            Me.PageInfo.ItemsCount = 0
            Me.PageInfo.ListCount  = 0
            Me.PageInfo.Page       = 0
            Me.PageInfo.PageCount  = 0
            ' 更新Buttons
            Me.Buttons.FirstButton.Enabled    = False
            Me.Buttons.PreviousButton.Enabled = False
            Me.Buttons.NextButton.Enabled     = False
            Me.Buttons.LastButton.Enabled     = False
        Else
            ' 更新PageInfo
            Me.PageInfo.ItemsCount = Me.SQL.DB.RecordCount
            Me.SQL.DB.PageSize    = Me.PageInfo.MaxList
            Me.PageInfo.PageCount  = Me.SQL.DB.PageCount
            If Me.PageInfo.Page < 1 Then Me.PageInfo.Page = 1
            If Me.PageInfo.Page > Me.PageInfo.PageCount Then Me.PageInfo.Page = Me.PageInfo.PageCount
            Me.PageInfo.FirstItem  = (Me.PageInfo.Page-1) * Me.PageInfo.MaxList + 1
            If Me.PageInfo.Page < Me.PageInfo.PageCount Then
                Me.PageInfo.ListCount = Me.PageInfo.MaxList
            Else
                Me.PageInfo.ListCount = Me.PageInfo.ItemsCount mod Me.PageInfo.MaxList
            End If
            Me.PageInfo.LastItem = Me.PageInfo.FirstItem + Me.PageInfo.ListCount - 1
            Me.SQL.DB.AbsolutePage = Me.PageInfo.Page
            ' 更新Buttons
            If Me.PageInfo.Page <= 1 then
                Me.Buttons.FirstButton.Enabled    = False
                Me.Buttons.PreviousButton.Enabled = False
            else
                Me.Buttons.FirstButton.Enabled    = true
                Me.Buttons.PreviousButton.Enabled = true
            End If
            If Me.PageInfo.Page >= Me.PageInfo.PageCount then
                Me.Buttons.NextButton.Enabled = False
                Me.Buttons.LastButton.Enabled = False
            else                             
                Me.Buttons.NextButton.Enabled = true
                Me.Buttons.LastButton.Enabled = true
            End If
        End If
    End sub
End Class
%>


3、kktpageex.asp

<%%>
<!--#INCLUDE file="kktpageinc.asp"-->
<%
'=======================================================================
' CLASS NAME:  kktPageEx 带模板的查询分页类
' DESIGN BY :  彭国辉
' DATE:        2004-03-12
' SITE:        http://kacarton.yeah.net/ ' EMAIL:       kacarton@sohu.com
'=======================================================================
Class kktPageEx
    
    'Private m_PageInfo, m_Buttons, m_SQL
    Public PageInfo, Buttons, SQL, Template
    
    ' 构造函数
    Private Sub Class_Initialize
        Set Me.PageInfo = CreatePageInfo()
        Set Me.Buttons  = CreateNavigateButtons()
        set Me.SQL      = New SQL_Component
        set Me.Template = New TPL_Component
    End Sub
    
    ' 析构函数
    Private Sub Class_Terminate
        Set Me.Buttons = Nothing
        Set Me.PageInfo = Nothing
        Set Me.SQL = Nothing
        Set Me.Template = nothing
    End Sub
    
    Public Property Get ClassName()
        ClassName = "kktPageEx"
    End Property
    
    Public Property Get Version()
        Version = "1.0"
    End Property
    
    Public Sub About()
        Response.Write("kktPageEx 带模板的查询分页类<br>" & vbCrLf &_
                       "程序设计:彭国辉 2004-03-12<br>" & vbCrLf &_
                       "个人网站:<a href="http://kacarton.yeah.net" mce_href="http://kacarton.yeah.net">http://kacarton.yeah.net</a><br>" & vbCrLf &_
                       "电子邮件:<a href="mailto:kacarton@sohu.com" mce_href="mailto:kacarton@sohu.com">kacarton@sohu.com</a><br>")
    End Sub
    
    ' 查询数据库、生成相关信息
    Public sub Process()
        Me.SQL.Process
        If Me.SQL.DB.Eof Then
            ' 更新PageInfo
            Me.PageInfo.FirstItem  = 0
            Me.PageInfo.LastItem   = 0
            Me.PageInfo.ItemsCount = 0
            Me.PageInfo.ListCount  = 0
            Me.PageInfo.Page       = 0
            Me.PageInfo.PageCount  = 0
            ' 更新Buttons
            Me.Buttons.FirstButton.Enabled    = False
            Me.Buttons.PreviousButton.Enabled = False
            Me.Buttons.NextButton.Enabled     = False
            Me.Buttons.LastButton.Enabled     = False
        Else
            ' 更新PageInfo
            Me.PageInfo.ItemsCount = Me.SQL.DB.RecordCount
            Me.SQL.DB.PageSize     = Me.PageInfo.MaxList
            Me.PageInfo.PageCount  = Me.SQL.DB.PageCount
            If Me.PageInfo.Page < 1 Then Me.PageInfo.Page = 1
            If Me.PageInfo.Page > Me.PageInfo.PageCount Then Me.PageInfo.Page = Me.PageInfo.PageCount
            Me.PageInfo.FirstItem  = (Me.PageInfo.Page-1) * Me.PageInfo.MaxList + 1
            If Me.PageInfo.Page < Me.PageInfo.PageCount Then
                Me.PageInfo.ListCount = Me.PageInfo.MaxList
            Else
                Me.PageInfo.ListCount = Me.PageInfo.ItemsCount mod Me.PageInfo.MaxList
            End If
            Me.PageInfo.LastItem = Me.PageInfo.FirstItem + Me.PageInfo.ListCount - 1
            Me.SQL.DB.AbsolutePage = Me.PageInfo.Page
            ' 更新Buttons
            If Me.PageInfo.Page <= 1 then
                Me.Buttons.FirstButton.Enabled    = False
                Me.Buttons.PreviousButton.Enabled = False
            else
                Me.Buttons.FirstButton.Enabled    = true
                Me.Buttons.PreviousButton.Enabled = true
            End If
            If Me.PageInfo.Page >= Me.PageInfo.PageCount then
                Me.Buttons.NextButton.Enabled = False
                Me.Buttons.LastButton.Enabled = False
            else                             
                Me.Buttons.NextButton.Enabled = true
                Me.Buttons.LastButton.Enabled = true
            End If
        End If
        Me.Template.Process Me.SQL.DB, Me.PageInfo.MaxList
    End Sub
    
    Public Sub Display()
        If Me.Template.ShowNavigateBar Then Me.Template.BindNavigateInfo Me.PageInfo, Me.Buttons
        Me.Template.Display
    End Sub
End Class
%>




连接:

ASP高级类kktPage——将ASP查询分页封装起来(2)

相关知识:

ASP中轻松实现变量名-值变换http://blog.csdn.net/nhconch/archive/2004/07/07/36104.aspx

ASP的数据库类http://blog.csdn.net/nhconch/archive/2004/07/16/42869.aspx

使用模板实现ASP代码与页面分离http://blog.csdn.net/nhconch/archive/2004/07/10/38683.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: