实体类

<%
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. Spring 事务管理高级应用难点剖析: 第 2 部分

    本文是“Spring 事务管理高级应用难点剖析” 系列文章的第 2 部分,作者将继续深入剖析在实际 Spring 事务管理应用中容易遇见的一些难点,包括混合使用多种数据访问技术(如 Spring JD ...

  2. vue render函数使用jsx语法 可以使用v-model语法 vuex实现数据持久化

    render函数使用jsx语法: 安装插件  transform-vue-jsx 可以使用v-model语法安装插件 jsx-v-model .babelrc文件配置: vuex实现数据持久化 安装插 ...

  3. CS231n 2016 通关 第五、六章 Fully-Connected Neural Nets 作业

    要求:实现任意层数的NN. 每一层结构包含: 1.前向传播和反向传播函数:2.每一层计算的相关数值 cell 1 依旧是显示的初始设置 # As usual, a bit of setup impor ...

  4. python -m json.tool 中文乱码 Format JSON with python

    现在以 json 为数据传输格式的 RESTful 接口非常流行.为调试这样的接口,一个常用的办法是使用 curl 命令: curl http://somehost.com/some-restful- ...

  5. DispatcherServlet详解

    1.1.DispatcherServlet作用 DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring Io ...

  6. TimeUtils(没试过)

    package util; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseExc ...

  7. 2、webpack基础配置

    我们需要安装webpack 还需要安装webpack cli 这两个都是我们的开发依赖 这里我们一般会加一个-D表示上线的时候不需要他们两个包 安装我们的webpack 先初始化一下,记住我们的安装依 ...

  8. [CVE-2014-3704]Drupal 7.31 SQL注入漏洞分析与复现

    记录下自己的复现思路 漏洞影响: Drupal 7.31 Drupal是一个开源内容管理平台,为数百万个网站和应用程序提供支持. 0x01漏洞复现 复现环境: 1) Apache2.4 2) Php ...

  9. Winform禁止程序多开 &&禁止多开且第二次激活第一次窗口

    一.禁止多开问题,运用Mutex锁 在Program.cs中运用Mutex锁 bool createNew;using (System.Threading.Mutex mutex = new Syst ...

  10. 利用ant 和 Junit 生成测试报告

    我们除了使用java来直接运行junit之外,我们还可以使用junit提供的junit task与ant结合来运行. 涉及的几个主要的ant task如下: <junit>,定义一个jun ...