您可以在这里快速查找:


 
您的位置: 编程学习 > asp编程 > 200601
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

MVC构架实现之ASP

byebye8742

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()
%>