<!--#include file="tgzcm_Conn.asp"-->
<!--#include file="tgzcm_Check.asp"-->
<%
dim action,del_id,class_id,class_bigid,class_orderid,class_name,class_dir
action=Trim(Request.QueryString("action"))
del_id=Cint(Request.QueryString("del_id"))
class_id=Cint(Request.Form("class_id"))
class_bigid=Cint(Request.Form("class_bigid"))
class_orderid=Cint(Request.Form("class_orderid"))
class_name=Trim(Request.Form("class_name"))
class_dir=Trim(Request.Form("class_dir"))

If action="add" Then
    Call class_add
Elseif action="edit" Then
    Call class_edit
Elseif action="del" Then
    Call class_del
End if

Sub class_add
	If class_name="" Or class_dir="" Then 
		Call tgzcm_err_c("必要参数不能为空！")
		Response.End
	End if  
    Dim maxid
	maxid=max_id("class")'通过调用函数得到当前最大ID
	Set rs = Server.CreateObject("adodb.recordset")
	sql = " select * from tgzcm_class "
	rs.Open sql, Conn, 1, 3
	rs.AddNew
	rs("class_id")=maxid
	rs("class_bigid")=class_bigid
	rs("class_orderid")=class_orderid
	rs("class_name")=class_name
	rs("class_dir")=class_dir
	rs.update
	rs.Close
	set rs=nothing
	Call class_create
	Response.Redirect "tgzcm_class.asp"
End sub

Sub class_edit
	If class_name="" Or class_dir="" Then 
		Call tgzcm_err_c("必要参数不能为空！")
		Response.End
	End if
	Set rs = Server.CreateObject("adodb.recordset")
	sql = " select * from tgzcm_class where class_id="&class_id&" "
	rs.Open sql, Conn, 1, 3
	If Not (rs.bof And rs.eof) Then
	    rs("class_bigid")=class_bigid 
		rs("class_orderid")=class_orderid
		rs("class_name")=class_name
		rs("class_dir")=class_dir
		rs.update
		Call class_create
		Response.Redirect "tgzcm_class.asp"
	Else
	    Call tgzcm_err_c("没有查询找到与此相符合的记录！")
	End if
	rs.Close
	set rs=nothing
End sub

Sub class_del
	'Call DelFolder("../"&GetClassEn(del_id))
	Conn.execute(" Update [tgzcm_name] Set class_id=0 Where class_id="&del_id&" ")    '更新栏目ID
	Conn.execute(" Delete from [tgzcm_class] where class_id="&del_id&" or class_id in (select class_id from tgzcm_class where class_bigid="&del_id&") ")    '删除分类数据表
	Call class_create
	Response.Redirect "tgzcm_class.asp"
End sub

Sub class_create'动态生成栏目名称以提供前台缓存
    Dim Class_Name,Class_En
	Class_Name="":Class_En=""
	Set crs = Server.CreateObject("adodb.recordset")
	sql = " Select class_id,class_name,class_dir from tgzcm_class order by class_id asc " 
	crs.Open sql, Conn, 1, 1
	If Not (crs.bof And crs.eof) Then
	    Class_Name = "Class_N_0=""未知"""&chr(13)
		Class_En = "Class_E_0=""noclass"""&chr(13)
		Do while not crs.eof
		Class_Name=Class_Name&"Class_N_"&crs("class_id")&"="""&crs("class_name")&""""&chr(13)
		Class_En=Class_En&"Class_E_"&crs("class_id")&"="""&crs("class_dir")&""""&chr(13)
		crs.movenext
		Loop
		Call MakeHtml("../tgzcm.Cache/tgzcm.Class.asp","<%"&chr(13)&Class_Name&Class_En&"%"&">")'生成栏目文件
	End if
	crs.Close
	Set crs=nothing
End Sub

Call CloseConn()'关闭数据库连接
%>