实体类

<%
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. 【CQ18高一暑假前挑战赛4】标程

    [二分或者STL] 二分: #include<bits/stdc++.h> using namespace std; ; int a[maxn]; int main() { ,pos; s ...

  2. [CTSC 2018] 混合果汁

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5343 [算法] 对于每组询问 , 首先二分答案 显然 , 最优策略为优先选择价格低的 ...

  3. bzoj 4712 洪水 —— 动态DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4712 设 f[x] = min(∑f[u] , a[x]),ls = ∑f[lson] 矩阵 ...

  4. moco实例

    一.moco模拟接口响应json moco的下载地址见虫师博客园:https://www.cnblogs.com/fnng/p/7511539.html foo.json文件内容如下 [ { &quo ...

  5. 杂项:UI

    ylbtech-杂项:UI 1.返回顶部 1. UI即User Interface(用户界面)的简称.泛指用户的操作界面,包含移动APP,网页,智能穿戴设备等.UI设计主要指界面的样式,美观程度.而使 ...

  6. SSIS 事务

    本文摘自:http://www.cnblogs.com/tylerdonet/archive/2011/09/23/2186579.html 在这一个随笔中将介绍在package中如何使用事务来保证数 ...

  7. Coding WebIDE 开放支持第三方 Git 仓库

    为了给开发者提供更多便捷的开发方式,Coding.net 现正式宣布 WebIDE 开放啦 ! 用户可以自由选择各大代码托管平台,推送代码到其它家代码仓库啦,同时新版的 WebIDE 还有如下特性: ...

  8. spark学习之简介

    1.   Spark概述 1.1.  什么是Spark(官网:http://spark.apache.org) Spark是一种快速.通用.可扩展的大数据分析引擎,2009年诞生于加州大学伯克利分校A ...

  9. python 内置函数的补充 isinstance,issubclass, hasattr ,getattr, setattr, delattr,str,del 用法,以及元类

    isinstance   是 python中的内置函数 , isinstance()用来判断一个函数是不是一个类型 issubclass  是python 中的内置函数,  用来一个类A是不是另外一个 ...

  10. git 的安装使用以及协作流程

    git安装: sudo apt-get install git-core git使用: 转:https://www.liaoxuefeng.com/wiki/0013739516305929606dd ...