效果图:

Read the rest of this entry

,

调用:

db.query("select * from News")
rs = db.fetch_all
for i=0 to db.num_rows - 1
    response.write rs(1,i) & "<br>"
next
 
db.query("select * from admin")
response.write db.get_value("id")

Read the rest of this entry

半年前写的一个ASP的分页函数

<%sub fanye(sql,n,col,wid,orderbycol,ifID,ifop,opname,opurl,opqstr,fyurl,sqlcol,rec,col_a,col_url,col_qstr,col_alname,col_align,defaultorderby)
' ************************************使用说明************************************
' **                   **
' **  本程序的各项功能均通过测试,但是由于参数很多,如果不能正常运行  **
' **  请仔细检查参数,参数的个数,以及参数中包含的",",这对于程序的运  **
' **  行是很重要的,在使用之前请仔细阅读下面的使用说明.     **
' **                   **
' **--参数说明------------------------------------------------------------------**
' **                   **
' **--sql:       SQL语句              **
' **--n:         每页显示记录数             **
' **--col:       列名,用逗号隔开            **
' **--wid:       列宽,用逗号隔开            **
' **--orderbycol:BOOLEAN值,点击列名是否可以重新排序,如果值为true,那么sql参数中 **
' **    请不要包含order by语句           **
' **--ifID:      第一项是否显示序号            **
' **--ifop:      最后一项是否为操作项           **
' **--opname:    操作项名称,用逗号隔开           **
' **--opurl:     操作项转向页面,用逗号隔开,可以带参数,但不可和数据库中数据相关 **
' **--opqstr:    操作项传递参数,操作项之间逗号隔开,参数之间空格隔开    **
' **--fyurl:     翻页转向页面,可以带参数,但不可和数据库中数据相关,一般是本页 **
' **--sqlcol:    对应数据库列名             **
' **--rec:       显示什么量词,如:"条记录","条留言"...       **
' **--col_a:     需要链接的列,逗号隔开           **
' **--col_url:   链接地址,逗号隔开,可以带参数,但不可和数据库中数据相关   **
' **--col_qstr:  链接传递的参数,列之间逗号隔开,参数之间空格隔开     **
' **--col_alname:需要重调对齐列列名,默认对齐方式是居中,如果全部居中请空出.  **
' **--col_align: 上述列的对齐方式.*技巧:这一项还可以对其他的属性进行设置,例如: **
' **    "center style*cursor:pointer",这样写这个参数,就能够将对应单元格**
' **    的鼠标指针设成手形,其他属性类推.        **
' **                   **
' **--参数说明------------------------------------------------------------------**
' **                   **
' **--注意事项------------------------------------------------------------------**
' **                   **
' **1-传递参数需与数据库列名相同            **
' **2-col,wid这两个参数中","应该相同,如果想留一栏不设置列宽,可空出来,例如:  **
' **  "20%,,30%"那么第二列的列宽就被空了下来.         **
' **3-opname,opurl参数中","也应该相同.           **
' **4-col_a,col_url参数中","也应该相同.           **
' **5-关于ifID,指的是序号,也就是1,2,3......而不是从数据库中的ID     **
' **6-ifID,ifop如果为true,则序号必须在第一项,操作项必须在最后一项,并且对应的 **
' **  sqlcol的第一项和最后一项也应该空起来,如:",ID,title,name,content,"   **
' **7-关于表格的背景色没有写在参数里,因为我想大家做网站风格都是一样的,可以  **
' **  直接在下面的设置中修改             **
' **8-再就是链接的style,直接在下面修改           **
' **9-使用之前先做好数据库的连接.            **
' **10col_alname,col_align参数中","也应该相同.         **
' **11序号和操作列的对齐方式为居中,不可通过参数修改,要修改直接在下面代码中修改. **
' **12列名所在的列的对齐方式同上.            **
' **13本程序仅适用于读取单一数据库表的翻页,并且仅从数据库中读取数据而不对数据作 **
' **  任何处理的翻页.               **
' **14当某些参数并不需要时,如ifop为false时,opname,opurl,opqstr这三项就并不需要, **
' **  此时应该用不相关的字符串作为参数,不可用空字符串!       **
' **                   **
' **--注意事项------------------------------------------------------------------**
' **                   **
' **                   **
' **--版权说明------------------------------------------------------------------**
' **                   **
' **--本程序供大家学习和交流之用,可以根据实际需要修改其中代码,但请保留以下文字--**
' **--本程序供大家学习和交流之用,可以根据实际需要修改其中代码,但请保留以下文字--**
' **    *****************************************     **
' **    * 程序作者:PW.Wang     *     **
' **    * QQ:22670595       *     **
' **    * Blog:http://hi.baidu.com   *     **
' **    * 讨论群:14802379      *     **
' **    *****************************************     **
' **--本程序供大家学习和交流之用,可以根据实际需要修改其中代码,但请保留以上文字--**
' **--本程序供大家学习和交流之用,可以根据实际需要修改其中代码,但请保留以上文字--**
' **                   **
' **--版权说明------------------------------------------------------------------**
' **                   **
' ************************************使用说明************************************
 
