您现在的位置是:网站首页> 编程资料编程资料
ajax+asp无限级分类树型结构的代码_AJAX相关_
2023-05-25
445人已围观
简介 ajax+asp无限级分类树型结构的代码_AJAX相关_
复制代码 代码如下:
<%
'数据库字段为类属性,添加、删除、修改、操作检查等函数为类的方法
Class Cls_Leibie
Private nClassID,sClassName,nParentID,sParentPath,nDepth,nRootID,nChild,nOrderID,sFilePath '定义私有变量(类的属性,即数据库字段对应的变量)
Private rs,sql,ErrorStr
Private Sub Class_Initialize()
ErrorStr="" '初始化错误信息为空
End Sub
Private Sub Class_Terminate() '销毁类时关闭数据库连接
If IsObject(Conn) Then
Conn.Close
Set Conn = Nothing
End If
End Sub
'*******************设置各个属性******************************************************
Public Property Let ClassID(str) '获取类别ID(主键)
nClassID=str
call ClassProperty() '获取类别ID时调用此函数读出类的所有属性
End Property
Public Property Let ClassName(str) '获取类别名称
sClassName=str
End Property
Public Property Get ClassName
ClassName=sClassName
End Property
Public Property Let ParentID(str) '获取类别父ID
nParentID=str
End Property
Public Property Get ParentID
ParentID=nParentID
End Property
Public Property Let ParentPath(str) '获取父路径ID
sParentPath=str
End Property
Public Property Get ParentPath
ParentPath=sParentPath
End Property
Public Property Let Depth(str) '获取类别深度
nDepth=str
End Property
Public Property Get Depth
Depth=nDepth
End Property
Public Property Let RootID(str) '获取类别根ID
nRootID=str
End Property
Public Property Get RootID
RootID=nRootID
End Property
Public Property Let Child(str) '子类别个数
nChild=str
End Property
Public Property Get Child
Child=nChild
End Property
Public Property Let OrderID(str) '排序ID
nOrderID=str
End Property
Public Property Get OrderID
OrderID=nOrderID
End Property
Public Property Let FilePath(str) '类别文件根目录(生成静态文件路径,小站奇人异事网([url]www.guaishi.org[/url])用的是生成静态,故设置此字段)
sFilePath=str
End Property
Public Property Get FilePath
FilePath=sFilePath
End Property
'******************************************************************************
Private Sub ClassProperty() '读取类的所有属性
sql="select * from ArticleClass where ClassID="& nClassID
set rs=conn.execute(sql)
if not rs.eof then
sClassName=trim(rs("ClassName"))
nParentID=trim(rs("ParentID"))
sParentPath=trim(rs("ParentPath"))
nDepth=trim(rs("Depth"))
nRootID=trim(rs("RootID"))
nChild=trim(rs("Child"))
nOrderID=trim(rs("OrderID"))
sFilePath=trim(rs("FilePath"))
end if
set rs=nothing
End Sub
Public Function FAddCheck() '类别添加检查函数,结果为0表示通过检查,为1表示有错误发生,有错误发生时退出函数,将错误信息写入错误变量ErrorStr
dim temprs
FAddCheck=0
if sClassName="" then '类名为空
FAddCheck=1
ErrorStr="类名不能为空!"
exit Function
else
if nParentID="" then '父id为空
FAddCheck=1
ErrorStr="父id不能为空!"
exit Function
else
if nParentID<>0 then
set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID) '父类别不存在
if temprs.eof then
FAddCheck=1
ErrorStr="所属类别不存在或已经被删除!"
exit Function
else
sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID '类名重复
set rs=conn.execute(sql)
if not rs.eof then
FAddCheck=1
ErrorStr="类名重复!"
exit Function
end if
set rs=nothing
end if
set temprs=nothing
else
sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID '类名重复
set rs=conn.execute(sql)
if not rs.eof then
FAddCheck=1
ErrorStr="类名重复!"
exit Function
end if
set rs=nothing
end if
end if
end if
End Function
Public Sub SAdd()
dim maxClassID,maxRootID
set rs = conn.execute("select Max(ClassID) from ArticleClass") '查找当前数据库中最大的类别id,如果没有数据则设置为0,要插入的类别id为当前最大id加1
maxClassID=rs(0)
if isnull(maxClassID) then
maxClassID=0
end if
set rs=nothing
nClassID=maxClassID+1
set rs=conn.execute("select max(rootid) From ArticleClass") '查找当前数据库中最大的根id,如果没有数据则设置为0,要插入的根id为当前最大根id加1
maxRootID=rs(0)
if isnull(maxRootID) then
maxRootID=0
end if
nRootID=maxRootID+1
set rs=conn.execute("select RootID,Depth,ParentPath,Child,OrderID From ArticleClass where ClassID=" & nParentID) '查找父类别相应信息
if not rs.eof then
nRootID=trim(rs("Rootid")) '根id与父类别根id相同
sParentPath=trim(rs("ParentPath"))& "," &nParentID
if cint(trim(nParentID))>0 then '父id大于0则有父类别,故要插入的类别的深度父类别的深度加1,父id不大于0则当前要插入的类别为根类别,则深度为0
nDepth=cint(trim(rs("Depth")))+1
else
nDepth=0
end if
if cint(trim(rs("Child")))>0 then
dim rsPrevOrderID
'得到与本栏目同级的最后一个栏目的OrderID
set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentID=" & ParentID)
prevOrderID=rsPrevOrderID(0)
'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID,如果比前一个值大,则改用这个值。
set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentPath like '" & ParentPath & ",%'")
if (not(rsPrevOrderID.bof and rsPrevOrderID.eof)) then
if not IsNull(rsPrevOrderID(0)) then
if rsPrevOrderID(0)>prevOrderID then
prevOrderID=rsPrevOrderID(0)
end if
end if
end if
set rsPrevOrderID=nothing
end if
nOrderID=prevOrderID+1
else
nOrderID=0
sParentPath="0"
nDepth=0
end if
set rs=nothing
nChild=0
sql="insert into ArticleClass (ClassID,ClassName,ParentID,ParentPath,Depth,RootID,Child,OrderID,FilePath) values ("& nClassID &",'"& sClassName &"',"& nParentID &",'"& sParentPath &"',"& nDepth &","& nRootID &","& nChild &","& nOrderID &",'"& sFilePath &"')"
conn.execute(sql)
if ParentID>0 then
'更新其父类的子栏目数
conn.execute("update ArticleClass set child=child+1 where ClassID="& nParentID)
'更新该栏目排序以及大于本需要和同在本分类下的栏目排序序号
if prevOrderID<>"" then
conn.execute("update ArticleClass set OrderID=OrderID+1 where rootid=" & nRootid & " and OrderID>"& prevOrderID &" and ClassID<>"& nClassID)
end if
end if
End Sub
Public Function FEditCheck() '类别修改检查函数,结果为0表示通过检查,为1表示有错误发生,有错误发生时退出函数,将错误信息写入错误变量ErrorStr
dim temprs
FEditCheck=0
if nClassID="" then '类别id为空
FEditCheck=1
ErrorStr="类别id不能为空!"
exit Function
else
if sClassName="" then '类名为空
FEditCheck=1
ErrorStr="类名不能为空!"
exit Function
else
if nParentID<>0 then
set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID) '父类别不存在
if temprs.eof then
FAddCheck=1
ErrorStr="所属类别不存在或已经被删除!"
exit Function
else
set rs=conn.execute("select ClassID from ArticleClass where ClassName='"& sClassName &"' and ClassID<>"& nClassID &"and ParentID="& nParentID)
if not rs.eof then '类名重复
FEditCheck=1
ErrorStr="类名重复!"
exit Function
end if
set rs=nothing
end if
set temprs=nothing
end if
end if
end if
End Function
Public Sub SEdit() '类别修改
sql="update ArticleClass set ClassName='"& sClassName &"',FilePath='"& sFilePath &"' where ClassID="& nClassID
相关内容
- Ajax的小贴士使用小结_AJAX相关_
- AJAX 常用函数创建XMLHTTP对象,区别IE,Mozilla浏览器_AJAX相关_
- AJAX 缓存问题的两种解决方法(IE)_AJAX相关_
- AJAX集天气\IP\多国语言翻译MP3(可同步LRC歌词显示)\万年历查询通_AJAX相关_
- [asp]天枫AJAX blog V1.0 程序提供下载了_AJAX相关_
- [asp]天枫AJAX百度音乐即时听附下载_AJAX相关_
- Baidu Musicbox 用到的ajax代码_AJAX相关_
- xmlhttp 乱码 比较完整的解决方法 (UTF8,GB2312 编码 解码)_AJAX相关_
- 本人ajax留言板的源程序 不错的应用js_AJAX相关_
- Ajax 学习资源 中外都有_AJAX相关_
点击排行
本栏推荐
