📄 admin_class_menu.asp
字号:
else
if rs("Child")>0 then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>该栏目含有子栏目,请删除其子栏目后再进行删除本栏目的操作</li>"
end if
end if
if FoundErr=True then
rs.close
set rs=nothing
exit sub
end if
PrevID=rs("PrevID")
NextID=rs("NextID")
if rs("Depth")>0 then
conn.execute("update MenuClass set child=child-1 where ClassID=" & rs("ParentID"))
end if
rs.delete
rs.update
rs.close
set rs=nothing
'修改上一栏目的NextID和下一栏目的PrevID
if PrevID>0 then
conn.execute "update MenuClass set NextID=" & NextID & " where ClassID=" & PrevID
end if
if NextID>0 then
conn.execute "update MenuClass set PrevID=" & PrevID & " where ClassID=" & NextID
end if
call CloseConn()
response.redirect "Admin_Class_Menu.asp"
end sub
sub ClearClass()
dim strClassID,rs,trs,ClassID
ClassID=trim(Request("ClassID"))
if ClassID="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>参数不足!</li>"
exit sub
else
ClassID=CLng(ClassID)
end if
strClassID=cstr(ClassID)
set rs=conn.execute("select ClassID,Child,ParentPath from MenuClass where ClassID=" & ClassID)
if rs.bof and rs.eof then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>栏目不存在,或者已经被删除</li>"
exit sub
end if
if rs(1)>0 then
set trs=conn.execute("select ClassID from MenuClass where ParentID=" & rs(0))
do while not trs.eof
strClassID=strClassID & "," & trs(0)
trs.movenext
loop
trs.close
set trs=conn.execute("select ClassID from MenuClass where ParentPath like '" & rs(2) & "," & rs(0) & ",%'")
do while not trs.eof
strClassID=strClassID & "," & trs(0)
trs.movenext
loop
trs.close
set trs=nothing
end if
rs.close
set rs=nothing
end sub
sub SaveMove()
dim ClassID,sql,rsClass,i
dim rParentID
dim trs,rs
dim ParentID,RootID,Depth,Child,ParentPath,ParentName,iParentID,iParentPath,PrevOrderID,PrevID,NextID
ClassID=trim(request("ClassID"))
if ClassID="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>参数不足!</li>"
exit sub
else
ClassID=CLng(ClassID)
end if
sql="select * From MenuClass where ClassID=" & ClassID
set rsClass=server.CreateObject ("Adodb.recordset")
rsClass.open sql,conn,1,3
if rsClass.bof and rsClass.eof then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>找不到指定的栏目!</li>"
rsClass.close
set rsClass=nothing
exit sub
end if
rParentID=trim(request("ParentID"))
if rParentID="" then
rParentID=0
else
rParentID=CLng(rParentID)
end if
if rsClass("ParentID")<>rParentID then '更改了所属栏目,则要做一系列检查
if rParentID=rsClass("ClassID") then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>所属栏目不能为自己!</li>"
end if
'判断所指定的栏目是否为外部栏目或本栏目的下属栏目
if rsClass("ParentID")=0 then
if rParentID>0 then
set trs=conn.execute("select rootid From MenuClass where LinkUrl='' and ClassID="&rParentID)
if trs.bof and trs.eof then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>不能指定外部栏目为所属栏目</li>"
else
if rsClass("rootid")=trs(0) then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>不能指定该栏目的下属栏目作为所属栏目</li>"
end if
end if
trs.close
set trs=nothing
end if
else
set trs=conn.execute("select ClassID From MenuClass where ParentPath like '"&rsClass("ParentPath")&"," & rsClass("ClassID") & "%' and ClassID="&rParentID)
if not (trs.eof and trs.bof) then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>您不能指定该栏目的下属栏目作为所属栏目</li>"
end if
trs.close
set trs=nothing
end if
end if
if FoundErr=True then
rsClass.close
set rsClass=nothing
exit sub
end if
if rsClass("ParentID")=0 then
ParentID=rsClass("ClassID")
iParentID=0
else
ParentID=rsClass("ParentID")
iParentID=rsClass("ParentID")
end if
Depth=rsClass("Depth")
Child=rsClass("Child")
RootID=rsClass("RootID")
ParentPath=rsClass("ParentPath")
PrevID=rsClass("PrevID")
NextID=rsClass("NextID")
rsClass.close
set rsClass=nothing
'假如更改了所属栏目
'需要更新其原来所属栏目信息,包括深度、父级ID、栏目数、排序、继承版主等数据
'需要更新当前所属栏目信息
'继承版主数据需要另写函数进行更新--取消,在前台可用ClassID in ParentPath来获得
dim mrs,MaxRootID
set mrs=conn.execute("select max(rootid) From MenuClass")
MaxRootID=mrs(0)
set mrs=nothing
if isnull(MaxRootID) then
MaxRootID=0
end if
dim k,nParentPath,mParentPath
dim ParentSql,ClassCount
dim rsPrevOrderID
if clng(parentid)<>rParentID and not (iParentID=0 and rParentID=0) then '假如更改了所属栏目
'更新原来同一父栏目的上一个栏目的NextID和下一个栏目的PrevID
if PrevID>0 then
conn.execute "update MenuClass set NextID=" & NextID & " where ClassID=" & PrevID
end if
if NextID>0 then
conn.execute "update MenuClass set PrevID=" & PrevID & " where ClassID=" & NextID
end if
if iParentID>0 and rParentID=0 then '如果原来不是一级分类改成一级分类
'得到上一个一级分类栏目
sql="select ClassID,NextID from MenuClass where RootID=" & MaxRootID & " and Depth=0"
set rs=server.CreateObject("Adodb.recordset")
rs.open sql,conn,1,3
PrevID=rs(0) '得到新的PrevID
rs(1)=ClassID '更新上一个一级分类栏目的NextID的值
rs.update
rs.close
set rs=nothing
MaxRootID=MaxRootID+1
'更新当前栏目数据
conn.execute("update MenuClass set depth=0,OrderID=0,rootid="&maxrootid&",parentid=0,ParentPath='0',PrevID=" & PrevID & ",NextID=0 where ClassID="&ClassID)
'如果有下属栏目,则更新其下属栏目数据。下属栏目的排序不需考虑,只需更新下属栏目深度和一级排序ID(rootid)数据
if child>0 then
i=0
ParentPath=ParentPath & ","
set rs=conn.execute("select * From MenuClass where ParentPath like '%"&ParentPath & ClassID&"%'")
do while not rs.eof
i=i+1
mParentPath=replace(rs("ParentPath"),ParentPath,"")
conn.execute("update MenuClass set depth=depth-"&depth&",rootid="&maxrootid&",ParentPath='"&mParentPath&"' where ClassID="&rs("ClassID"))
rs.movenext
loop
rs.close
set rs=nothing
end if
'更新其原来所属栏目的栏目数,排序相当于剪枝而不需考虑
conn.execute("update MenuClass set child=child-1 where ClassID="&iParentID)
elseif iParentID>0 and rParentID>0 then '如果是将一个分栏目移动到其他分栏目下
'得到当前栏目的下属子栏目数
ParentPath=ParentPath & ","
set rs=conn.execute("select count(*) From MenuClass where ParentPath like '%"&ParentPath & ClassID&"%'")
ClassCount=rs(0)
if isnull(ClassCount) then
ClassCount=1
end if
rs.close
set rs=nothing
'获得目标栏目的相关信息
set trs=conn.execute("select * From MenuClass where ClassID="&rParentID)
if trs("Child")>0 then
'得到与本栏目同级的最后一个栏目的OrderID
set rsPrevOrderID=conn.execute("select Max(OrderID) From MenuClass where ParentID=" & trs("ClassID"))
PrevOrderID=rsPrevOrderID(0)
'得到与本栏目同级的最后一个栏目的ClassID
sql="select ClassID,NextID from MenuClass where ParentID=" & trs("ClassID") & " and OrderID=" & PrevOrderID
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
PrevID=rs(0) '得到新的PrevID
rs(1)=ClassID '更新上一个栏目的NextID的值
rs.update
rs.close
set rs=nothing
'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID,如果比前一个值大,则改用这个值。
set rsPrevOrderID=conn.execute("select Max(OrderID) From MenuClass 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
PrevID=0
PrevOrderID=trs("OrderID")
end if
'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
conn.execute("update MenuClass set OrderID=OrderID+" & ClassCount & "+1 where rootid=" & trs("rootid") & " and OrderID>" & PrevOrderID)
'更新当前栏目数据
conn.execute("update MenuClass set depth="&trs("depth")&"+1,OrderID="&PrevOrderID&"+1,rootid="&trs("rootid")&",ParentID="&rParentID&",ParentPath='" & trs("ParentPath") & "," & trs("ClassID") & "',PrevID=" & PrevID & ",NextID=0 where ClassID="&ClassID)
'如果有子栏目则更新子栏目数据,深度为原来的相对深度加上当前所属栏目的深度
set rs=conn.execute("select * From MenuClass where ParentPath like '%"&ParentPath&ClassID&"%' order by OrderID")
i=1
do while not rs.eof
i=i+1
iParentPath=trs("ParentPath") & "," & trs("ClassID") & "," & replace(rs("ParentPath"),ParentPath,"")
conn.execute("update MenuClass set depth=depth-"&depth&"+"&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 MenuClass set child=child+1 where ClassID="&rParentID)
'更新其原父类的子栏目数
conn.execute("update MenuClass set child=child-1 where ClassID="&iParentID)
else '如果原来是一级栏目改成其他栏目的下属栏目
'得到移动的栏目总数
set rs=conn.execute("select count(*) From MenuClass where rootid="&rootid)
ClassCount=rs(0)
rs.close
set rs=nothing
'获得目标栏目的相关信息
set trs=conn.execute("select * From MenuClass where ClassID="&rParentID)
if trs("Child")>0 then
'得到与本栏目同级的最后一个栏目的OrderID
set rsPrevOrderID=conn.execute("select Max(OrderID) From MenuClass where ParentID=" & trs("ClassID"))
PrevOrderID=rsPrevOrderID(0)
sql="select ClassID,NextID from MenuClass where ParentID=" & trs("ClassID") & " and OrderID=" & PrevOrderID
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
PrevID=rs(0)
rs(1)=ClassID
rs.update
set rs=nothing
'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID,如果比前一个值大,则改用这个值。
set rsPrevOrderID=conn.execute("select Max(OrderID) From MenuClass 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
PrevID=0
PrevOrderID=trs("OrderID")
end if
'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
conn.execute("update MenuClass set OrderID=OrderID+" & ClassCount &"+1 where rootid=" & trs("rootid") & " and OrderID>" & PrevOrderID)
conn.execute("update MenuClass set PrevID=" & PrevID & ",NextID=0 where ClassID=" & ClassID)
set rs=conn.execute("select * From MenuClass where rootid="&rootid&" order by OrderID")
i=0
do while not rs.eof
i=i+1
if rs("parentid")=0 then
ParentPath=trs("ParentPath") & "," & trs("ClassID")
conn.execute("update MenuClass set depth=depth+"&trs("depth")&"+1,OrderID="&PrevOrderID&"+"&i&",rootid="&trs("rootid")&",ParentPath='"&ParentPath&"',parentid="&rParentID&" where ClassID="&rs("ClassID"))
else
ParentPath=trs("ParentPath") & "," & trs("ClassID") & "," & replace(rs("ParentPath"),"0,","")
conn.execute("update MenuClass set depth=depth+"&trs("depth")&"+1,OrderID="&PrevOrderID&"+"&i&",rootid="&trs("rootid")&",ParentPath='"&ParentPath&"' where ClassID="&rs("ClassID"))
end if
rs.movenext
loop
rs.close
set rs=nothing
trs.close
set trs=nothing
'更新所指向的上级栏目栏目数
conn.execute("update MenuClass set child=child+1 where ClassID="&rParentID)
end if
end if
call CloseConn()
Response.Redirect "Admin_Class_Menu.asp"
end sub
sub UpOrder()
dim ClassID,sqlOrder,rsOrder,MoveNum,cRootID,tRootID,i,rs,PrevID,NextID
ClassID=trim(request("ClassID"))
cRootID=Trim(request("cRootID"))
MoveNum=trim(request("MoveNum"))
if ClassID="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>参数不足!</li>"
else
ClassID=CLng(ClassID)
end if
if cRootID="" then
FoundErr=true
ErrMsg=ErrMsg & "<br><li>错误参数!</li>"
else
cRootID=Cint(cRootID)
end if
if MoveNum="" then
FoundErr=true
ErrMsg=ErrMsg & "<br><li>错误参数!</li>"
else
MoveNum=Cint(MoveNum)
if MoveNum=0 then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>请选择要提升的数字!</li>"
end if
end if
if FoundErr=True then
exit sub
end if
'得到本栏目的PrevID,NextID
set rs=conn.execute("select PrevID,NextID from MenuClass where ClassID=" & ClassID)
PrevID=rs(0)
NextID=rs(1)
rs.close
set rs=nothing
'先修改上一栏目的NextID和下一栏目的PrevID
if PrevID>0 then
conn.execute "update MenuClass set NextID=" & NextID & " where ClassID=" & PrevID
end if
if NextID>0 then
conn.execute "update MenuClass set PrevID=" & PrevID & " where ClassID=" & NextID
end if
dim mrs,MaxRootID
set mrs=conn.execute("select max(rootid) From MenuClass")
MaxRootID=mrs(0)+1
'先将当前栏目移至最后,包括子栏目
conn.execute("update MenuClass set RootID=" & MaxRootID & " where RootID=" & cRootID)
'然后将位于当前栏目以上的栏目的RootID依次加一,范围为要提升的数字
sqlOrder="select * From MenuClass where ParentID=0 and RootID<" & cRootID & " 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,包括子栏目
conn.execute("update MenuClass set RootID=RootID+1 where RootID=" & tRootID)
i=i+1
if i>MoveNum then
rsOrder("PrevID")=ClassID
rsOrder.update
conn.execute("update MenuClass set NextID=" & rsOrder("ClassID") & " where ClassID=" & ClassID)
exit do
end if
rsOrder.movenext
loop
rsOrder.movenext
if rsOrder.eof then
conn.execute("update MenuClass set PrevID=0 where ClassID=" & ClassID)
else
rsOrder("NextID")=ClassID
rsOrder.update
conn.execute("update MenuClass set PrevID=" & rsOrder("ClassID") & " where ClassID=" & ClassID)
end if
rsOrder.close
set rsOrder=nothing
'然后再将当前栏目从最后移到相应位置,包括子栏目
conn.execute("update MenuClass set RootID=" & tRootID & " where RootID=" & MaxRootID)
call CloseConn()
response.Redirect "Admin_Class_Menu.asp?Action=Order"
end sub
sub DownOrder()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -