'**************************************************************
' 类名:C@objectname
' Memo:
'
' Write: www.yuanyue.cn / tom @date @time
'***************************************************************
class C@objectname
{public @fieldname '@fieldmemo}
end class
'获取列表数组
'conn 数据库连接
'site 站点
'return C@objectname对象的数组
'备注: 如果没有数据,对返回值执行typeof运算的结果就不是array
public function read@objectnameList(conn,site)
dim result
dim rs : set rs = server.CreateObject("adodb.recordset")
rs.open "select * from @objectname where Site='" & replace(site,"'","''") & "'",conn,1,3
if not rs.eof then
redim result(rs.recordcount-1)
dim i
do while not rs.eof
dim item : set item = new C@objectname
{item.@fieldname = rs("@fieldname")}
set result(i) = item
i = i + 1
rs.movenext
loop
end if
rs.close
set rs = nothing
read@objectnameList = result
end function
'读取对象
public Function read@objectname(conn,id)
dim result
dim rs : set rs = server.CreateObject("adodb.recordset")
rs.open "select * from @objectname where id=" & id,conn,1,3
if not rs.eof then
set result= new C@objectname
{result.@fieldname = rs("@fieldname")}
end if
rs.close
set rs = nothing
set read@objectname= result
end function
'显示下拉列表
'conn 数据库连接
'site 站点
'selected 选中的内容
'注: 输出形如: <option value=id>text</option>
public sub show@objectnameOptions(conn,site,selected)
dim list : list = read@objectnameList(conn,site)
if isarray(list) then
dim i
dim item
if len(selected) > 0 then
dim find : find = false
for i = 0 to ubound(list)
set item = list (i)
if (not find) and trim(item.id) = selected then
find = true
response.Write "<option value='" & item.id & "' selected>" & item.name & "</option>"
else
response.Write "<option value='" & item.id & "'>" & item.name & "</option>"
end if
next
else
for i = 0 to ubound(list)
set item = list(i)
response.Write "<option value=" & item.id & ">" & item.name & "</option>"
next
end if
end if
end sub
'新增对象
public sub Create@objectname(conn,object)
dim rs : set rs = server.CreateObject("adodb.recordset")
rs.open "select * from @objectname where 1=0",conn,1,3
rs.addnew
call init@objectnameRecord(object, rs)
rs.update
'object.ID = rs("ID") '取得自动编号
rs.close
set rs = nothing
end sub
'修改对象
public sub Update@objectname(conn,object)
dim rs : set rs = server.CreateObject("adodb.recordset")
rs.open "select * from @objectname where ID=" & object.ID,conn,1,3
call init@objectnameRecord(object, rs)
rs.update
rs.close
set rs = nothing
end sub
'删除对象
'conn 数据库连接
'idArray 编号数组
public sub Delete@objectname(conn,idArray)
dim idstr : idstr = ""
if not isArray(idarray) then exit sub
idstr = join(idArray,",")
dim sql : sql = "delete from @objectname where ID in(" & idstr & ")"
conn.execute sql
end sub
'把对象的内容填充到记录集中去
public sub init@objectnameRecord(object,rs)
{ rs("@fieldname") = object.@fieldname }
end sub
'把记录集的内容填充到对象中去
public sub init@objectnameObject(object,rs)
{object.@fieldname = rs("@fieldname")}
end sub
'从request.form初始化对象
public sub init@objectnameFromRequest(object)
{object.@fieldname = request.form("@fieldname")}
end sub