ASP中设计和使用类2
<%
class ClassList
private CurrentClassID
private CurrentTableName
private ParentClassID
private CurrentClassName
public property let ClassID(str)
CurrentClassID = str
end property
public property let ClassTable(str)
CurrentTableName = str
end property
public property let ParentID(str)
ParentClassID = str
end property
public property let ClassName(str)
CurrentClassName = str
end property
dim list()
dim i,n
Private Sub Class_Initialize()'初始化变量
i=0
n=0
End Sub
'如果存在此类别ID,则查询次类别ID对应的所有子类别ID
public function ClassArray(thisid,pid)'取得下级ID
'如果存在数据,则递归调用子类CLassID,ClassName和累加记录总数
if pid>0 then
sql="select * from "&CurrentTableName&" where "&ParentClassID&"="&thisid
else
sql="select * from "&CurrentTableName&" where "&CurrentClassID&"="&thisid
end if
set rs_c=conn.execute(sql)
n=n+1
do while not rs_c.eof
response.Write("执行语句"+i+"次")
list(0,i)=rs_c(CurrentClassID)'装入数组中
list(1,i)=rs_c(CurrentClassName)
list(2,i)=n
'n=n+1
i=i+1
thisid=ClassArray(rs_c(CurrentClassID),1)
'这里递归调用子类别,直到最后一个子类
rs_c.movenext
loop
'累加记录总数
n=n-1
rs_c.close
set rs_c=nothing
response.End()
end function
public function ArrayList()'循环出所有根类
set rs_c=conn.execute("select count("&CurrentClassID&") from "&CurrentTableName)
lenght=rs_c(0)
rs_c.close
set rs_c=nothing
if not isnull(lenght) and lenght>0 then
redim list(2,lenght)'设置数组
set rs1=conn.execute("select "&CurrentClassID&" from "&CurrentTableName&" where "&ParentClassID&"=0")
do while not rs1.eof
call ClassArray(rs1(CurrentClassID),0)
'n=1
rs1.movenext
loop
rs1.close
set rs1=nothing
else
response.Write("没有任何类别")
response.End()
end if
ArrayList=list
end function
end class
%>