实体类

<%
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也玩三层架构(有源代码)的更多相关文章

  1. ASP.NET的三层架构(DAL,BLL,UI)

    ASP.NET的三层架构(DAL,BLL,UI) BLL   是业务逻辑层   Business   Logic   Layer DAL   是数据访问层   Data   Access   Laye ...

  2. Asp.Net MVC三层架构之autofac使用教程

    开发环境:vs2015..net4.5.2.mvc5.ef6 Autofac简介 IOC控制反转(Inversion of Control,缩写为IOC),Autofac是一个开源的依赖注入框架,Au ...

  3. Asp.Net之三层架构

    三层架构之理论: 通常意义上讲的三层架构就是将整个项目应用划分为:表现层(UI),业务逻辑层(BLL),数据访问层(DAL).与传统的二层架构的区别在于在用户界面(UI)和数据库服务器之间,添加中间层 ...

  4. asp.net中三层架构与mvc之区别?

    对于标题中的问题,如果是没有同时接触三层架构和mvc的初级.net开发人员,想必一定会非常糊涂和混淆.关于此我也百度过N回,看过N多帖子和 回答,但几乎没有人能表述清楚.近期我从典型mvc+entit ...

  5. ASP.NET创建三层架构图解详细教程

    1.新建项目 2.创建Visual Studio解决方案 3.再创建项目 4.选择类库类型 5.依次创建bll(业务逻辑层),dal(数据访问层)和model(模型层也可以叫实体层) 6.添加一个网站 ...

  6. asp.net 3.三层架构

    1.新建项目和类库 CZBK.ItcastProject (空白项目) CZBK.ItcastProject.BLL (类库) -- 逻辑业务 CZBK.ItcastProject.Common (类 ...

  7. ASP.NET三层架构的分析

    BLL   是业务逻辑层   Business   Logic   Layer DAL   是数据访问层   Data   Access   Layer ASP.NET的三层架构(DAL,BLL,UI ...

  8. MVC项目实践,在三层架构下实现SportsStore-02,DbSession层、BLL层

    SportsStore是<精通ASP.NET MVC3框架(第三版)>中演示的MVC项目,在该项目中涵盖了MVC的众多方面,包括:使用DI容器.URL优化.导航.分页.购物车.订单.产品管 ...

  9. ASP.Net MVC+EF架构

    ASP.Net MVC是UI层的框架,EF是数据访问的逻辑. 如果在Controller中using DbContext,把查询的结果的对象放到cshtml中显示,那么一旦在cshtml中访问关联属性 ...

随机推荐

  1. 属性(@property)的修饰词有哪些,各自是什么作用,在哪种情况下用?

       之前面试了几家公司,都会问到这个基础的问题,以前,没有怎么注意,所以答的很混乱,所以查了查网上的资料,特意整理了一份.   常见修饰词有:assign.weak.strong.retain.co ...

  2. 通用双向链表的设计(参考Linux系统中的实现)

    通常我们设计设计链表都是将数据域放在里面,这样每次需要使用链表的时候都需要实现一个链表,然后重新实现它的相关操作,这里参考Linux系统中的设计实现了一个通用的双向链表,只需要在你的结构里面有一个这个 ...

  3. Gulp简单应用

    1.创建一个工程,在webstorm控制台   cnpm install --save-dev gulp      cnpm install --save-dev gulp-concat        ...

  4. PHPstorm相同变量标识

    setting-> plugins-> Browse Repositories 输入BrowseWordAtCaret 搜索,安装,然后重启

  5. python在三引号中使用变量

  6. Cannot resolve symbol 'log'

    IntelliJ IDEA 写实体类时使用toString报错,报异常: 原因:缺少commons-lang3-3.8.1.jar包. 下载路径:http://commons.apache.org/p ...

  7. python使用xlrd操作Excel文件

    一.xlrd读取Excel文件 用xlrd进行读取比较方便,流程和平常手动操作Excel一样,打开工作簿(Workbook),选择工作表(sheets),然后操作单元格(cell). 例子:要打开当前 ...

  8. CPython里的GIL

    GIL不是Python特性,是CPython解释器特性,因为CPython有垃圾回收机制. GIL 本质是互斥锁,保护解释器安全. 保证线程安全,垃圾回收线程不会和其他线程一起运行. 多个线程不能实现 ...

  9. TypeScript完全解读(26课时)_20.声明文件

    首先学习识别已有的js库的类型 识别已有的js库的类型 UMD既可以作为全局库使用,也可以作为模块使用 先在着手来编写一个全局的库 新建文件 接收一个title,改变页面title的值 这里用到 &a ...

  10. UVa 11520 Fill the Square (水题,暴力)

    题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, ...