<!-- #Include File="Include/AMH_Onlogin.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V2.0》，简称“AsaiMHV2”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

Dim n_Data_Name
del_upload_true=True
Index_Url="Server"
Data_Name = "AsaiMHServer"
Call AMH_Master(1,2)
Call AMH_Header(1)
Call Data_Name_Select()
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>'><%Response.Write tit%></a></td>
  <td width=10></td>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>&Action=Add'>添加新<%Response.Write Tit_Fir%></a></td>
  <td width=10></td>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>&Action=Mod'><%Response.Write Tit_Fir%>数据批量处理</a></td>
</td></tr>
</table>
</td></tr>
<%
Call AMH_Table(1)

Select Case LCase(Action)
  	Case "mod"
    	AsaiMHServer_Mod()
  	Case "del"
    	AsaiMHServer_Del()
  	Case "add"
    	AsaiMHServer_Add()
  	Case "edit"
    	AsaiMHServer_Edit()
  	Case Else
    	AsaiMHServer_Main()
End Select

Call AMH_Ender(tit)

Sub AsaiMHServer_Del()
  Dim Del_True
  Del_True=False
  Sql="Select count(*) From "&n_Data_Name&" Where Server_ID="&id
  Set Rs=Cls.Exec(Sql,1)
  If Rs(0)>0 Then Del_True=True
  Rs.Close
  If Del_True=True Then
    Call AMH_Msg("删除"&Tit_Fir&"失败："&Tit_Fir&"（ID:"&id&"）下有数据存在！\n\n请先进行"&Tit_Fir&"数据处理后再尝试删除。","?ChannelIDs="&iChannelIDs,1)
  Else
    Call Cls.Exec("Delete From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" and s_id="&id,0)
    Call AMH_Msg("已成功删除一个"&Tit_Fir&"（ID:"&id&"）！","?ChannelIDs="&iChannelIDs,1)
  End If
End Sub

Sub AsaiMHServer_Mod()
  	Dim Is_All,Server_ID 	
    Call AMH_Td(Tit_Fir&"数据批量处理(表："&n_Data_Name&")")
  	If Chk() Then
       Is_All=False
       If Cls.Code_Form("Is_All")="yes" Then Is_All=True
       csid=Cls.Code_Form("ClassID")
	   Call Chk_cid()
       Server_ID=Trim(Request.Form("Server_ID"))
       If Int(Server_ID)<1 Then Server_ID=0
       If Int(Server_ID)<1 Then
      	  Call AMH_Error("请选择 "&Tit_Fir&" 的 分类 和 "&Tit_Fir&"ID！")
      	  Exit Sub
       End If
       Sql="update "&n_Data_Name&" Set Server_ID="&Server_ID
	   If Is_All=False Then
         If Int(cid)>0 Then
          Sql=Sql&" Where ClassID="&cid
         End If
       End If
       Call Cls.Exec(Sql,0)
       Call AMH_Msg("已成功对"&Tit_Fir&"数据进行批量处理！","?ChannelIDs="&iChannelIDs,1)
      Exit Sub
  	End If
  	Call Form_First()
	%>
	<Form action='?ChannelIDs=<%=iChannelIDs%>&action=Mod' method=post>
	<input type=hidden name=Chk value='yes'>
    <tr><td colspan=2>所有<%response.write Tit_Fir%>：<input type=checkbox name=Is_All value='yes'>选择将对所有<%response.write Tit_Fir%>数据进行批量处理</td></tr>
	<tr><td height=30><%Response.Write Cls.ChannelName%>分类：</td><td><%Response.Write LoadClassSelect(iChannelIDs,cid,Cls.ClassDepth)%></td></tr>
	<tr><td height=30><%Response.Write Tit_Fir%>选择：</td><td><%Call Server_Select("Server_ID")%></td></tr>
	<tr><td colspan=2 align=center height=30><input type=submit value='进行<%Response.Write Tit_Fir%>数据批量处理' onclick="javascript:return click_return('对<%Response.Write Tit_Fir%>数据进行批量处理',0);" class=btn></td></tr>
	</Form>
	<%
End Sub

Sub AsaiMHServer_Edit()
  	Dim Rs2,s_name,s_url
  	Sql="Select top 1 * From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" and s_id="&id
	Call Cls.Exe_Conn(Rs,SQL,3)
  	If Rs.eof Then
    		Rs.Close
    		Call AMH_Msg(Tit_Fir&"ID（"&id&"）不存在！","?",1)
    		Exit Sub
  	End If
    Call AMH_Td("编辑"&Tit_Fir)
  	If Cls.Chk() Then
    		s_name=Cls.Code_Admin("s_name",1,20)
    		s_url=Cls.Code_Admin("s_url",1,250)
    		If s_name="" or s_url="" or s_url="http://" Then
      			Call AMH_Error(Tit_Fir&"的 ID、名称 和 地址 不能为空！")
      			Exit Sub
    		End If
    		If right(s_url,1)<>"/" Then
      			s_url=s_url&"/"
    		End If
    		Sql="Select count(s_id) From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" and s_id<>"&id&" and s_name='"&s_name&"'"
    		Set Rs2=Cls.Exec(Sql,1)
    		If Rs2(0)>0 Then
      			Rs2.Close
      			Set Rs2=nothing
      			Call AMH_Error(Tit_Fir&"（ID:"&id&"）的 名称（"&s_name&"） 不能重复！")
      			Exit Sub
    		End If
    		Rs2.Close
    		Set Rs2=nothing
    		Rs("s_name")=s_name
    		Rs("s_url")=s_url
    		Rs.update
    		Rs.Close
    		Call AMH_Msg("成功编辑一条"&Tit_Fir&"（"&s_name&"）信息！","?ChannelIDs="&iChannelIDs,1)
    		Exit Sub
  	End If
  	Call Form_First()
	%>
	<Form name=Add_frm action='?ChannelIDs=<%=iChannelIDs%>&action=Edit&id=<%Response.Write id%>' method=post>
	<input type=hidden name=Chk value='yes'>
	<tr>
	<td><%Response.Write Tit_Fir%>ID：</td>
	<td><%Response.Write id%><%Response.Write redx%>不可以修改</td>
	</tr>
	<tr>
	<td><%Response.Write Tit_Fir%>名称：</td>
	<td><input type=text name=s_name value='<%Response.Write Rs("s_name")%>' size=30 maxlength=20><%Response.Write redx%></td>
	</tr>
	<tr>
	<td><%Response.Write Tit_Fir%>地址：</td>
	<td><input type=text name=s_url value='<%Response.Write Rs("s_url")%>' size=50 maxlength=250><%Response.Write redx%></td>
	</tr>
	<%
  	Rs.Close
  	Call Submit_Edit()
End Sub

Sub AsaiMHServer_Add()
  	Dim tmp_sid,s_id,s_name,s_url
	tmp_sid=0
	Sql="Select s_id From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" order by s_id desc"
	Set Rs=Cls.Exec(Sql,1)
	If not Rs.eof Then
  		tmp_sid=Int(Rs(0))+1
	Else
		tmp_sid=1
	End If
	Rs.Close	
    Call AMH_Td("添加"&Tit_Fir)
  	If Cls.Chk() Then
    		s_id=Trim(Request.Form("s_id"))
    		s_name=Cls.Code_Admin("s_name",1,20)
    		s_url=Cls.Code_Admin("s_url",1,250)
    		If Int(s_id)<1 or s_name="" or s_url="" or s_url="http://" Then
      			Call AMH_Error(Tit_Fir&"的 ID、名称 和 地址 不能为空！")
      			Exit Sub
    		End If
    		If right(s_url,1)<>"/" Then
      			s_url=s_url&"/"
    		End If
    		Sql="Select count(s_id) From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" and (s_id="&s_id&" or s_name='"&s_name&"')"
    		Set Rs=Cls.Exec(Sql,1)
    		If Rs(0)>0 Then
      			Rs.Close
      			Call AMH_Error(Tit_Fir&"的 ID（"&s_id&"） 和 名称（"&s_name&"） 不能重复！")
      			Exit Sub
    		End If
    		Rs.Close
    		Sql="Select * From "&Data_Name&" Where ChannelIDs="&iChannelIDs
		    Call Cls.Exe_Conn(Rs,SQL,3)
    		Rs.Addnew
    		Rs("s_id")=s_id
    		Rs("ChannelIDs")=iChannelIDs
    		Rs("s_name")=s_name
    		Rs("s_url")=s_url
    		Rs.update
    		Rs.Close
    		Call AMH_Msg("成功添加一条"&Tit_Fir&"（"&s_name&"）信息！","?ChannelIDs="&iChannelIDs,1)
    		Exit Sub
  	End If
  	Call Form_First()
	%>
	<Form name=Add_frm action='?ChannelIDs=<%=iChannelIDs%>&action=Add' method=post>
	<input type=hidden name=Chk value='yes'>
	<tr>
	<td><%Response.Write Tit_Fir%>ID：</td>
	<td><input type=text name=s_id value='<%Response.Write tmp_sid%>' size=10 maxlength=10><%Response.Write redx%>添加后将不可以修改</td>
	</tr>
	<tr>
	<td><%Response.Write Tit_Fir%>名称：</td>
	<td><input type=text name=s_name value='' size=30 maxlength=20><%Response.Write redx%></td>
	</tr>
	<tr>
	<td><%Response.Write Tit_Fir%>地址：</td>
	<td><input type=text name=s_url value='http://' size=50 maxlength=250><%Response.Write redx%></td>
	</tr>
	<%
  	Call Submit_Add()
End Sub

Sub AsaiMHServer_Main()
  	Dim s_id,s_name
	%>
	<table cellspacing=1 cellpAdding=3 class=table0>
	<Form name=sel_Form action='?ChannelIDs=<%=iChannelIDs%>' method=post>
	<tr align=center>
	<td class=td width='10%'><%Response.Write Tit_Fir%>ID</td>
	<td class=td width='25%'><%Response.Write Tit_Fir%>名称</td>
	<td class=td width='50%'><%Response.Write Tit_Fir%>地址</td>
	<td class=td width='15%'>相关操作</td>
	</tr>
	<%
  	Sql="Select * From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" order by s_id"
  	Set Rs=Cls.Exec(Sql,1)
  	Do While not Rs.eof
    		s_id=Rs("s_id")
    		s_name=Rs("s_name")
		%>
		<tr align=center>
		<td><%Response.Write s_id%></td>
		<td align=left><%Response.Write s_name%></td>
		<td align=left><%Response.Write Cls.Code_html(Rs("s_url"),1,30+tnum)%></td>
		<td><a href='?ChannelIDs=<%=iChannelIDs%>&action=Edit&id=<%Response.Write s_id%>'>编辑</a>&nbsp;&nbsp;<a href='?ChannelIDs=<%=iChannelIDs%>&action=del&id=<%Response.Write s_id%>' onclick="javascript:return click_return('删除<%Response.Write Tit_Fir%>（<%Response.Write s_name%>）',0);">删除</a></td>
		</tr>
		<%
    	Rs.Movenext
  	Loop
  	Rs.Close
	%>
     </Form>
	</table>
	<%
End Sub

Sub Server_Select(Case_name)
  	Dim temp,n_id
  	temp="<Select name="&Case_name&" size=1><option value='0'>请先选择...</option>"
  	Sql="Select s_id,s_name From "&Data_Name&" Where ChannelIDs="&iChannelIDs
  	Set Rs=Cls.Exec(Sql,1)
  	Do While not Rs.eof
    	n_id=Int(Rs(0))
    	temp=temp&vbcrlf&"<option value='"&n_id&"'>"&Rs(1)&"</option>"
    	Rs.Movenext
  	Loop
  	Rs.Close
  	Set Rs=nothing
	Response.Write temp&"</Select>"
End Sub

Sub Data_Name_Select()
  	Sql="Select MenuDataName From AsaiMHMenu Where ChannelIDs="&iChannelIDs
    Set Rs=Cls.Exec(Sql,1)
	If not Rs.eof Then
    	n_Data_Name=Rs(0)
	End If
  	Rs.Close
End Sub

'======================================================
%>
