MVC构架实现之ASP

类别:Asp 点击:0 评论:0 推荐:

D.ASP
<%
class DataAccess

 private p_dbname
 private p_conn
 private p_rs
 
 public property let dbname(o_dbname)
  p_dbname=o_dbname
 end Property
 
 public property get dbname
  dbname=p_dbname
 end Property
 
 private sub class_initialize
  set p_conn=server.CreateObject("adodb.connection")
  set p_rs=server.CreateObject("adodb.recordset")
 end sub
 
 private sub class_terminate
  
 end sub
 
 public sub opendb()  
  p_conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath(p_dbname)
 end sub
 
 public function getrows(o_sql,o_recordnum,o_recordstart,o_recordfields)
  p_rs.open o_sql,p_conn,1,1
  p_rs.move o_recordstart
  getrows=p_rs.getrows(o_recordnum,0,o_recordfields)
  p_rs.close
 end function

end class
%>
M.ASP
<%
class UserModel

 private p_da
 
 private sub class_initialize   
  set p_da=new DataAccess
  p_da.dbname="ip.mdb"
  p_da.opendb()
 end sub
 
 private sub class_terminate  
  set p_da=nothing
 end sub
 
 public function getusersrows()
  getusersrows=p_da.getrows("select * from ip",-1,1,array("onip","offip"))
 end function
 
 public function getuserrow(user_id)
  getuserrow=p_da.getrows("select * from ip where id="&user_id,-1,0,array("onip","offip"))
 end function

end class
%>
v.asp
<%
class UserView

 private p_model
 private p_rows
  
 private sub class_initialize 
  set p_model=new UserModel 
 end sub
 
 private sub class_terminate 
  set p_model=nothing 
 end sub
 
 public sub showusers()
  p_rows=p_model.getusersrows()
  for i=0 to ubound(p_rows,2)
   response.write p_rows(0,i)&" "&p_rows(1,i)&"<br>"
  next
 end sub
 
 public sub showuser(user_id)
  p_rows=p_model.getuserrow(user_id)
  response.write p_rows(0,i)&" "&p_rows(1,i)&"<br>"
 end sub

end class
%>
index.asp
<!--#include file="D.ASP"-->
<!--#include file="M.ASP"-->
<!--#include file="V.ASP"-->
<%
set user=new UserView
user.showusers()
%>

本文地址:http://com.8s8s.com/it/it7824.htm