<%
Class ClassClass
	Private Conn  
	Private IForm  
	
	Public Property Let TForm(ByRef ExteriorForm)
		if IsObject(ExteriorForm) then
			Set IForm = ExteriorForm
		else
			Class_Terminate()
		end if
	End Property
	
	Private Sub Class_initialize() 
		Dim DBC
		Set DBC = New DataBaseClass
		Set Conn = DBC.OpenConnection()
		Set DBC = Nothing
	End Sub 
	
	Private Sub Class_Terminate()
		Set Conn=Nothing
	End Sub 
	
	Private Function CheckClass(PicClassID,ParentID,PicClassEName,PicClassCName,PicClassTemp)
		Dim TempSqlClass,RsTempClassObj
		CheckClass = ""
		if PicClassID <> "" then
			if (Conn.Execute("Select * from PicClass where PicClassID = '" & PicClassID & "'").Eof) then 
				CheckClass = CheckClass & "栏目不存在，可能已经被删除"  
				Exit Function
			end if
		end if
		if ParentID <> "0" then
			if (Conn.Execute("Select * from PicClass where PicClassID = '" & ParentID & "'").Eof) then 
				CheckClass = CheckClass & "父栏目不存在，可能已经被删除"  
				Exit Function
			end if
		end if
		if PicClassEName = "" then
		   CheckClass = CheckClass & "栏目的英文名没有填写！"
		end if
		if PicClassCName = "" then
		   CheckClass = CheckClass & "栏目的中文名没有填写！"
		end if
		if PicClassTemp = "" then
		   CheckClass = CheckClass & "栏目的模板没有填写！"
		end if
		if PicClassID = "" then
			TempSqlClass = "Select PicClassEName from PicClass where PicClassEName='"& PicClassEName & "'"
		else
			TempSqlClass = "Select PicClassEName from PicClass where PicClassEName='"& PicClassEName & "' and PicClassID<>'" & PicClassID & "'"
		end if
		if Not (Conn.Execute(TempSqlClass).Eof) then
		   CheckClass = CheckClass & "栏目的英文名已经存在！"
		end if
	End Function
	
	Public Function AddAndModifyClass()
		Dim RsClassObj
		Dim SqlClass,ErrStr,EditTF
		Dim ParentID,PicClassEName,PicClassCName,PicClassTemp,PicClassID,AddTime
		AddTime = IForm("AddTime")
		PicClassID = IForm("PicClassID")
		ParentID = IForm("ParentID")
		PicClassEName = IForm("PicClassEName")
		PicClassCName = IForm("PicClassCName")
		PicClassTemp = IForm("PicClassTemp")
		if PicClassID = "" then
			EditTF = False
		else
			EditTF = true
		end if
		ErrStr = CheckClass(PicClassID,ParentID,PicClassEName,PicClassCName,PicClassTemp)
		if ErrStr <> "" then
			AddAndModifyClass= ErrStr 
			Exit Function
		end if
		Set RsClassObj = Server.CreateObject("ADODB.Recordset")
		if PicClassID = "" then
			PicClassID = GetRandomID18()
			SqlClass = "select * from PicClass"
			RsClassObj.Open SqlClass,Conn,3,3
			RsClassObj.AddNew
		else
			PicClassID = PicClassID
			SqlClass = "select * from PicClass where PicClassID='" & PicClassID & "'"
			RsClassObj.Open SqlClass,Conn,3,3
		end if
		RsClassObj("PicClassID") = PicClassID
		RsClassObj("PicClassEName") = PicClassEName
		RsClassObj("PicClassCName") = PicClassCName
		RsClassObj("ParentID") = ParentID
		if AddTime <> "" then
			RsClassObj("AddTime") = AddTime
		else
			RsClassObj("AddTime") = Now
		end if
		RsClassObj("ChildNum") = 0
		RsClassObj("PicClassTemp") = PicClassTemp
		RsClassObj.UpDate
		RsClassObj.Close
		Conn.Execute("Update PicClass Set ChildNum = ChildNum + 1 where PicClassID = '" & ParentID & "'")
		Set RsClassObj = Nothing
		if err.Number = 0 then
			AddAndModifyClass = ""  
			Exit Function
		else
			if EditTF then
				AddAndModifyClass = "栏目修改失败"  
				Exit Function
			else
				AddAndModifyClass = "栏目添加失败"  
				Exit Function
			end if
		end if
	End Function
	
	Public Function MoveClass(SourceClassID,ObjectClassID)
		Dim RsClassObj,SqlClass,SourceClassParentID
		SqlClass = "Select ParentID from PicClass where PicClassID='" & SourceClassID & "'"
		Set RsClassObj = Conn.Execute(SqlClass)
		if Not RsClassObj.Eof then
			SourceClassParentID = RsClassObj("ParentID")
		else
			SourceClassParentID = ""
		end if
		MoveClass = "Update PicClass Set ParentID = '" & ObjectClassID & "' where PicClassID = '" & SourceClassID & "';"
		Conn.Execute(MoveClass)
		if SourceClassParentID <> "" then
			MoveClass = "Update PicClass Set ChildNum=ChildNum-1 where PicClassID = '" & SourceClassParentID & "';"
			Conn.Execute(MoveClass)
		end if
		MoveClass = "Update PicClass Set ChildNum=ChildNum+1 where PicClassID = '" & ObjectClassID & "';"
		Conn.Execute(MoveClass)
	End Function
	
	Public Function CopyClass(SourceClassID,ObjectClassID)
		Dim RsSourceClassObj,SourceClassSql,RsObjectClassObj,ObjectClassSql,i
		SourceClassSql = "Select * from PicList where PicClassID='" & SourceClassID & "'"
		ObjectClassSql = "Select * from PicList where PicClassID='" & ObjectClassID & "'"
		Set RsObjectClassObj = Server.CreateObject("ADODB.Recordset")
		RsObjectClassObj.Open ObjectClassSql,Conn,3,3
		Set RsSourceClassObj = Conn.Execute(SourceClassSql)
		if Not RsSourceClassObj.Eof then
			
		else
		
		end if
		Set RsSourceClassObj = Nothing
		Set RsObjectClassObj = Nothing
	End Function
End Class
%>
