Code代码片断(5do8)

FSO正则ADO内置对象基础语法

新主题
远程桌面 Web 连接
[ASP]使用类,实现模块化(...
ISAPI Rewrite 实例
清除字符串中的html代码
说话自由

首页 » ASP » 基础语法 »

[ASP]使用类,实现模块化(源码) [blueidea.com]

标签: asp class OO
[ASP]使用类,实现模块化(源码) [blueidea.com]

控制读取数据库信息的类:
参考源码:

 
'名称:ado_5do8
'作用:读取数据库的各项操作
'来源-耕耘村http://www.5do8.com http://www.Blueidea.com-5do8
'创作:5do8
'联系:5do8@5do8.com
'更新:2005年11月13日
'授权:蓝色理想网站积分超过3000,耕耘村所有注册用户
'类的接口:ado_5do8.ConnectString=数据库绝对路径
  'ado_5do8.rs_top 调用数目,表的名称
Class ado_5do8
 Private conn,sqlstr,rs,iid,itable,isession
   'sqlstr:数据库地址,为绝对路径,私有
   'conn:打开数据库的连接,私有
'------------------------------------------------------------------
rem 消除一些不想要的数字 
Private Function litter_in(r1,r2)
If IsNumeric(r1) and IsNumeric(r2) Then
 Dim dimrr
 If r1>r2 Then
 dimrr=r2
 Else
 dimrr=r1
 End If
 Else
 dimrr=0
 End if
 litter_in=dimrr
 End Function
'-----------------------------------------------------------------
Private Function killint(i,killstr,killsub)
  If Not IsNumeric(i) Then
  i=killstr
  ElseIf i<=0 Then
  i=killsub
  End if
  killint=Int(Left(i,5))
  End Function
'-----------------------------------------------------------
private Sub startconn()
   On Error Resume Next
    Set conn=server.CreateObject("adodb.connection")
   strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sqlstr)
   conn.open strconn
   If Err Then
   err.Clear
   Set Conn = Nothing
   mess="发生错误,不能连接数据库"
   response.write(mess)
   response.End
   Else
   mess="连接数据库conn成功...........<br/>"
   response.write(mess)
   End If
   End Sub
'----------------------------------------------------------------
private Sub closeconn()
   conn.close
   Set conn=Nothing
   response.write("<strong style='color:red'>关闭conn连接</strong>...<hr/>")
  End sub
'-----------------------------------------------------------------
Private Sub closers()
  rs.close
  Set rs=Nothing
  response.write("<strong style='color:#085420'>关闭数据库RS</strong>.......<br/>")
  End Sub
'-----------------------------------------------------------------
Property Get havese
  havese=isession
  End Property
 
Property Let havese(yoursession)
  isession=yoursession
  If yoursession="" Then
  isession="nodef"
  End If
  End Property
 
'-----------------------------------------------------------------
Public Function makesession(arraydata)
   If IsArray(arraydata) then
   makear=arraydata
   Else
   makear=Array(0,0,0,0)
   End If
   If isession="" Then
   isession="nodef"
   End if
   session(isession)=makear
   End Function
'-----------------------------------------------------------------
private Function getsession()
  thisget=session(isession)
  If Not IsArray(thisget) Then
  thisget=Array(0,0,0,0)
  End If
  Getsession=thisget
  End function
'-----------------------------------------------------------------
Property Get ConnectString
ConnectString = sqlstr
End Property
Property Let ConnectString(str)
sqlstr = str
End Property
'-----------------------------------------------------------------
Property Get getid
getid = iid
End Property
Property Let getid(id)
iid = id
End Property
'-----------------------------------------------------------------
Property Get gettable
gettable = itable
End Property
Property Let gettable(table)
itable = table
End Property
'-----------------------------------------------------------------
'------------------------------------------------------------------
public Function readarraysession(iStart,ipageno,irowid)
  rowid=killint(irowid,0,0)
  start=killint(istart,0,0)
  pageno=killint(ipageno,5,5)
   data=getsession
  iRows = UBound(data, 2)
  iCols = UBound(data, 1)
  response.write("<h5>总数获得了:")
  response.write("<b> "&iRows+1&"</b>条信息</h5><hr/><ul style='width:100%;'>")
  If rowid = 0 then
  If iRows > (ipageno + iStart) Then
  iStop = ipageno + iStart - 1
  Else
  iStop = iRows
  End If
  For iRowLoop = Start to iStop
  Response.Write ("<li style='padding:4px 0;'><a href=?k=read&rowid="&irowloop+1&">"&data(1, iRowLoop) & " </a><span style='padding:4px 0 4px 10px;background-color:#ccc; '>较慢,不推荐点击--><a href=?k=list&id="&data(0,irowloop)&">更新</a>< /span></li>")
  Next
  Response.Write "</ul><div style='top:20px;background-color:#ccc;color:#020;font-weight:bold;bordr-top:2px solid #008;padding:10px 0;color:#b00'>列表(<a href=default.asp>回到典型模式</a>):"
  if Start > 0 then
   Response.Write "<A HREF=""?k=read&Start=" & iStart-ipageno &"&pageno=" & ipageno & """>Previous</A>"
  end if
  if iStop < iRows then
  Response.Write " <A HREF=""?k=read&Start=" & iStart+ipageno &"&pageno=" & ipageno & """>Next</A>"
  end If
 
  response.write"</div>"
  Else
  rowid=litter_in(rowid-1,iRows)
  response.write("<div style='width:85%'><h4 style='text-align:center'><a href=?k=read&pageno="&pageno&"&start="&start&"& gt;返回列表</a></h4></h2><hr /><h5>"&server.htmlencode(data(1,rowid))&"</h5><p>"&server.htmlencode(data(2,rowid))&"<h5>+-----"&server.htmlencode(data(3,rowid))&"")
  response.write("<div >")
  End if
  End Function
 
