<!--#include file="../../Conn.asp" -->
<!--#include file="../../Comm/Site_Class.asp" -->
<%
PagePath = "../../"

Set Qsite = New Site_Class

Qsite.SiteConfig_Master()
%>
<!--#include file="../Check_Login.asp" -->
<%
Qsite.Check_AdminFlag(arrAdminFlag(0 , 6))

If Request.Form <> "" Then
	If Request.Form("PoliticalId") = 0 Then
		SaveNewPolitical()
	Else
		SaveEditPolitical()
	End If
End If

If Request.QueryString("action") = "del" Then
	DelPolitical(Qsite.chgStr(Trim(Request.QueryString("PoliticalId"))))
ElseIf Request.QueryString("action") = "up" Then
	UpPx(Qsite.chgStr(Trim(Request.QueryString("PoliticalId"))))
ElseIf Request.QueryString("action") = "down" Then
	DownPx(Qsite.chgStr(Trim(Request.QueryString("PoliticalId"))))
End If

Sub SaveNewPolitical()
	Dim PoliticalName,Px
	PoliticalName = Qsite.chgStr(Trim(Request.Form("PoliticalName")))
	Px = Qsite.chgStr(Trim(Request.Form("Px")))
	
	If PoliticalName = "" Or IsNull(PoliticalName) Then
		Qsite.ShowMsg "请输入政治面貌名称" , ""
	End If

	If Px = "" Or IsNull(Px) Or Not IsNumeric(Px) Then Px = 1
	
	Set Rs = Conn.Execute("select PoliticalName from PoliticalTbl where PoliticalName = '"& PoliticalName &"'")
	If Not Rs.Eof Then
		Qsite.ShowMsg "政治面貌已经存在，请返回重新输入" , ""
	End If
	Set Rs = Nothing
	
	Conn.Execute("update PoliticalTbl set Px = Px + 1 where Px >= "& Px)
	
	Conn.Execute("insert into PoliticalTbl (PoliticalName , Px) values ('"& PoliticalName &"' , "& Px &")")
	
	Qsite.ShowMsg "政治面貌添加成功" , "Admin_Political.asp"
End Sub

Sub SaveEditPolitical()
	Dim PoliticalId,PoliticalName,Px
	Dim OldPx
	PoliticalId = Qsite.chgStr(Trim(Request.Form("PoliticalId")))
	PoliticalName = Qsite.chgStr(Trim(Request.Form("PoliticalName")))
	Px = Qsite.chgStr(Trim(Request.Form("Px")))
	
	If PoliticalId = "" Or IsNull(PoliticalId) Or Not IsNumeric(PoliticalId) Then PoliticalId = 0
	
	If PoliticalName = "" Or IsNull(PoliticalName) Then
		Qsite.ShowMsg "请输入政治面貌名称" , ""
	End If
	
	If Px = "" Or IsNull(Px) Or Not IsNumeric(Px) Then Px = 1
	
	Set Rs = Conn.Execute("select PoliticalName from PoliticalTbl where PoliticalName = '"& PoliticalName &"' and PoliticalId <> "& PoliticalId)
	If Not Rs.Eof Then
		Qsite.ShowMsg "政治面貌已经存在，请返回重新输入" , ""
	End If
	Set Rs = Nothing
	
	Set Rs = Conn.Execute("select Px from PoliticalTbl where PoliticalId = "& PoliticalId)
	If Rs.Eof Then
		OldPx = Px
	Else
		OldPx = Rs("Px")
	End If
	
	If Cint(Px) > Cint(OldPx) Then
		Conn.Execute("update PoliticalTbl set Px = Px - 1 where Px > "& OldPx &" and Px <= "& Px)
	ElseIf Cint(Px) < Cint(OldPx) Then
		Conn.Execute("update PoliticalTbl set Px = Px + 1 where Px >= "& Px &" and Px < "& OldPx)
	End If
	
	Conn.Execute("update PoliticalTbl set PoliticalName = '"& PoliticalName &"' , Px = "& Px &" where PoliticalId = "& PoliticalId)
	
	Qsite.ShowMsg "政治面貌修改成功" , "Admin_Political.asp"
End Sub

Sub DelPolitical(PoliticalId)
	Dim OldPx,Rs,dKey
	Dim IncludePoliticalId
	
	If PoliticalId = "" Or IsNull(PoliticalId) Or Not IsNumeric(PoliticalId) Then PoliticalId = 0
	
	Set Rs = Conn.Execute("select Px from PoliticalTbl where PoliticalId = "& PoliticalId)
	If Rs.Eof Then
		OldPx = 9999
	Else
		OldPx = Rs("Px")
	End If
	Set Rs = Nothing
	
	Conn.Execute("delete from PoliticalTbl where PoliticalId =" & PoliticalId)
	
	Conn.Execute("update PoliticalTbl set Px = Px - 1 where Px > "& OldPx)
	
	Qsite.ShowMsg "政治面貌删除成功" , "Admin_Political.asp"
End Sub

Sub UpPx(PoliticalId)
	Dim OldPx
	
	If PoliticalId = "" Or IsNull(PoliticalId) Or Not IsNumeric(PoliticalId) Then PoliticalId = 0
	
	Set Rs = Conn.Execute("select Px from PoliticalTbl where PoliticalId = "& PoliticalId)
	If Rs.Eof Then
		OldPx = 1
	Else
		OldPx = Rs("Px")
	End If
	Set Rs = Nothing
	
	If Cint(OldPx) > 1 Then
		Conn.Execute("update PoliticalTbl set Px = Px + 1 where Px = "& OldPx - 1)
		Conn.Execute("update PoliticalTbl set Px = Px - 1 where PoliticalId = "& PoliticalId)
	End If
	
	Response.Redirect("Admin_Political.asp")
	Response.End()