' -----------------处理参数------------------
cols=split(col,",")
wids=split(wid,",")
if instr(fyurl,"?")>0 then
 fyurl=fyurl&"&"
else
 fyurl=fyurl&"?"
end if
sqlcols=split(sqlcol,",")
if orderbycol then
 orderstrs=split(sqlcol,",")
 orderby=saferequest("orderby")
 if orderby="" then orderby=defaultorderby
 sql=sql&" order by "&orderby
 orderby2=replace(orderby," desc","")
 for d=0 to ubound(sqlcols)
  if sqlcols(d)=orderby2 then
   if instr(orderby," desc")<=0 then
    orderstrs(d)=orderstrs(d)&" desc"
   else
    orderstrs(d)=replace(orderstrs(d)," desc","")
   end if
   exit for
  end if
 next
end if
opnames=split(opname,",")
opurls=split(opurl,",")
for b=0 to ubound(opurls)
 if instr(opurls(b),"?")>0 then
  opurls(b)=opurls(b)&"&"
 else
  opurls(b)=opurls(b)&"?"
 end if
next
opqstrs=split(opqstr,",")
redim opqstrss(ubound(opqstrs))
for w=0 to ubound(opqstrs)
 opqstrss(w)=split(opqstrs(w)," ")
next
col_as=split(col_a,",")
col_urls=split(col_url,",")
for c=0 to ubound(col_urls)
 if instr(col_urls(c),"?")>0 then
  col_urls(c)=col_urls(c)&"&"
 else
  col_urls(c)=col_urls(c)&"?"
 end if
next
col_qstrs=split(col_qstr,",")
redim col_qstrss(ubound(col_qstrs))
for t=0 to ubound(col_qstrs)'
 col_qstrss(t)=split(col_qstrs(t)," ")
next
col_alnames=split(col_alname,",")
col_aligns=split(col_align,",")
for l=0 to ubound(col_aligns)
 if col_aligns(l)="" then col_aligns(l)="center"
next
' -----------------处理参数------------------
 
set rs=server.createobject("adodb.recordset")
rs.PageSize = cint(n)  
rs.CursorLocation = 3
rs.open sql,conn,0,2,1
pre = true
last = true
page = trim(request("page"))
 
if len(page) = 0 then
 intpage = 1
    pre = false
else
    if cint(page) =< 1 then
        intpage = 1
        pre = false
    else
     if cint(page) >= rs.PageCount then
            intpage = rs.PageCount
            last = false
        else
            intpage = cint(page)
        end if
    end if
end if
if not rs.eof then
    rs.AbsolutePage = intpage