'-----------------------------------------------------------------
Public Function list_ids()
  sql3="select * from "&itable&" where id="&iid&" "
  startconn()
  Set rs=conn.execute(sql3)
  If rs.eof And rs.bof Then
  data=Array(0,0,0,0)
  Else
  data=Rs.GetRows()
  End If
  closers
  closeconn
   response.write(UBound(data)&":")
  response.write(server.htmlencode(data(2,0)))
  End function
'-----------------------------------------------------------------
Public Function rs_top(num,table,whe)
  startconn()
  sql="select top "&num&" * from "&table&""
  sql2="select count(*) as szd_count from "&table&" "" "&whe&""
  Set rs=conn.execute(sql2)
  szd_count=rs("szd_count")
  closers
   Set rs = Conn.Execute(sql)
   dim data
  If Rs.Eof Then
  data="no data"
  Else
  data=Rs.GetRows()
  End if
  closers
  closeconn()
  Call makesession (data)
    End Function
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End Class
使用的时候:
Dim action
 action=request("k")
 If action="view"  Then
 Call viewnew
 ElseIf action="list" Then
 Call list()
  ElseIf action="read" Then
 Call read()
 Else
 Call ff()
 End if
  Sub ff()
%>
<form style="border-top:2px solid #008;border-bottom:2px solid #008;margin:auto;background-color:#eee;padding:20px 5px;color:#008;font-weight:bold;">
   <label>显示信息总数:<input name="n" type="text" maxlength="4" size="10" />每页数目:<input name="pagesize" type="text" maxlength="4" size="10" value="5"/><input name="arrstart" type="hidden" value="0"></label>
   <h5 style="border-top:1px solid #000;padding:5px 0"> 操作:<input name="k" type="submit" value="view" /></h5>
</form> <%End sub%>
  <%Sub viewnew()
  f_num=killint(request("n"),1,1)
   pagesize=killint(request("pageno"),5,5)
  arrstart=killint(request("start"),0,0)
  rowid=killint(request("rowid"),0,0)
 Set cs=new ado_5do8
 cs.ConnectString="data/a.mdb"
 cs.havese="shi"
   cs.rs_top f_num,"site_szd",""
 cs.readarraysession  arrstart,pagesize,rowid
      End sub
  Sub list()
  response.write("<h5><a href=default.asp>返回默认模式</a></h5>")
     response.write"下面显示具体信息:<hr/>"
    id=request("id")
    id=killint(id,1,1)
    Set listid=new ado_5do8
    listid.ConnectString="data/a.mdb"
     listid.getid=id
    listid.gettable="site_szd"
    listid.list_ids()
 End Sub
Sub read()
  response.write"<div style='background-color:#ccc;padding:20px 0;color:080;font-weight:bold;border-bottom:2px solid #008'>页面分析完毕,要更新请选择<a href=default.asp>回到典型模式</a>参数:Start,开始元素;pageno,每页条数</div& gt;"
   pagesize=killint(request("pageno"),5,5)
  arrstart=killint(request("start"),0,0)
  rowid=killint(request("rowid"),0,0)
  Set cs=new ado_5do8
  cs.havese="shi"
  cs.readarraysession  arrstart,pagesize,rowid
End sub
Function killint(i,killstr,killsub)
  If Not IsNumeric(i) Then
  i=killstr
  ElseIf i<=0 Then
  i=killsub
  End if
  killint=Int(Left(i,5))
  End Function
%>

more123写于2008-7-12 11:53:39

如果愿意,请留下你观点或者感受...
称呼*
内容*
验证码*