<!--#include file="conn.asp"-->
<!--#include file="chkadmin.asp"-->
<!--#include file="inc/char.asp"-->
<%dim id,sql,rs,Sequence,ParentID
id=CInt(Trim(Request.QueryString("id")))

dim errmsg,founderr
founderr=false

if chkadmin=false or power(5)="0" then
	founderr=true
	errmsg=errmsg+"<li>您没有删除分类的权限</li>"
end if

sql="select ParentID,ChildID,Sequence from Class where ID="&id
set rs=conn.execute(sql)
ParentID=rs(0)
Sequence=rs(2)
if not(isnull(rs(1)) or rs(1)="") then
	founderr=true
	errmsg=errmsg+"<li>此分类还有下级分类，不能删除</li>"
end if
	
if founderr=false then
	conn.execute("update Class set Sequence=Sequence-1 where ParentID="&ParentID&" and Sequence>"&Sequence)
	conn.execute("delete from Class where ID="&id)
	conn.execute("delete from Software where ClassID="&id)
	dim ChildID
	sql="select ID from Class where ParentID="&ParentID&" order by Sequence"
	set rs=conn.execute(sql)
	if rs.eof and rs.bof then
		ChildID=""
	else
		ChildID=CStr(rs(0))
		rs.movenext
		do while not rs.eof
			ChildID=ChildID&","&CStr(rs(0))
			rs.movenext
		loop
	end if
	conn.execute("update Class set ChildID='"&ChildID&"' where ID="&ParentID)
	dim gourl,msg
	gourl="class_list.asp?id="&ParentID
	msg="此分类已删除！"
	call ok()
else
	call error()
end if

set rs=nothing
conn.close
set conn=nothing%>