<!--#include file="tgzcm_Conn.asp"-->
<!--#include file="tgzcm_Check.asp"-->
<%
Dim action,del_id,server_id,server_playerid,server_orderid,server_name,server_all
action=Trim(Request.QueryString("action"))
del_id=cint(request.QueryString("del_id"))
server_id=cint(request.form("server_id"))
server_playerid=cint(request.form("server_playerid"))
server_orderid=cint(request.form("server_orderid"))
server_name=tgzcm_replace(trim(request.form("server_name")))
server_all=trim(request.form("server_all"))

If action="add" Then
 Call server_add
Elseif action="edit" Then
 call server_edit
ElseIf action="del" Then
 call server_del
End If

Sub server_add
    If server_name="" Then 
	Call adnim_err_c("服务器组名字不能为空！")
	Response.End
    End if
    Dim maxid
	maxid=max_id("server")'通过调用函数得到当前最大ID
	Set rs = Server.CreateObject("adodb.recordset")
	sql = " select * from tgzcm_server "
	rs.Open sql, Conn, 1, 3
	rs.AddNew
	rs("server_id")=maxid
	rs("server_playerid")=server_playerid
	rs("server_orderid")=server_orderid
	rs("server_name")=server_name
	rs("server_all")=server_all
	rs.Update
	rs.Close
	set rs=nothing
	response.redirect "tgzcm_server.asp"
End sub

Sub server_edit
    If server_name="" Then 
	Call adnim_err_c("服务器组名字不能为空！")
	Response.End
    End if
	Set rs = Server.CreateObject("adodb.recordset")
	sql = " select * from tgzcm_server where server_id="&server_id&" "
	rs.Open sql, Conn, 1, 3
	If Not (rs.bof And rs.eof) Then 
	    rs("server_playerid")=server_playerid
		rs("server_orderid")=server_orderid
		rs("server_name")=server_name
		rs("server_all")=server_all
		rs.update
		response.redirect "tgzcm_server.asp"
	Else
	    Call adnim_err_a("没有查询找到与此相符合的记录！")
	End if
	rs.Close
	set rs=nothing
End sub

Sub server_del
	'delfolder"../"&zt_en
	dim del_server_id
	Conn.Execute(" delete from adnim_server where server_id="&del_id&" ")'删除服务器表
	Conn.Execute(" delete from adnim_url where server_id="&del_id&" ")   '删除地址表
	Set rs = Server.CreateObject("adodb.recordset")
	sql = " select data_id,server_id from adnim_data where server_id like '%"&del_id&"|%' order by data_id asc "
	rs.Open sql, Conn, 1, 1
	If Not (rs.bof And rs.eof) Then
	  do while not rs.eof
	  del_server_id=replace(rs("server_id"),del_id&"|","")
	  'rs("server_id")=del_server_id
	  'rs.update'修改每部影片所属服务器组的属性
	  Conn.Execute(" Update [adnim_data] Set server_id='"&del_server_id&"' Where data_id="&rs("data_id")&" ")'修改每部影片所属服务器组的属性
	  rs.movenext
	  loop
	Else
	  Call adnim_err_a("还没有添加作何影片，不对影片所属地址组进行操作！")
	End if
	rs.Close
	set rs=nothing
	response.redirect "tgzcm_server.asp"
End sub

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