asp也玩三层架构(有源代码)
实体类
<%
Class UserInfo
Private mintId
Public Property Let UserId(intUserId)
mintId = intUserId
End Property
Public Property Get UserId()
UserId=mintId
End Property
Private mstrName
Public Property Let UserName(strName)
mstrName = strName
End Property Public Property Get UserName()
UserName = mstrName
End Property Private mintAge
Public Property Let UserAge(intAge)
mintAge=intAge
End Property
Public Property Get UserAge()
UserAge = mintAge
End Property
End Class
%>
数据访问层类
<!--#include file="Model.asp"-->
<!--#include file="DBHelper.asp"-->
<%
Class UserDAL Public Sub InsertUser(objUserInfo)
strInsertSql="insert into Users (UserName,UserAge) values ('" &objUserInfo.UserName &_
"',"& objUserInfo.UserAge &")"
DB.ExecuteNonQuery(strInsertSql)
End Sub Public Sub DeleteUser(intUserId)
strDeleteSql="delete from Users where UserId="& intUserId
DB.ExecuteNonQuery(strDeleteSql)
End Sub Public Sub UpdateUser(objUserInfo)
strUpdateSql="update Users set UserName='"& objUserInfo.UserName &"',UserAge="& objUserInfo.UserAge &_
" where UserId="& objUserInfo.UserId
DB.ExecuteNonQuery(strUpdateSql)
End Sub Public Function GetAllUser()
strSelectSql="select * from Users"
Set rs=DB.ExecuteQuery(strSelectSql)
Set dic=Server.CreateObject("Scripting.Dictionary")
While not rs.eof
Set user=CreateUser(rs)
dic.Add user.UserId,user
rs.MoveNext
wend
rs.Close
Set rs=nothing
Set GetAllUser=dic
End Function
Public Function GetUserById(intUserId)
strSelectSql="select * from Users where UserId="&intUserId
Set rs=DB.ExecuteQuery(strSelectSql)
Set user=CreateUser(rs)
rs.Close
Set rs=nothing
Set GetUserById=user End Function Private Function CreateUser(rs)
Set user=new UserInfo
user.UserId=rs("UserId")
user.UserName=rs("UserName")
user.UserAge=rs("UserAge")
Set CreateUser=user
End Function End Class Set UserDao=new UserDAL
%>
用到的DBHelper类
<%
Class DBHelper
Private conn
Private Sub Class_Initialize
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("DB.mdb")
Set conn=Server.CreateObject("ADODB.Connection" )
conn.Open(strConn)
End Sub
Private Sub Class_Terminate
conn.Close()
Set conn=nothing
End Sub
Public Function ExecuteQuery(strSql)
Set rs=Server.CreateObject("ADODB.RecordSet")
rs.Open strSql,conn,1,1
Set ExecuteQuery=rs
End Function
Public Sub ExecuteNonQuery(strSql)
conn.Execute(strSql)
End Sub
End Class
Set DB=new DBHelper
%>
业务层类
<!--#include file="DAL.asp"-->
<%
Class UserBLL
Public Function InsertUser(objUserInfo)
If not IsNumeric(objUserInfo.UserAge) Then
InsertUser="年龄必需是数字!"
Else
UserDao.InsertUser(objUserInfo)
InsertUser="添加用户成功!"
End If
End Function
Public Function DeleteUser(intUserId)
If IsNumeric(intUserId) Then
UserDao.DeleteUser(intUserId)
DeleteUser="删除用户成功!"
End If
End Function
Public Function UpdateUser(objUserInfo)
If not IsNumeric(objUserInfo.UserAge) Then
UpdateUser="年龄必需是数字!"
Else
UserDao.UpdateUser(objUserInfo)
UpdateUser="更新用户成功!"
End If
End Function
Public Function GetAllUser()
Set GetAllUser=UserDao.GetAllUser()
End Function
Public Function GetUserById(intUserId)
Set GetUserById=UserDao.GetUserById(intUserId)
End Function
End Class
Set UserManager=new UserBLL
%>
下面是表示层代码
显示所有User
<!--#include file="BLL.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head> <body> <form id="form1" name="form1" method="post" action="DoInsertUser.asp"> <label>姓名:
<input type="text" name="Name" />
年龄:
<input type="text" name="Age" />
<input type="submit" name="Submit" value="添加" />
</label>
<table width="361" border="1">
<tr>
<td width="56">UserId</td>
<td width="74">UserName</td>
<td width="65">UserAge</td>
<td width="73"> </td>
<td width="59"> </td>
</tr>
<%Set users=UserManager.GetAllUser()
For Each user in users.Items
%>
<tr>
<td><%=user.UserId%></td>
<td><%=user.UserName%></td>
<td><%=user.UserAge%></td>
<td><a href="EditUser.asp?UserId=<%=user.UserId%>">编辑</a></td>
<td><a href="DoDeleteUser.asp?UserId=<%=user.UserId%>">删除</a></td>
</tr>
<%
Next
%> </table>
</form>
</body>
</html>
asp也玩三层架构(有源代码)的更多相关文章
- ASP.NET的三层架构(DAL,BLL,UI)
ASP.NET的三层架构(DAL,BLL,UI) BLL 是业务逻辑层 Business Logic Layer DAL 是数据访问层 Data Access Laye ...
- Asp.Net MVC三层架构之autofac使用教程
开发环境:vs2015..net4.5.2.mvc5.ef6 Autofac简介 IOC控制反转(Inversion of Control,缩写为IOC),Autofac是一个开源的依赖注入框架,Au ...
- Asp.Net之三层架构
三层架构之理论: 通常意义上讲的三层架构就是将整个项目应用划分为:表现层(UI),业务逻辑层(BLL),数据访问层(DAL).与传统的二层架构的区别在于在用户界面(UI)和数据库服务器之间,添加中间层 ...
- asp.net中三层架构与mvc之区别?
对于标题中的问题,如果是没有同时接触三层架构和mvc的初级.net开发人员,想必一定会非常糊涂和混淆.关于此我也百度过N回,看过N多帖子和 回答,但几乎没有人能表述清楚.近期我从典型mvc+entit ...
- ASP.NET创建三层架构图解详细教程
1.新建项目 2.创建Visual Studio解决方案 3.再创建项目 4.选择类库类型 5.依次创建bll(业务逻辑层),dal(数据访问层)和model(模型层也可以叫实体层) 6.添加一个网站 ...
- asp.net 3.三层架构
1.新建项目和类库 CZBK.ItcastProject (空白项目) CZBK.ItcastProject.BLL (类库) -- 逻辑业务 CZBK.ItcastProject.Common (类 ...
- ASP.NET三层架构的分析
BLL 是业务逻辑层 Business Logic Layer DAL 是数据访问层 Data Access Layer ASP.NET的三层架构(DAL,BLL,UI ...
- MVC项目实践,在三层架构下实现SportsStore-02,DbSession层、BLL层
SportsStore是<精通ASP.NET MVC3框架(第三版)>中演示的MVC项目,在该项目中涵盖了MVC的众多方面,包括:使用DI容器.URL优化.导航.分页.购物车.订单.产品管 ...
- ASP.Net MVC+EF架构
ASP.Net MVC是UI层的框架,EF是数据访问的逻辑. 如果在Controller中using DbContext,把查询的结果的对象放到cshtml中显示,那么一旦在cshtml中访问关联属性 ...
随机推荐
- python中通过xlwt、xlrd和xlutils操作xls
xlwt模块用于在内存中生成一个xls/xlsx对象,增加表格数据,并把内存中的xls对象保存为本地磁盘xls文件; xlrd模块用于把本地xls文件加载到内存中,可以读取xls文件的表格数据,查询x ...
- Linux下启动mongodb
完成安装mongodb(略) 创建数据目录: # mkdir /data/mongo 创建配置文件 # vi /data/mongo/mongodb.cnf dbpath=/data/mongo/ l ...
- windbg调试堆破坏
堆破坏 所谓的堆破坏,是说没控制好自己的指针,把不属于你分配的那块内存给写覆盖了.这块内存可能是你程序的数据,也可能是堆的管理结构.那么这个会导致怎样的后果呢?可能的情况我们来yy下 把程序里的计算结 ...
- visualstudio2017 +EF+Mysql生成实体数据模型闪退
VisualStudio2017+EF+MySql正常运转,费了不少劲,踏过不少坑 1.安装 Connector/NET 8.0.13 地址:https://dev.mysql.com/downloa ...
- http://blog.sina.com.cn/s/blog_6145ed810102vr8k.html
http://blog.sina.com.cn/s/blog_6145ed810102vr8k.html
- .Net框架中的CLR,CTS,ClS的解释
CLR的全称(Common Language Runtime) 公共语言运行时 可以把它理解为包含运行.Net程序的引擎 和 一堆符合公用语言基础(CLI)的类库的集合,他是一个规范的实现,我们开发的 ...
- vim opencv
http://blog.csdn.net/fdl19881/article/details/7275203 ctags .vim: http://www.vim.org/scripts/script. ...
- 20个Flutter实例视频教程-第03节: 不规则底部工具栏制作-1
第03节: 不规则底部工具栏制作-1 博客地址: https://jspang.com/post/flutterDemo.html#toc-973 视频地址: https://www.bilibili ...
- Subresource Integrity(子资源一致性)和JS DDos 攻击
以下文章转载自 http://www.cnblogs.com/zoucaitou/p/4505483.html 和 http://www.puronglong.com/blog//2015/04/12 ...
- ubuntu 安装 lamp 和配置虚拟机
1:sudo passwd root #设定root密码 su 切换 exit 退出 ,或者 普通用户下 加sudo 2:sudo apt-get update #更新软件列表 3:sudo ...