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