end if
%>
<table bgcolor="#ffffff" width="100%" border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td><table bgcolor="#f95559" width="100%" border="0" cellspacing="1" cellpadding="0">
      <tr bgcolor=#ffcc99>
        <%'写表头
   for x=0 to ubound(cols)
   if orderbycol then
    if (x=0 and ifID=true) or (x=ubound(cols) and ifop=true) then
     response.write "<td height=22 align=center width="&wids(x)&"><b>"&cols(x)&"</b></td>"
    else
     response.write "<td height=22 align=center width="&wids(x)&"><b><a href="&fyurl&"orderby"&"="&server.urlencode(orderstrs(x))&">"&cols(x)&"</a></b></td>"
    end if
   else
     response.write "<td height=22 align=center width="&wids(x)&"><b>"&cols(x)&"</b></td>"
   end if
   next
  %>
      </tr>
  <%
    num=1
  for y=1 to n
  if rs.eof or rs.bof then exit for
  '写循环体
  %>
      <tr bgcolor="#ffffff" onmouseover=this.style.background='#ffcc99' onmouseout=this.style.background='#ffffff'>
  <%
      for z=0 to ubound(cols)
      if z=0 and ifID=true then
    response.write "<td height=22 align=center>"&num+n*(intpage-1)&"</td>"
   elseif z=ubound(cols) and ifop=true then
    response.write "<td height=22 align=center>"
    for m=0 to ubound(opnames)
     if opnames(m)="删除" then
     response.write "<a onclick=""return confirm('确定删除?')"" href="&opurls(m)
     else
     response.write "<a href="&opurls(m)
     end if
     for e=0 to ubound(opqstrss(m))
      if e=ubound(opqstrss(m)) then
       response.write opqstrss(m)(e)&"="&rs(opqstrss(m)(e))
      else
       response.write opqstrss(m)(e)&"="&rs(opqstrss(m)(e))&"&"
      end if
     next
     if m=ubound(opnames) then
      response.write ">"&opnames(m)&"</a>"
     else
      response.write ">"&opnames(m)&"</a> "
     end if
    next
    response.write "</td>"
   else
    for r=0 to ubound(col_as)
     if col_as(r)=cols(z) then
      response.write "<td height=22 align="
      if col_alname="" then 
       response.write "center>"
      else
       eq=0
       for a=0 to ubound(col_alnames)
        if col_alnames(a)=cols(z) then 
         eq=1
         aa=a
        exit for
        end if
       next
       if eq=1 then
        if instr(col_aligns(aa),"left")=1 then
         response.write col_aligns(aa)&"> "
        else
         response.write col_aligns(aa)&">"
        end if
       else 
        response.write "center>"
       end if
      end if
      response.write "<a href="&col_urls(r)
      for u=0 to ubound(col_qstrss(r))
       if u=ubound(col_qstrss(r)) then
        response.write col_qstrss(r)(u)&"="&rs(col_qstrss(r)(u))
       else
        response.write col_qstrss(r)(u)&"="&rs(col_qstrss(r)(u))&"&"
       end if
      next
      response.write ">"&rs(sqlcols(z))&"</a></td>"
     else
      response.write "<td height=22 align="
      if col_alname="" then 
       response.write "center>"
      else
       eq1=0
       for k=0 to ubound(col_alnames)
        if col_alnames(k)=cols(z) then 
         eq1=1
         kk=k
        exit for
        end if
       next
       if eq1=1 then
        if instr(col_aligns(kk),"left")=1 then
         response.write col_aligns(kk)&"> "
        else
         response.write col_aligns(kk)&">"
        end if
       else 
        response.write "center>"
       end if
      end if
      response.write rs(sqlcols(z))&"</td>"
     end if
    next 
   end if
   next
    %>
      </tr>
   <%
  rs.movenext
  num=num+1
  next
   %>
    </table></td>
  </tr>
  <tr>
    <td><table bgcolor=#ffffff width="100%" border="0" cellpadding="0" cellspacing="2">
      <tr><!--翻页-->
        <%if rs.pagecount > 0 then%>
        <td height="20" align="left">当前页<font />          共<font rs.RecordCount%></font><%=rec%>
          本页显示第
        <%response.write rs.pagesize*(intpage-1)+1%>~<%if intpage<rs.pagecount then 
        num=rs.pagesize*intpage 
        else 
        num=rs.recordcount
        end if
  response.write num%> <%=left(rec,1)%></td>
        <%else%>
        <td height="20" align="left">当前页0/0  共0<%=rec%></td>
        <%end if%>
        <td width="45%" align="right"><a href=<%=fyurl%>page=1>首页</a>|
          <%if pre then%>
            <a href=<%=fyurl%>page=<%=intpage -1%>>上页</a>|
          <%end if%>
            <%if last then%>
            <a href=<%=fyurl%>page=<%=intpage +1%>>下页</a>|
          <%end if%>
            <a href=<%=fyurl%>page=<%=rs.PageCount%>>尾页</a>|
            转到第
            <select style="width=45px;" name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
              <%for i = 1 to rs.PageCount
     if i = intpage then%>
      <option value=<%=fyurl%>page=<%=i%> selected><%=i%></option>
     <%else%>
      <option value=<%=fyurl%>page=<%=i%>><%=i%></option>
       <%end if
          next
  rs.close
  set rs=nothing
        %>
        </select>
 
        页</td>
      </tr>
    </table></td>
  </tr>
</table>
<%end sub%>

昨天晚上一个通宵,将半年前写的这个Sub改成了Class,

其实不仅是一种类别的改变, 同时将css定义与循环体分开了,更利于定义新的皮肤,适合不同的场所,

再就是对赋值的错误参数的检测有了进一步提高;

再一个好处是类Class所体现的,封装性,这是Sub所不具备的,还记得以前调用Call Fanye(….)括号里面写一大参数的时候,有时候会把我原来的表格的结构破坏了,后来发现是我用的循环变量和Sub里用的循环体变量一样,导致了错误的发生

另一个好处,我觉得我再用我现在写的这个类时,就会松一口气了,最起码不用写一个参数看下一个参数,并且顺序还不能错,这个就可以在构造函数:Class_Initialize中对某些参数给一些默认值,这样就不必每一个参数都赋值,并且顺序也无所谓

好了,说了这么多好处,还是来看一下具体的程序吧,不过我觉得不太会有人能看完,呵呵

fanye.asp:

<link href="fy.css" rel="stylesheet" type="text/css" />
<%
Class Fanye
 Private fDBPath  'DateBasePath  数据库地址
 Private fConn
 Private fSql  'Sql Language SQL 语句
 Private fRs   'RecordSet     记录集
 Private fN   'The number of records in one page 第一页显示的记录条数
 Private fColNames'The names of columns   表格中每一列表头的名称
 Private fColWidth'The width of columns  每一列的宽度
 Private fOrderByCol 'Bool. If ordering by clicking ColNames is avaliable 是否可能通过点击列名来重新排序
 Private fIfID  'Bool. If there is a natural number at the head of a record 是否从1 开始对记录进行编号,并显示在第一列
 Private fIfOp'Bool. If Op is abled    是否对记录有操作项
 Private fOpNames '操作项的名字
 Private fOpUrls  '操作项的链接,包含在href在内如链接为a.asp时,应这样给值: href=a.asp,这样就比如灵活,可以加属性,如这样赋值: onlick="javascript:alert('ensure?')" href=a.asp
 Private fOpQueryString '操作项的参数,注意参数的名字和数据库中对应的列名相同
 Private fFyUrl  'The url of current page 翻页URL
 Private fDBColNames '数据库中的列表
 Private fRec  ' eg.条记录 获取记录的量词
 Private fAColSN 'The serial number of columns who needs a link, 需要添加链接的列的序号,从0开始
 Private fAColUrls 'The url of the link above,对应的链接,同操作项的链接
 Private fAColQueryString'对应的参数,同操作项的参数
 Private fDefaultOrderBy '默认的排序依据
 Private fAddColSN '需要添加其他属性的列的序号,从0开始
 Private fAddColPro'对应的属性
 
 Private pre '记录是否显示上一页
 Private last '记录是否显示下一页
 Private page '页数
 Private orderby '接收排序命令
 Private intpage '当前页数
 Private fErr  'To record errors
 
 Public Property Let IfID(ForT)
  fIfID=ForT
 End Property
 
 Public Property Let IfOp(TorF)
  fIfOp=TorF
 End Property
 
 Public Property Let N ( Nvalue )
  fN=Nvalue
 End Property
 
 Public Property Let Rec(RecValue)
  fRec=RecValue
 End Property
 
 Public Property Let OrderByCol(OBC)
  fOrderByCol=OBC
 End Property
 
 Public Property Let AColSN(AColNamesValue)
  fAColSN=AColNamesValue
 End Property
 
 Public Property Let AColUrls(AColUrlsValue)
  fAColUrls=AColUrlsValue
 End Property
 
 Public Property Let AColQueryString(AColQueryStringValue)
  fAColQueryString=AColQueryStringValue
 End Property
 
 Public Property Let DefaultOrderBy(DefaultOrderByValue)
  fDefaultOrderBy=DefaultOrderByValue
 End Property
 
 Public Property Let FyUrl(FyUrlValue)
  fFyUrl=FyUrlValue
 End Property
 
 Public Property Let DBColNames(DBColNamesValue)
  fDBColNames=DBColNamesValue
 End Property
 
 Public Property Let OpQueryString(OpQueryStringValue)
  fOpQueryString=OpQueryStringValue
 End Property
 
 Public Property Let OpUrls(OpUrlsValue)
  fOpUrls=OpUrlsValue
 End Property
 
 Public Property Let OpNames(OpNamesValue)
  fOpNames=OpNamesValue
 End Property
 
 Public Property Let ColNames(ColNamesValue)
  fColNames=ColNamesValue
 End Property
 
 Public Property Let ColWidth(ColWidthValue)
  fColWidth=ColWidthValue
 End Property 
 
 Public Property Let DBPath( DBPathValue )
  fDBPath  =DBPathValue
 End Property 
 
 Public Property Let Sql(SqlValue)
  fSql  =SqlValue
 End Property
 
 Public Property Let AddColSN(AddColSNValue)
  fAddColSN=AddColSNValue
 End Property
 
 Public Property Let AddColPro(AddColProValue)
  fAddColPro=AddColProValue
 End Property
 
 Private Sub Class_Initialize()   '构造函数
  fN   =10 '10 Records in One Page as Default
  fErr  =""
  fOrderByCol =False 'Order by columns is disabled
  fIfID  =False'There is a natural number at the head of a record
  fIfOp  =False'Op is abled.
  fRec  ="条记录"
  fAColSN  =-1  '默认不添加链接
  pre   =True
  last  =True
  fAddColSN =-1  '默认不添加属性
  fAddOpSN =-1
  fAColUrls ="noaccesslink" '为配合fAColSN的一致性而赋的初值
 
  Set fConn =Server.CreateObject("Adodb.Connection")
  Set fRs  =Server.Createobject("Adodb.Recordset")
 End Sub
 
 Private Sub Class_Terminate() '析构函数
  fRs.Close
  Set fRs  =Nothing
  fConn.Close
  set fConn =Nothing
 End Sub 
 
 Private Function Getorderby(i)   '获取从Querystring的排序依据
  dim ob
  ob=request.QueryString("orderby")
  if not fOrderByCol then
   ob=fDefaultOrderBy
  else
   if ob=DBColName()(i) then
    ob=DBColName()(i)&" desc"
   else
    ob=DBColName()(i)
   end if
  end if
  Getorderby=ob
 End Function
 
 Private Function ColName()     '处理列名
  ColName=Split(fColNames,",")
 End Function
 
 Private Function ColWid()   '处理列宽
  Dim i
  If fColWidth="" Or IsNull(fColWidth) Or IsEmpty(fColWidth) Then
   fColWidth=""
   For i=0 To ColNum-1
    fColWidth=fColWidth&","
   Next
  End If
  ColWid=Split(fColWidth,",")
 End Function
 
 Private Function DBColName()  '处理数据库列名参数
  DBColName=Split(fDBColNames,",")
 End Function
 
 Private Function OpName()    '处理操作项名称
  OpName=Split(fOpNames,",")
 End Function
 
 Private Function AColSNs() '处理超链接列的序号 
  AColSNs=split(fAColSN,",")  
 End Function
 
 Private Function AddColSNs() '处理添加属性列的序号
  AddColSNs=split(fAddColSN,",")
 End Function
 
 Private Function AddColPros() '处理添加属性参数
  AddColPros=split(fAddColPro,",")
 End function
 
 Private Function AColUrl() '添加超链接的URL参数处理
  dim p
  AColUrlss=split(fAColUrls,",")
  for p=0 to ubound(AColUrlss)
   if instr(AColUrlss(p),".asp?")>0 or instr(AColUrlss(p),"?")=6 then '这里的6说一下,其实是我自己的习惯,我习惯于同一页面的链接这样来写:"?action=A"
    AColUrlss(p)=AColUrlss(p)&"&"                                 '那么给值就是这样的:  href=?action=A,所以这里的"?"在第6位
   Else
    AColUrlss(p)=AColUrlss(p)&"?"
   end if
  next
  AColUrl=AColUrlss
 End Function
 
 Private Function GetACQs(x)  '获取超链接的参数的字符串,即类似.asp?后面的内容,x为链接的序号,即给出的第几个链接
  dim p,acqstr,acqstrs()
  acqstr=""
  If fAColQueryString="" or isnull(fAColQueryString) or isempty(fAColQueryString) then
   GetACQs=""
   Exit Function
  End If
  acqs=split(fAColQueryString,",")
  If acqs(x)="" or isnull(acqs(x)) or isempty(acqs(x)) then
   GetACQs=""
   Exit Function
  End if
  Redim acqstrs(ubound(acqs))
  acqstrs(x)=split(acqs(x)," ")
  for p=0 to ubound(acqstrs(x))-1
   acqstr=acqstr&acqstrs(x)(p)&"="&fRs(acqstrs(x)(p))&"&"
  next
  acqstr=acqstr&acqstrs(x)(ubound(acqstrs(x)))&"="&fRs(acqstrs(x)(ubound(acqstrs(x))))
  GetACQs=acqstr
 End Function
 
 Private Function OpUrl()  '处理操作URL
  dim p
  OpUrl1=Split(fOpUrls,",")
  for p=0 to Ubound(OpUrl1)
  If Instr(OpUrl1(p),".asp?")>0 Or Instr(OpUrl1(p),"?")=6 Then
   OpUrl1(p)=OpUrl1(p)&"&"
  Else
   OpUrl1(p)=OpUrl1(p)&"?"
  End If
  Next
  OpUrl=OpUrl1
 End Function
 
 Private Function GetOpQs(x) '同样也是获得URL的参数的字符串,为了后面方便与前缀的URL进行连接
  dim p,opqstr,Opqss()
  opqstr=""
  If fOpQueryString="" Or isnull(fOpQueryString) or isempty(fOpQueryString) then
   GetOpQs=""
   Exit Function
  End if
  OpQs=Split(fOpQueryString,",")
  If OpQs(x)="" Or isnull(OpQs(x)) or isempty(OpQs(x)) then
   GetOpQs=""
   Exit Function
  End if
  Redim Opqss(Ubound(OpQs))
  Opqss(x)=Split(OpQs(x)," ")
  for p=0 to ubound(Opqss(x))-1
   opqstr=opqstr&Opqss(x)(p)&"="&fRs(Opqss(x)(p))&"&"
  next
  opqstr=opqstr&Opqss(x)(Ubound(Opqss(x)))&"="&fRs(Opqss(x)(Ubound(Opqss(x))))
  GetOpQs=opqstr
 End Function
 
 Private Function FUrl()  '对翻页URL进行处理
  If Instr(fFyUrl,".asp?")>0 Or Instr(fFyUrl,"?")=6 Then
   FUrl=fFyUrl&"&"
  Else
   FUrl=fFyUrl&"?"
  End If
 End Function
 
 Private Function ColNum()  '获得表格的列数,为了程序方便,实际表格的列数应该是ColNum+1
  If (fIfID And fIfOp) Then
   ColNum=Ubound(ColName)+2
  ElseIf ((Not fIfID) And (Not fIfOp)) Then
   ColNum=Ubound(ColName)
  Else
   ColNum=Ubound(ColName)+1
  End If
 End Function
 
 Private Sub ShowErr()  '错误处理,还等进一步完善
  dim r,s
  If fDBpath="" Or isnull(fDBPath) or isempty(fDBPath) then
   fErr=fErr&"<div >数据库路径未指定.<div>"
  end if
  If fSql="" Or IsNull(fSql) Or IsEmpty(fSql) Then
   fErr=fErr&"<div >数据库操作语句未指定.<div>"
  End If
  If fColNames="" Or IsNull(fColNames) Or IsEmpty(fColNames) Then
   fErr=fErr&"<div >未指定列名.<div>"
  End If
  If Ubound(ColWid)<>ColNum Then
   fErr=fErr&"<div >参数错误,列名与列宽对应的列数不对.<div>"
  End If
  If Ubound(ColName)<>Ubound(DBColName) Then
   fErr=fErr&"<div >参数错误,列名与数据库列名对应的列数不对.<div>" 
  End If
  If fIfOp Then
   If fOpNames="" Or IsNull(fOpNames) Or IsEmpty(fOpNames) Then
    fErr=fErr&"<div >肯定了有操作但未指定操作名称.<div>"
   End If   
   If fOpUrls="" Or IsNull(fOpUrls) Or IsEmpty(fOpUrls) Then
    fErr=fErr&"<div >肯定了有操作但未指定操作URL.<div>"
   End If
  End If
  If fFyUrl="" Or IsNull(fFyUrl) Or IsEmpty(fFyUrl) Then
   fErr=fErr&"<div >翻页的URL未指定.<div>"
  End If
  If fDBColNames="" Or IsNull(fDBColNames) Or IsEmpty(fDBColNames) Then
   fErr=fErr&"<div >数据库列名未指定.<div>"
  End If
  If fOrderByCol Then
   If Instr(Lcase(fSql),"order by")>0 Then
    fErr=fErr&"<div >确定可通过列名重新排序后,SQL语句中不可再含有ORDER BY子句.<div>"
   End If
  End If
  If Ubound(AColSNs)=0 then
   If Cint(AColSNs()(0))<>-1 And (cint(AColSNs()(0))<0 Or cint(AColSNs()(0))>Ubound(ColName)) then
    fErr=fErr&"<div >需要添加超链接的列的序号不正确.<div>"
   End if 
  Else
   for r=0 to Ubound(AColSNs)
    if Cint(AColSNs()(r))<0 or Cint(AColSNs()(r))>Ubound(ColName) then
     fErr=fErr&"<div >需要添加超链接的列的序号不正确.<div>"
     exit for
    End if
   next
  End if
  If Ubound(AddColSNs)=0 then
   If Cint(AddColSNs()(0))<>-1 And (cint(AddColSNs()(0))<0 Or cint(AddColSNs()(0))>ubound(ColName)) then
    fErr=fErr&"<div >需要添加附加属性的列的序号不正确.<div>"
   end if
  else
   for s=0 to ubound(AddColSNs)
    if cint(AddColSNs()(s))<0 or Cint(AddColSNs()(s))>Ubound(ColName) then
     fErr=fErr&"<div >需要添加附加属性的列的序号不正确.<div>"
     exit for
    end if
   next
  end if
  If Ubound(AColSNs)<>Ubound(AColUrl) Then
   fErr=fErr&"<div >需要添加超链接的列数与给出的URL数目不对."&ubound(acolsns)&ubound(acolurl)&"<div>"
  End If
 
  If fErr<>"" Then
   Response.Write fErr
   Response.End()
  End If  
 End Sub
 
 Private Sub Fanye_Initialize()   '生成之前的准备工作,如对错误参数的检测等,及一些变量的赋值
  ShowErr
  if fDefaultOrderBy="" or isnull(fDefaultOrderBy) or isempty(fDefaultOrderBy) then
   fDefaultOrderBy=DBColName()(0)
  end if
  If fOrderByCol Then 
   If request.QueryString("orderby")<>"" Then
    fSql=fSql&" ORDER BY "&request.QueryString("orderby")
   Else
    fSql=fSql&" ORDER BY "&fDefaultOrderBy
   End If
  End If
  fConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(fDBPath)
  fRs.PageSize = fN
  fRs.CursorLocation = 3
  fRs.Open fSql,fConn,0,2,1 
 End Sub
 
 Private Sub CreateTiTle()   '生成表头
  Dim i,j
  Response.Write "<tr id='fytitle'>"
  If fIfID Then
   Response.Write "<td width="&ColWid()(0)&">序号</td>"
  End If
  For i=0 To Ubound(ColName)
   If fIfID Then j=i+1 Else j=i
   If not fOrderByCol then
    Response.Write "<td width="&ColWid()(j)&">"&ColName()(i)&"</td>"
   Else
    Response.Write "<td width="&ColWid()(j)&"><a title='ORDER BY "&ColName()(i)&"' href='"&FUrl&"orderby="&Server.URLEncode(Getorderby(i))&"'>"&ColName()(i)&"</a></td>"
   End if
  Next
  If fIfOp Then
   Response.Write "<td width="&ColWid()(Ubound(ColWid))&">操作</td>"
  End If
  Response.Write "</tr>"  
 End Sub
 
 Private Sub CreateTbody(x)  '生成循环体
  Dim i,j,k,l,cpro
  Response.Write "<tr >"
  If fIfID Then
   Response.Write "<td >"&Cstr(x)&"</td>"
  End If
  For i=0 To Ubound(ColName)
   if Ubound(AddColSNs)=0 then
    if i=cint(AddColSNs()(0)) then
     cpro="<td "&AddColPros()(0)&">"
    else
     cpro="<td>"
    end if
   else
    for l=0 to ubound(AddColSNs)
     if i=cint(AddColSNs()(l)) then
      cpro="<td "&AddColPros()(l)&">"
      exit for
     end if
    next
   end if
   if Ubound(AColSNs)=0 then
    if i=Cint(AColSNs()(0)) then
     Response.Write cpro&"<a "&AColUrl()(i)&GetACQs(i)&">"&fRs(DBColName()(i))&"</a></td>"
    else
     Response.Write cpro&fRs(DBColName()(i))&"</td>"
    end if
   else
    for k=0 to Ubound(AColSNs)
     if i=Cint(AColSNs()(k)) then
      response.Write cpro&"<a "&AColUrl()(k)&GetACQs(k)&">"&fRs(DBColName()(i))&"</a></td>"
      exit for
     end if
    next
   end if
  Next
  If fIfOp Then
   Response.Write "<td >"
   For j=0 To Ubound(OpName)
    Response.Write " <a title="&Opname()(j)&" "&OpUrl()(j)&GetOpQs(j)&">"&OpName()(j)&"</a>"
   Next
   Response.Write "</td>"
  End If
  Response.Write "</tr>"
 End Sub
 
 Private Sub CreateBody()  '与循环体组成表的主体
  dim i
  page=Trim(Request("page"))
  If Not IsNumeric(page) Or len(page)=0 Then 
   intpage =1
   pre  =False
  Else
   If CInt(page)<=1 Then
    intpage =1
    pre  =False
   Else
    If CInt(page)>=fRs.PageCount Then
     intpage =fRs.PageCount
     last =False
    Else
     intpage =CInt(page)
    End If
   End If
  End If
  If Not fRs.EOF Then
      fRs.AbsolutePage = intpage
  End If
  i=1
  Do While Not fRs.EOF
   CreateTbody(i)
  fRs.MoveNext
  i=i+1
  Loop
 End Sub
 
 Private Sub CreateFooter()  '生成表脚
  Response.Write "<table id='fyfttab' cellspacing=0 cellpadding=0><tr>"
  If fRs.PageCount > 0 then
   Response.Write "<td>当前页 <font>"&intpage&"</font>/"&fRs.PageCount&"  共 <font>"&fRs.RecordCount&"</font> "&fRec&"  本页显示第 "&fRs.PageSize*(intpage-1)+1&"~"
   if intpage<fRs.pagecount then 
           num=fRs.pagesize*intpage 
         else 
          num=fRs.recordcount
         end if
   response.write num&" "&left(fRec,1)&"</td>"
        else
         response.write "<td>当前页0/0  共0"&fRec&"</td>"
        end if
        Response.Write "<td align='right'><a href="&FUrl&"page=1>首页</a> | "
        if pre then
            Response.Write "<a href="&FUrl&"page="&intpage -1&">上页</a> | "
        end if
        if last then
            Response.Write "<a href="&FUrl&"page="&intpage +1&">下页</a> | "
        end if
        Response.Write "<a href="&FUrl&"page="&fRs.PageCount&">尾页</a> | 转到第 <span><select onchange='javascript:location=this.options[this.selectedIndex].value;'>"
        for i = 1 to fRs.PageCount
   if i = intpage then
    Response.Write "<option value="&FUrl&"page="&i&" selected>"&i&"</option>"
   else
    Response.Write "<option value="&FUrl&"page="&i&">"&i&"</option>"
   end if
        next
        Response.Write "</select></span> 页 </td></tr></table>"
 End Sub
 
 Public Sub Create()   '最后生成翻页的表格
  Fanye_Initialize
  Response.Write "<table cellspacing=1 cellpadding=0 id='fy'>"
  CreateTitle
  CreateBody
  Response.Write "<tr id='fyfooter'><td colspan="&ColNum+1&">"
  CreateFooter
  Response.Write "</td></tr></table>"
 End Sub
 
End Class
%>
 
Test.asp
 
<!--#include file="fanye.asp"-->
<%
dim fy
set fy  =New Fanye
fy.DBPath ="db/s.mdb"
fy.Sql  ="select * from abc"
fy.ColNames ="id,abc"
fy.ColWidth =",,,"
fy.DBColNames="id,abc"
fy.IfID  =True
fy.IfOp  =True
fy.OrderByCol=True
fy.OpNames="VIEW,MODIFY,DELETE"
fy.OpUrls="href=view.asp,href=modify.asp,onclick=return(confirm('ensure?')) href=delete.asp"
fy.OpQueryString="id abc,id,abc"
fy.fyUrl ="test.asp"
fy.DefaultOrderBy="id"
fy.AColSN="1,0"
fy.AColUrls="href=asdfasdf.asp,href=?aaaaa=aaa.htm"
fy.AColQueryString="id abc,abc"
fy.AddColSN="1,0"
fy.AddColPro="onclick=""alert('asdf')"",bgcolor=black"
fy.Create
set fy=nothing
%>
 
最后是 fanye.css
 
.fyerr{color:#FF0000;font-weight:bold;font-size:12px;}
#fytitle{font-size:12px;font-weight:bold;text-align:center;background:#ffddaa;height:22px;}
#fy{width:100%;text-align:center;background:#feaaae;}
#fy a{color:#0099FF;text-decoration:none;}
#fy a:hover{color:#FF9900;text-decoration:underline;}
.fytr{font-size:12px;height:22px;background:#FFFFFF;alert:expression(onmouseover=function(){this.style.background='#ffeebb'},onmouseout=function(){this.style.background='#ffffff'})}
#fyfooter{background:#ffffFF;}
#fyfttab{width:100%;height:25px;}
#fyfttab td{font-size:12px;padding-left:10px;padding-right:10px;}
#fyfttab font{font-size:12px;color:#FF0000;}
#fyfttab select{width:47px;margin:-2px;font-size:12px;}
#fyfttab span{height:18px;width:45px;overflow:hidden;border:1px solid #ffcc99;}

其中css中还包括两个小点,一个是在css中使用JS,另一个是平面下拉框的实现.细心的应该早就看出来了吧,呵呵

,

昨天用FCKeditor做一个东西,碰到编码的问题,由于开始根本就没有发现问题的所在,头天也没有解决,后来经过仔细思考后终于解决

问题是这样的:
我在用asp写一个网站的后台管理,没有用FCKeditor的时候发现汉字的显示一切正常.但是当调用了FCKeditor后,发现汉字就显示不正常了. 但是当时并没有注意到并不所有的汉字的显示都有问题, 我的第一反应就是编码的问题,去网上搜了一下,说是FCKeditor所用的UTF-8编码和网页编码用的GB2312的编码问题,有人说都改成GBK,也有人说用函数进行转换一下,还有的说用记事本将汉字存为UTF-8格式,我只试了第一种方法,并不凑效,同时我觉得其他两种方法在原理上和第一种方法应该差不多,便没有再试下去.

后来经常观察发现,其实并不是所有的汉字显示都有问题,只是写在<% %>之间的汉字的显示才有问题
于是我马上意识到这其实并不是FCKeditor的编码的问题,问题应该出在ASP对汉字的编码上,再搜索发现ASP的CodePage是对汉字编码进行规定的,于是在页首加入<%@CodePage=936%>简体中文,问题就解决了

所以发现问题后不能盲目去找答案,这样并不能快速的解决问题,应该先找个问题所在,再针对找解决办法.

,
subject="审核通过!"  
 body="<B>XXXXXX公司欢迎您。</B> " _   
  &"<B>您的用户名:111,密码:111</B> " _   
  &"<B>如果您有什么需求请您与我们联系。</B> " _   
  &"<B>顺颂商祺!</B> " _   
  &" " _   
  &"电话:010-XXXXXXXX   /   传真:010-XXXXXXXX   /  手机:13XXXXXXXX " _   
  &"网址:www.xxx.com  /  邮箱:***@yahoo.com.cn"  
 
 
email="<A href="mailto:***@yahoo.com.cn">***@yahoo.com.cn</A>"  
Dim msg,SendMail   
Set msg = Server.Createobject("JMAIL.message")   
msg.silent = true   
msg.Logging = true   
msg.Charset = "gb2312"  
msg.MailServerUserName = "***"    &apos;输入smtp服务器验证登陆名 (邮局中任何一个用户的Email地址)   
msg.MailServerPassword = "******"    &apos;输入smtp服务器验证密码 (用户Email帐号对应的密码)   
msg.From = "<A href="mailto:***@yahoo.com.cn">***@yahoo.com.cn</A>"    &apos;发件人Email   
msg.FromName = "XXXX"     &apos;发件人姓名   
msg.AddRecipient "<A href="mailto:***@163.com">***@163.com</A>"   &apos;收件人Email   
msg.Subject = subject      &apos;信件主题   
&apos;msg.Body = "邮件正文"      &apos;正文   
msg.HTMLBody = body     &apos;HTML正文   
msg.ReturnReceipt=true   
msg.Send ("smtp."&right(email,instr(email,"@"))) &apos;smtp服务器地址(企业邮局地址)   
set msg = nothing   
if err then   
SendMail=err.description   
err.clear   
else   
SendMail="邮件发送成功!"  
end if   
Response.write SendMail