📄 function.asp
字号:
sql="select "&ClassID&","&NextID&" from "&TableName&" where "&RootID&"=" & MaxRootID & " and "&Depth&"=0"
set rs=server.CreateObject("Adodb.recordset")
rs.open sql,conn,1,3
rePrevID=rs(0) '得到新的PrevID
rs(1)=reClassID '更新上一个一级分类栏目的NextID的值
rs.update
rs.close
set rs=nothing
MaxRootID=MaxRootID+1
'更新当前栏目数据
conn.execute("update "&TableName&" set "&depth&"=0,"&OrderID&"=0,"&rootid&"="&maxrootid&","&parentid&"=0,"&ParentPath&"='0',"&PrevID&"=" & rePrevID & ","&NextID&"=0 where "&ClassID&"="&reClassID)
'如果有下属栏目,则更新其下属栏目数据。下属栏目的排序不需考虑,只需更新下属栏目深度和一级排序ID(rootid)数据
if rechild>0 then
i=0
reParentPath=reParentPath & ","
set rs=conn.execute("select * From "&TableName&" where "&ParentPath&" like '%"&reParentPath & reClassID&"%'") '所有该栏目的下级栏目
do while not rs.eof
i=i+1
mParentPath=replace(rs(""&ParentPath&""),reParentPath,"")
conn.execute("update "&TableName&" set "&depth&"="&depth&"-"&redepth&","&rootid&"="&maxrootid&","&ParentPath&"='"&mParentPath&"' where "&ClassID&"="&rs(""&ClassID&""))
rs.movenext
loop
rs.close
set rs=nothing
end if
'更新其原来所属栏目的栏目数,排序相当于剪枝而不需考虑
conn.execute("update "&TableName&" set "&child&"="&child&"-1 where "&ClassID&"="&iParentID)
elseif iParentID>0 and reParentID>0 then '如果是将一个分栏目移动到其他分栏目下
'得到当前栏目的下属子栏目数
reParentPath=reParentPath & ","
set rs=conn.execute("select count(*) From "&TableName&" where "&ParentPath&" like '%"&reParentPath & reClassID&"%'")
ClassCount=rs(0)
if isnull(ClassCount) then
ClassCount=1
end if
rs.close
set rs=nothing
'获得目标栏目的相关信息
set trs=server.CreateObject("adodb.recordset")
trs.open"select * From "&TableName&" where "&ClassID&"="&reParentID,conn,1,3
if trs(""&Child&"")>0 then
'得到与本栏目同级的最后一个栏目的OrderID
set rsPrevOrderID=conn.execute("select Max("&OrderID&") From "&TableName&" where "&ParentID&"=" & trs(""&ClassID&""))
PrevOrderID=rsPrevOrderID(0)
'得到与本栏目同级的最后一个栏目的ClassID
sql="select "&ClassID&","&NextID&" from "&TableName&" where "&ParentID&"=" & trs(""&ClassID&"") & " and "&OrderID&"=" & PrevOrderID
set rs=server.createobject("adodb.recordset")
'PrevOrderID=PrevOrderID+1
rs.open sql,conn,1,3
rePrevID=rs(0) '得到新的PrevID
rs(1)=reClassID '更新上一个栏目的NextID的值
rs.update
rs.close
set rs=nothing
'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID,如果比前一个值大,则改用这个值。
set rsPrevOrderID=conn.execute("select Max("&OrderID&") From "&TableName&" where "&ParentPath&" like '" & trs(""&ParentPath&"") & "," & trs(""&ClassID&"") & ",%'")
if (not(rsPrevOrderID.bof and rsPrevOrderID.eof)) then
if not IsNull(rsPrevOrderID(0)) then
if rsPrevOrderID(0)>PrevOrderID then
PrevOrderID=rsPrevOrderID(0)
'PrevOrderID=PrevOrderID+1
end if
end if
end if
else
rePrevID=0
PrevOrderID=trs(""&OrderID&"")
end if
'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
conn.execute("update "&TableName&" set "&OrderID&"="&OrderID&"+" & ClassCount & "+1 where "&rootid&"=" & trs(""&rootid&"") & " and "&OrderID&">" & PrevOrderID)
'更新当前栏目数据
conn.execute("update "&TableName&" set "&depth&"="&trs(""&depth&"")&"+1,"&OrderID&"="&PrevOrderID&"+1,"&rootid&"="&trs(""&rootid&"")&","&ParentID&"="&reParentID&","&ParentPath&"='" & trs(""&ParentPath&"") & "," & trs(""&ClassID&"") & "',"&PrevID&"=" & rePrevID & ","&NextID&"=0 where "&ClassID&"="&reClassID)
'如果有子栏目则更新子栏目数据,深度为原来的相对深度加上当前所属栏目的深度
set rs=conn.execute("select * From "&TableName&" where "&ParentPath&" like '%"&reParentPath&reClassID&"%' order by "&OrderID&"")
i=1
do while not rs.eof
i=i+1
iParentPath=trs(""&ParentPath&"") & "," & trs(""&ClassID&"") & "," & replace(rs(""&ParentPath&""),reParentPath,"")
conn.execute("update "&TableName&" set "&depth&"="&depth&"-"&redepth&"+"&trs(""&depth&"")&"+1,"&OrderID&"="&PrevOrderID&"+"&i&","&rootid&"="&trs(""&rootid&"")&","&ParentPath&"='"&iParentPath&"' where "&ClassID&"="&rs(""&ClassID&""))
rs.movenext
loop
rs.close
set rs=nothing
trs.close
set trs=nothing
'更新所指向的上级栏目的子栏目数
conn.execute("update "&TableName&" set "&child&"="&child&"+1 where "&ClassID&"="&reParentID)
'更新其原父类的子栏目数
conn.execute("update "&TableName&" set "&child&"="&child&"-1 where "&ClassID&"="&iParentID)
else '如果原来是一级栏目改成其他栏目的下属栏目
'得到移动的栏目总数
set rs=conn.execute("select count(*) From "&TableName&" where "&rootid&"="&rerootid)
ClassCount=rs(0)
rs.close
set rs=nothing
'获得目标栏目的相关信息
set trs=server.CreateObject("adodb.recordset")
trs.open"select * From "&TableName&" where "&ClassID&"="&reParentID,conn,1,3
if trs(""&Child&"")>0 then
'得到与本栏目同级的最后一个栏目的OrderID
set rsPrevOrderID=conn.execute("select Max("&OrderID&") From "&TableName&" where "&ParentID&"=" & trs(""&ClassID&""))
PrevOrderID=rsPrevOrderID(0)
sql="select "&ClassID&","&NextID&" from "&TableName&" where "&ParentID&"=" & trs(""&ClassID&"") & " and "&OrderID&"=" & PrevOrderID
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
rePrevID=rs(0)
rs(1)=reClassID
rs.update
set rs=nothing
'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID,如果比前一个值大,则改用这个值。
set rsPrevOrderID=conn.execute("select Max("&OrderID&") From "&TableName&" where "&ParentPath&" like '" & trs(""&ParentPath&"") & "," & trs(""&ClassID&"") & ",%'")
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
else
rePrevID=0
PrevOrderID=trs(""&OrderID&"")
end if
'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
conn.execute("update "&TableName&" set "&OrderID&"="&OrderID&"+" & ClassCount &"+1 where "&rootid&"=" & trs(""&rootid&"") & " and "&OrderID&">" & PrevOrderID)
conn.execute("update "&TableName&" set "&PrevID&"=" & rePrevID & ","&NextID&"=0 where "&ClassID&"=" & reClassID)
set rs=conn.execute("select * From "&TableName&" where "&rootid&"="&rerootid&" order by "&OrderID&"")
i=0
do while not rs.eof
i=i+1
if rs(""&parentid&"")=0 then
reParentPath=trs(""&ParentPath&"") & "," & trs(""&ClassID&"")
conn.execute("update "&TableName&" set "&depth&"="&depth&"+"&trs(""&depth&"")&"+1,"&OrderID&"="&PrevOrderID&"+"&i&","&rootid&"="&trs(""&rootid&"")&","&ParentPath&"='"&reParentPath&"',"&parentid&"="&reParentID&" where "&ClassID&"="&rs(""&ClassID&""))
else
reParentPath=trs(""&ParentPath&"") & "," & trs(""&ClassID&"") & "," & replace(rs(""&ParentPath&""),"0,","")
conn.execute("update "&TableName&" set "&depth&"="&depth&"+"&trs(""&depth&"")&"+1,"&OrderID&"="&PrevOrderID&"+"&i&","&rootid&"="&trs(""&rootid&"")&","&ParentPath&"='"&reParentPath&"' where "&ClassID&"="&rs(""&ClassID&""))
end if
rs.movenext
loop
rs.close
set rs=nothing
trs.close
set trs=nothing
'更新所指向的上级栏目栏目数
conn.execute("update "&TableName&" set "&child&"="&child&"+1 where "&ClassID&"="&reParentID)
end if
end if
end sub
'***************************************
'过程名:Moveup()
'作用:用于一级栏目的上移
'时间:2005-4-20
'开发者:郭立江
'参数设置:
' Tablename:表名
' Reclassid:要上移的ClassID
' Rerootid:要上移的rootid
' Movenum:要上移的位数
'Talbename表里的字段设置
' Classid:栏目ID,唯一标识;程序写入
' Parentid:父级栏目ID
' Nextid:前栏目ID(同级栏目比较下)
' Previd:后栏目ID(同级栏目比较下)
' Rootid:一级栏目排序
'***************************************
Sub Moveup(TableName,RerootID,Movenum,ReClassID,ClassID,ParentID,NextID,PrevID,RootID)
dim sql,rsClass,i
dim ReNextid,ReprevID
dim sqlOrder,rsOrder,tRootID,rs
if reClassID="" then
FoundErr=True
response.Write"<script language='javascript'>alert('参数不足');history.back();</script>"
response.End()
else
reClassID=CLng(reClassID)
end if
if reRootID="" then
FoundErr=true
response.Write"<script language='javascript'>alert('错误参数');history.back();</script>"
response.End()
else
reRootID=Cint(reRootID)
end if
if MoveNum="" then
FoundErr=true
response.Write"<script language='javascript'>alert('错误参数');history.back();</script>"
response.End()
else
MoveNum=Cint(MoveNum)
if MoveNum=0 then
FoundErr=True
response.Write"<script language='javascript'>alert('请选择要提升的数字!');history.back();</script>"
response.End()
end if
end if
if FoundErr=True then
exit sub
end if
'得到本栏目的PrevID,NextID
set rs=conn.execute("select "&PrevID&","&NextID&" from "&TableName&" where "&ClassID&"=" & reClassID)
rePrevID=rs(0)
reNextID=rs(1)
rs.close
set rs=nothing
'先修改上一栏目的NextID和下一栏目的PrevID
if rePrevID>0 then
conn.execute "update "&TableName&" set "&NextID&"=" & reNextID & " where "&ClassID&"=" & rePrevID
end if
if reNextID>0 then
conn.execute "update "&TableName&" set "&PrevID&"=" & PrevID & " where "&ClassID&"=" & reNextID
end if
dim mrs,MaxRootID
set mrs=conn.execute("select max("&rootid&") From "&TableName&"")
MaxRootID=mrs(0)+1
'先将当前栏目移至最后,包括子栏目
conn.execute("update "&TableName&" set "&RootID&"=" & MaxRootID & " where "&RootID&"=" & reRootID)
'然后将位于当前栏目以上的栏目的RootID依次加一,范围为要提升的数字
sqlOrder="select * From "&TableName&" where "&ParentID&"=0 and "&RootID&"<" & reRootID & " order by "&RootID&" desc"
set rsOrder=server.CreateObject("adodb.recordset")
rsOrder.open sqlOrder,conn,1,3
if rsOrder.bof and rsOrder.eof then
exit sub '如果当前栏目已经在最上面,则无需移动
end if
i=1
do while not rsOrder.eof
tRootID=rsOrder("RootID") '得到要提升位置的RootID,包括子栏目
tclassID=rsOrder("classID")
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from "&TableName&" where "&classID&"=" & tclassID,conn,1,3
conn.execute("update "&TableName&" set "&RootID&"="&RootID&"+1 where "&RootID&"=" & tRootID)
i=i+1
if i>MoveNum then
rs(""&previd&"")=reclassid
rs.update
rs.close
rs.open"select * from "&TableName&" where "&classid&"="&reclassid,conn,1,3
rs(""&nextid&"")=rsorder(""&Classid&"")
rs.update
exit do
end if
rsOrder.movenext
loop
set rs=nothing
rsOrder.movenext
if rsOrder.eof then
'conn.execute("update "&TableName&" set PrevID=0 where ClassID=" & ClassID)
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from "&TableName&" where "&Classid&"="&reClassid,conn,1,3
rs(""&previd&"")=0
rs.update
rs.close
set rs=nothing
else
rsOrder(""&NextID&"")=reClassID
rsOrder.update
'conn.execute("update "&TableName&" set PrevID=" & rsOrder("ClassID") & " where ClassID=" & ClassID)
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from "&TableName&" where "&classid&"="&reclassid,conn,1,3
rs(""&previd&"")=rsorder(""&classid&"")
rs.update
rs.close
set rs=nothing
end if
rsOrder.close
set rsOrder=nothing
'然后再将当前栏目从最后移到相应位置,包括子栏目
conn.execute("update "&TableName&" set "&RootID&"=" & tRootID & " where "&RootID&"=" & MaxRootID)
end sub
'****************************************************
'过程名:Movedown
'作用:用于一级栏目的下移
'时间:2005-4-20
'开发者:郭立江
'参数设置:
' Tablename:表名
' Reclassid:要上移的ClassID
' Rerootid:要上移的rootid
' Movenum:要下移的位数
'Talbename表里的字段设置
' Classid:栏目ID,唯一标识;程序写入
' Parentid:父级栏目ID
' Nextid:前栏目ID(同级栏目比较下)
' Previd:后栏目ID(同级栏目比较下)
' Rootid:一级栏目排序
'****************************************************
Sub Movedown(TableName,RerootID,Movenum,ReClassID,ClassID,ParentID,NextID,PrevID,RootID)
dim sql,rsClass,i
dim ReNextid,ReprevID
dim sqlOrder,rsOrder,tRootID,rs
if reClassID="" then
FoundErr=True
response.Write"<script language='javascript'>alert('参数不足');history.back();</script>"
response.End()
else
reClassID=CLng(reClassID)
end if
if reRootID="" then
FoundErr=true
response.Write"<script language='javascript'>alert('错误参数');history.back();</script>"
response.End()
else
reRootID=Cint(reRootID)
end if
if MoveNum="" then
FoundErr=true
response.Write"<script language='javascript'>alert('错误参数');history.back();</script>"
response.End()
else
MoveNum=Cint(MoveNum)
if MoveNum=0 then
FoundErr=True
response.Write"<script language='javascript'>alert('请选择要下移的数字!');history.back();</script>"
response.End()
end if
end if
if FoundErr=True then
exit sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -