MVC构架实现之ASP

王朝网络·asp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

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

%>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有