End Sub

Sub DownPx(PoliticalId)
	Dim maxPx,OldPx
	
	If PoliticalId = "" Or IsNull(PoliticalId) Or Not IsNumeric(PoliticalId) Then PoliticalId = 0
	
	Set Rs = Conn.Execute("select Px from PoliticalTbl where PoliticalId = "& PoliticalId)
	If Rs.Eof Then
		OldPx = 9999
	Else
		OldPx = Rs("Px")
	End If
	Set Rs = Nothing
	
	Set Rs = Conn.Execute("select top 1 Px from PoliticalTbl order by Px desc")
	If Rs.Eof Then
		maxPx = 9999
	Else
		maxPx = Rs("Px")
	End If
	Set Rs = Nothing
	
	If Cint(OldPx) < Cint(maxPx) Then
		Conn.Execute("update PoliticalTbl set Px = Px - 1 where Px = "& OldPx + 1)
		Conn.Execute("update PoliticalTbl set Px = Px + 1 where PoliticalId = "& PoliticalId)
	End If
	
	Response.Redirect("Admin_Political.asp")
	Response.End()
End Sub

Dim PoliticalId,PoliticalName,PoliticalKey,Px,contPx
Dim strTitle,strSubmit

Set Rs = server.createobject("ADODB.Recordset")

Sql = "select * from PoliticalTbl order by Px asc"

Rs.Open "select top 1 * from PoliticalTbl order by Px desc" , Conn ,1 , 1
If Rs.Eof Then
	contPx = 1
Else
	contPx = Rs("Px") + 1
End If
Rs.Close
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>政治面貌管理</title>
<link href="../skins/css/main.css" rel="stylesheet" type="text/css">
<script language="javascript">
function PosDel(PoliticalId)
{
	var question = confirm("你确定要删除此条记录吗？");
	if (question !="0")
	{
		location.href = "Admin_Political.asp?action=del&PoliticalId=" + PoliticalId;
	}
}
</script>
</head>

<body>
<%
PoliticalId = Qsite.chgStr(Trim(Request.QueryString("PoliticalId")))

If PoliticalId = "" Or IsNull(PoliticalId) Or Not IsNumeric(PoliticalId) Then PoliticalId = 0

If PoliticalId = 0 Then
	PoliticalName = ""
	Px = contPx
	strTitle = "添加政治面貌"
	strSubmit = "添加"
Else
	Rs.Open "select * from PoliticalTbl where PoliticalId = "& PoliticalId , Conn , 1 , 1
	If Rs.Eof Then
		PoliticalId = 0
		PoliticalName = ""
		Px = contPx
		strTitle = "添加政治面貌"
		strSubmit = "添加"
	Else
		PoliticalName = Rs("PoliticalName")
		Px = Rs("Px")
		strTitle = "修改政治面貌"
		strSubmit = "修改"
	End If
End If
%>
<form name="PosForm" method="post" action="Admin_Political.asp" style="margin:0">
	<table width="100%" border="0" cellspacing="1" cellpadding="5">
		<tr>
			<td height="25" class="td_title"><%=strTitle%></td>
		</tr>
		<tr>
			<td height="23" class="td_content">政治面貌名称：
				<input name="PoliticalName" type="text" class="input_1" id="PoliticalName" size="50" value="<%=PoliticalName%>">
排序
<input name="Px" type="text" class="input_1" id="Px" size="20" value="<%=Px%>">			
	<input name="Submit" type="submit" class="input_1" value="<%=strSubmit%>">
	<%
	If PoliticalId <> 0 Then
	%>
	<input name="Submit" type="button" class="input_1" value="返回" onClick="javascript:history.back();">
	<%
	End If
	%>
	<input name="PoliticalId" type="hidden" id="PoliticalId" value="<%=PoliticalId%>"></td>
		</tr>
	</table>
	<br>
</form>
<%
If PoliticalId = 0 Then
%>
	<table width="100%" border="0" cellspacing="1" cellpadding="5">
		<tr>
			<td height="25" colspan="2" class="td_title">政治面貌列表</td>
		</tr>
<%
Rs.Open Sql , Conn , 1 , 1
If Rs.Eof Then
%>
		<tr>
			<td height="23" colspan="2" class="td_content">暂无政治面貌信息</td>
		</tr>
<%
Else
%>
		<tr>
<%
	i = 0
	Do While Not Rs.Eof
%>
			<td width="50%" height="23" class="td_content"><%=Rs("PoliticalName")%> &nbsp;&nbsp;&nbsp;[<a href="Admin_Political.asp?action=up&PoliticalId=<%=Rs("PoliticalId")%>">前移</a> | <a href="Admin_Political.asp?action=down&PoliticalId=<%=Rs("PoliticalId")%>">后移</a> | <a href="Admin_Political.asp?PoliticalId=<%=Rs("PoliticalId")%>">修改</a> | <a href="#" onClick="PosDel('<%=Rs("PoliticalId")%>');return false;">删除</a>]</td>
<%
	Rs.MoveNext
	i = i + 1
	If i Mod 2 = 0 And Not Rs.Eof Then
		Response.Write("</tr></tr>")
	End If
	If i Mod 2 > 0 And Rs.Eof Then
		Response.Write("<td width=""50%"" class=""td_content"">&nbsp;</td>")
	End If
	Loop
%>
			
		</tr>
<%
End If
Rs.Close

Set Rs = Nothing
%>
</table>
<%
End If
%>
</body>
</html>
