<% Option Explicit %>
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Const.asp" -->
<%
Dim DBC,Conn,LableTypeObj,ID,NameType,TypeDes,TypeType,BigTypeID
Set DBC=new DataBaseClass
Set Conn=DBC.OpenConnection
Set DBC=Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0302") then Call ReturnError()
ID=request("ID")
BigTypeID=request("BigTypeID")
if BigTypeID <> "" then
	if BigTypeID < 0 OR BigTypeID = "" then
		BigTypeID = "0"
	else
		BigTypeID = BigTypeID
	end if
end if
set LableTypeObj = Server.CreateObject("ADODB.recordset")
if ID<>"" then
	LableTypeObj.open "select * from LableType where ID="&ID,conn,3,3
	NameType = LableTypeObj("TypeName")
	TypeDes = LableTypeObj("Description")
	TypeType = Cstr(LableTypeObj("ParentID"))
	LableTypeObj.close
else
	NameType = ""
	TypeDes = ""
	TypeType = BigTypeID
end if
if request.Form("submit") = " 确  定 " then
	if request.Form("TypeName")="" then
		Response.Write("<script>alert(""错误：\n请填写完整"");location.href=""LableTypeAddNew.asp?BigTypeID="&request("BigTypeID")&""";</script>")
		Response.End
	end if
	on error resume next
	if ID<>"" then
		LableTypeObj.open "select * from LableType where ID="&ID,conn,3,3
		dim TempTF
		TempTF = SelectObj(CInt(Request.form("TypeType")),ID)
		if TempTF then
			Response.Write("<script>alert(""错误：\n父类型不能移到子类型中"");location.href=""LableTypeAddNew.asp?BigTypeID="&request("BigTypeID")&"&ID="&request("ID")&""";</script>")
			Response.End
		end if
	else
		LableTypeObj.open "select * from LableType",conn,3,3
		LableTypeObj.addnew
	end if
	LableTypeObj("TypeName")=request.Form("TypeName")
	LableTypeObj("Description")=request.Form("Description")
	if Request.form("TypeType") <> "" then
		LableTypeObj("ParentID") = CInt(Request.form("TypeType"))
	else
		LableTypeObj("ParentID") = 0
	end if
	LableTypeObj.Update
	
	if err.number=0 then 
		CloseWindow
	else
		if ID<>"" then
			AlertAndCloseWindow "修改失败"
		else
			AlertAndCloseWindow "添加失败"
		end if
	end if
end if
Sub CloseWindow()
%>
<script language="javascript">
	dialogArguments.location.reload();
	window.close();
</script>
<%
End Sub
Sub AlertAndCloseWindow(ErrorStr)
	Set Conn = Nothing
%>
<script language="javascript">
	alert ('<% = ErrorStr %>')
	dialogArguments.location.reload();
	window.close();
</script>
<%
End Sub
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>标签类型</title>
</head>
<link href="../Inc/ModeWindow.css" rel="stylesheet">
<body scroll=no bgcolor="#FFFFFF" topmargin="0" leftmargin="0">
<table width="100%">
	<form name=TypeForm method=post action="" >
	<tr>
		<td><div align="right"><font size="2.5">类型名称</font></div></td>
		<td><input name="TypeName" size="30" value="<% = NameType %>"></td>
	</tr>
	<tr>
	  <td width="100"><div align="right"><font size="2.5">父类型</font></div></td>
	  <td><select name="TypeType">
		<option <% if BigTypeID = "0" then Response.Write("Selected") %> value="0">根类型</option>
		<%
		Dim TempTypeObj
		Set TempTypeObj = Conn.Execute("Select * from LableType")
		do while Not TempTypeObj.Eof 
			if TempTypeObj("TypeName") <> NameType then
				%>
				<option <% if TypeType = Cstr(TempTypeObj("ID")) then Response.Write("Selected") %> value="<% = TempTypeObj("ID") %>"><% = TempTypeObj("TypeName") %></option>
				<%
			end if
		TempTypeObj.MoveNext
		Loop
		%>
		</select></td>
	</tr>
	<tr>
		<td><div align="right"><font size="2.5">类型描述</font></div></td>
		<td><textarea name="Description" rows="8" cols="35"><% = TypeDes %></textarea></td>
	</tr>
	<tr>
	<td colspan="2"><table width="100%">
		<tr>
			<td width="50%" align="right"><input name="submit" type="submit" value=" 确  定 " class=Anbutc></td>
			<td width="50%" align="left"><input type="reset" value=" 取  消 " onclick="window.close()" class=Anbutc> </td>
		</tr>
	</table></td>
	</tr>
	</form>
</table>
</body>
</html>
<%
Function SelectObj(SID,ID)
	Dim TempObj,Str
	Str = "Select * From LableType Where ParentID= "& ID
	Set TempObj = conn.Execute(Str)
	do while not TempObj.eof
		if SID = TempObj("ID") then
			SelectObj = true
			Exit do
		end if
		SelectObj = SelectObj(SID,TempObj("ID"))
		if SelectObj = true then Exit do
	TempObj.movenext
	Loop
	TempObj.Close
	Set TempObj = Nothing
End Function
Set conn = Nothing
%>