易截截图软件、单文件、免安装、纯绿色、仅160KB

俩函数搞定asp的orm映射[原创]

俩函数搞定asp的orm映射
orm必须用到实体类,像C#这样的语言 写实体类挺痛苦的,除非用工具
而asp有个好处,因为他可以动态构建一个字符串并把此字符串动态解析为代码,也就是他的 execute 和 ExecuteGlobal 俩函数
下面这个函数是  实体类生成器 只要传入列名字符串就能生成 一个全局可用的类
'定义一个实体类
'clsname 自定义类名
'cols 列字符串逗号分隔
sub clsnew(clsname,cols)
dim p
p = "class "&clsname&" :public "&cols&":public cols:sub class_initialize():cols="""&cols&""":end sub:sub fill(a,rownum):dim b,i:b = split(cols,"",""):for i=0 to ubound(b):execute b(i)&""=""&a(i,rownum):next:end sub: end class"
'一个动态的类 通过传入逗号分隔的列名字符串 来定义类内部的变量属性
'实体类内部带有一个填充自己的方法,用结果集的二维数组来填充
ExecuteGlobal p
'全局执行完 以后 本页面到处可用此类了
end sub
'二维数组表转化为实体类数组
'clsname 类名
'a 记录集的二维数组
function orm(clsname,a)
dim r(),i,o
redim r(ubound(a,2))
for i=0 to ubound(a,2)
execute "set o = new "&clsname
o.fill a,i
set r(i)=o
next
orm = r
end function
'使用实例
sub testorm
dim cols,clsname
cols = "id,bookid,type1"
clsname = "booktype"
dim a,b,i
conn_open
getrsa "select top 20 id,bookid,type type1 from book_type",a
'getrsa是执行sql并取得结果数组的函数
'a是通过rs.getrows获得的二维数组
conn_close
clsnew clsname,cols
b = orm(clsname,a)
for i=0 to ubound(b)
echo b(i).id&" "&b(i).bookid&" "&b(i).type1&"<br/>"
'这里我们就达到了目的 再也不用写rs("id")这样的了 用点代替了括号和双引号
next
end sub
'附 执行sql的函数
sub getrsa(sql,a)
dim rs
set rs = conn.execute(sql)
if not rs.eof then
a = rs.getrows()
else
a = ""
end if
set rs = nothing
end sub


相关文档:

用ASP发送邮件


'creat by qqlxinye@tom.com
'time 2008-09-19
'qq:273453129
'web www.qqlxinye.cn
dim outSmtp,outUser,outPsd,recUser,recSubmit,bodyContent,AddAttachment,ifsend
function init_mail(str1,str2,str3,str4,str5,str6,str7)
  outSmtp=str1
  outUser=str2
  outPsd=str3
  recUser=str ......

asp静态生成,伪静态

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- #include file="../configinc/conndb.asp"-->
<!--#include file="../configi ......

asp数据库连接代码

conndb.asp
<%
Session.CodePage=65001
response.Charset="utf-8"
%>
<%
'数据库连接文件
dim conn
dim connstr
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath("../date/#heihuhuhuajian.mdb")+";Jet OLEDB:Database Pass ......

在asp验证码中head.fix和body.fix

fix是bmp的一种衍生格式,可用于asp生成验证码图形。
一个例子:
1 图象绘制完成后,将文件存为24位位图格式的BMP图象文件。
2 去除前54Byte内容.
3 改名为BODY+数字.FIX
4 修改CHECKCODE.ASP,调用你新做的这个文件.
(checkcode.asp 负责生成和输出验证码 1309 byte,head.fix 是54byte的BMP头,body.fix 数字0~9 10 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号