实体类

<%
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. DAG上的DP

    引例:NYOJ16 矩形嵌套 时间限制:3000 ms  |           内存限制:65535 KB 难度:4   描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可 ...

  2. 探究c++默认初始化

    按照c++ primer 5th第40页的描述,如果定义变量时没有指定初值,则变量被默认初始化,此时变量被赋予了“默认值”. 根据变量定义的位置,分为两种情况: 1.定义于任何函数体之外的变量被初始化 ...

  3. 评判云服务靠谱程度 -- Coding 安全那些事

    本文依据孙宇聪在 SegmentFault D-Day 北京场的演讲内容整理,并授权首发于“高效运维”公众号.10月11日,SegmentFault 将在上海举办D-Day,围绕 Docker 主题. ...

  4. UVaLive 3983 Robotruck (DP + 单调队列)

    题意:有n个垃圾,第i个垃圾坐标为(xi,yi),重量为wi,有一个机器人,要按照编号从小到大的顺序剑气所有的垃圾兵扔进垃圾桶,垃圾桶在原点, 每次总重量不能超过C,两点间距离为曼哈顿距离,求出最短的 ...

  5. yzm10铺瓷砖 一只小蜜蜂 ycb与取款机

    yzm10铺瓷砖 一天yzm10接到任务,要求用2×1大小的瓷砖,来铺2×4的地面,地面需要恰好被铺满.这对yzm10来说太容易了,于是他马上设计出了5种不同的铺法(旋转情况算不同种,如图示2.4). ...

  6. Uncaught TypeError: window.showModalDialog is not a function 谷歌

    //新版本谷歌没有window.showModalDialog,创建一个window.openif(window.showModalDialog == undefined){ window.showM ...

  7. 使用you-get下载网页小视频(实际上你可以下载任意你想要的web网页中的内容)

    1. 什么是you-get? You-Get是一个小型的命令行实用程序,用于从Web下载媒体内容(视频,音频,图像),如果没有其他方便的方法可以尝试使用you-get. 2.安装you-get 打开命 ...

  8. ajaxForm上传文件到本地服务器(封装)

    不啰嗦,直接看代码 1.html: <div class="con-item fix"> <span class="f">文章封面< ...

  9. poj3276 Face The Right Way

    Face The Right Way POJ - 3276 题目大意: n头牛排成一列,每头牛向前或向后,为了让所有牛都面向前方,设定一个k值,每操作一次恰好使k头连续的牛转向,求最少的操作次数m和对 ...

  10. webpack 中导入 vue 和普通网页使用 vue 的区别(四)

    一:在普通网页中使用 vue 使用 script 标签,引入 vue 包 在 ndex 页面中,创建一个 id 为 App 的 div 容器 通过 new Vue 得到一个 vue 实例 二:在 we ...