admin_soft_class.asp

来自「适适合做个人、学校、公司、政府等站点 一个灵活性很好的网站原代码」· ASP 代码 · 共 1,312 行 · 第 1/4 页

ASP
1,312
字号
	end if
	'更新栏目名称
	ClassName=trim(request("ClassName"))
   	rsClass("ClassName")=ClassName
	rsClass.update
	rParentID=trim(request("ParentID"))'父栏目ID
	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 SoftClass where ClassID="&rParentID)'rootid根栏目ID
				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 SoftClass 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")'根栏目ID
	ParentPath=rsClass("ParentPath")'栏目路径
	PrevID=rsClass("PrevID")'同级的上一个栏目ID
	NextID=rsClass("NextID")'同级的下一个栏目ID
	rsClass.close
	set rsClass=nothing
    '假如更改了所属栏目
    '需要更新其原来所属栏目信息,包括深度、父级ID、栏目数、排序、继承版主等数据
    '需要更新当前所属栏目信息
    '继承版主数据需要另写函数进行更新--取消,在前台可用ClassID in ParentPath来获得
    dim mrs,MaxRootID
    set mrs=Conn.execute("select max(rootid) From SoftClass")
    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 SoftClass set NextID=" & NextID & " where ClassID=" & PrevID
	end if
	if NextID>0 then
		Conn.execute "update SoftClass set PrevID=" & PrevID & " where ClassID=" & NextID
	end if
	
	if iParentID>0 and rParentID=0 then  	'如果原来不是一级分类改成一级分类
		'得到上一个一级分类栏目
		sql="select ClassID,NextID from SoftClass 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 SoftClass 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 SoftClass where ParentPath like '%"&ParentPath & ClassID&"%'")
			do while not rs.eof
				i=i+1
				mParentPath=replace(rs("ParentPath"),ParentPath,"")
				Conn.execute("update SoftClass 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 SoftClass set child=child-1 where ClassID="&iParentID)
		
	elseif iParentID>0 and rParentID>0 then    '如果是将一个分栏目移动到其他分栏目下
		'得到当前栏目的下属子栏目数
		ParentPath=ParentPath & ","
		set rs=Conn.execute("select count(*) From SoftClass 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 SoftClass where ClassID="&rParentID)
		if trs("Child")>0 then		
			'得到与本栏目同级的最后一个栏目的OrderID
			set rsPrevOrderID=Conn.execute("select Max(OrderID) From SoftClass where ParentID=" & trs("ClassID"))
			PrevOrderID=rsPrevOrderID(0)
			'得到与本栏目同级的最后一个栏目的ClassID
			sql="select ClassID,NextID from SoftClass 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 SoftClass 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 SoftClass set OrderID=OrderID+" & ClassCount & "+1 where rootid=" & trs("rootid") & " and OrderID>" & PrevOrderID)
		
		'更新当前栏目数据
		Conn.execute("update SoftClass 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 SoftClass 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 SoftClass 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 SoftClass set child=child+1 where ClassID="&rParentID)
		'更新其原父类的子栏目数			
		Conn.execute("update SoftClass set child=child-1 where ClassID="&iParentID)
	else    '如果原来是一级栏目改成其他栏目的下属栏目
		'得到移动的栏目总数
		set rs=Conn.execute("select count(*) From SoftClass where rootid="&rootid)
		ClassCount=rs(0)
		rs.close
		set rs=nothing
		'获得目标栏目的相关信息		
		set trs=Conn.execute("select * From SoftClass where ClassID="&rParentID)
		if trs("Child")>0 then		
			'得到与本栏目同级的最后一个栏目的OrderID
			set rsPrevOrderID=Conn.execute("select Max(OrderID) From SoftClass where ParentID=" & trs("ClassID"))
			PrevOrderID=rsPrevOrderID(0)
			sql="select ClassID,NextID from SoftClass 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 SoftClass 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 SoftClass set OrderID=OrderID+" & ClassCount &"+1 where rootid=" & trs("rootid") & " and OrderID>" & PrevOrderID)
		Conn.execute("update SoftClass set PrevID=" & PrevID & ",NextID=0 where ClassID=" & ClassID)
		set rs=Conn.execute("select * From SoftClass 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 SoftClass 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 SoftClass 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 SoftClass set child=child+1 where ClassID="&rParentID)

	end if
  end if
	Response.Write "<p align=center>资源栏目修改成功,3秒后自动返回下载栏目管理页!<script>window.setTimeout(""location.href='Admin_Soft_Class.asp'"",3000);</script></p>"
end sub
sub ClearClass()
	dim strClassID,rs,trs,SuccessMsg,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 SoftClass 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 SoftClass 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 SoftClass 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
	Conn.execute("update SoftData set S_Recycle=True,S_RecycleTime='"&Now()&"' where S_SoftClassID in (" & strClassID & ")")
	Response.Write "<p align=center>栏目清空成功,3秒后自动返回下载栏目管理页!<script>window.setTimeout(""location.href='Admin_Soft_Class.asp'"",3000);</script></p>"
    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 SoftClass where ClassID=" & ClassID)
	PrevID=rs(0)
	NextID=rs(1)
	rs.close
	set rs=nothing
	'先修改上一栏目的NextID和下一栏目的PrevID
	if PrevID>0 then
		Conn.execute "update SoftClass set NextID=" & NextID & " where ClassID=" & PrevID
	end if
	if NextID>0 then
		Conn.execute "update SoftClass set PrevID=" & PrevID & " where ClassID=" & NextID
	end if

	dim mrs,MaxRootID
	set mrs=Conn.execute("select max(rootid) From SoftClass")
	MaxRootID=mrs(0)+1
	'先将当前栏目移至最后,包括子栏目
	Conn.execute("update SoftClass set RootID=" & MaxRootID & " where RootID=" & cRootID)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?