<% userPageRights="{plane}" %>
<!--#include file="check.asp"-->
<!--#include file="../Include/Char.asp" -->
<%
'Define Variable 
dim i
dim rs,rst
dim mCityName,mGrade,mSql,mFlag
'initialization 
mFlag=true'add
if request("action")="edit" then mFlag=false

'Insert Records
if request("action")="add" then
  mCityName=Trim(server.htmlencode(request("txtCityName")))
  if Trim(Request.QueryString("grade"))="" then mGrade=1 else mGrade=Cint(Request.QueryString("grade"))
  mSql="insert into Plane_CityType(F_CityName,F_Grade)values('"&mCityName&"',"&mGrade&")"
  conn.execute(mSql)
  response.redirect "CityTypeManage.asp"
end if

'Modify Records
if request("action")="editsave" then
  mCityName=Trim(server.htmlencode(request.form("txtCityName2")))
  mSql="update Plane_CityType set F_CityName='" & mCityName &"' where F_ID="&request.querystring("CityID")
  conn.execute(mSql)
  response.redirect "CityTypeManage.asp"
  flag=false
end if

'Delect Records
if request("action")="delete" then
  mSql = "DELETE FROM Plane_CityType WHERE F_ID=" &Request.QueryString("CityID")
  conn.execute mSql
  Response.Redirect "CityTypeManage.asp"
end if

'Sort Grade Up
If Request.QueryString("action")="up" then
   mSql="update Plane_CityType set F_Grade=F_Grade-1 where F_Grade="&request.querystring("grade")
   conn.execute(mSql)
   mSql="update Plane_CityType set F_Grade=F_Grade+1 where F_Grade="&cint(request.querystring("grade"))-1&" and F_ID<>"&Request.QueryString("F_ID")
   conn.execute(mSql)
   Response.Redirect "CityTypeManage.asp"
 End if

'Sort Grade Down
If Request.QueryString("action")="down" then
   mSql="update Plane_CityType set F_Grade=F_Grade+1 where F_Grade="&request.querystring("grade")
   conn.execute(mSql)
   mSql="update Plane_CityType set F_Grade=F_Grade-1 where F_Grade="&cint(request.querystring("grade"))+1&" and F_ID<>"&Request.QueryString("F_ID")
   conn.execute(mSql)
   Response.Redirect "CityTypeManage.asp"
 End if
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../Files/Style.css" rel="stylesheet" type="text/css">
<SCRIPT language="JavaScript">
function jDelete(url)
{
  if((confirm(" 警告:请确定是否删除,删除后不能恢复! "))==true) 
	self.location=url+'&action=delete';
}
</SCRIPT>
<script language="javascript">
function CheckData(){
  if (document.form1.txtCityName.value=="")
   {
    alert("名称不能为空");
	document.form1.txtCityName.focus();
	return false;
   }
}

function CheckData2(){
  if (document.form2.txtCityName2.value=="")
   {
    alert("名称不能为空");
	document.form2.txtCityName2.focus();
	return false;
   }
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="44%"><b>功能：[城市管理]</b></td>
    <td width="81%" align="right"><a href="CityTypeManage.asp#input">→添加记录</a></td>
  </tr>
</table>
<table width="96%" border="0" cellspacing="1" cellpadding="1" align="center">
  <tr bgcolor="#CCCCCC" align="center"> 
    <td height="11" width="6%"><b><font color="#FFFFFF">ID</font></b></td>
    <td width="6%" height="11"><b><font color="#FFFFFF">新序</font></b></td>
    <td width="11%"><b><font color="#FFFFFF">城市名称</font></b></td>
    <td width="12%"><b><font color="#FFFFFF">排序</font></b></td>
    <td height="11" width="14%"><b><font color="#FFFFFF">管理</font></b></td>
  </tr>
</table>
<%  
    set rs=server.createobject("ADODB.recordset")
    mSql="select * from Plane_CityType order by F_Grade"
    rs.open mSql,conn,1,1
	if rs.eof then
      response.write "<p align=center><font color=red><B> 暂无记录！</B></font></p>"
    else
      for i=1 to rs.recordcount 
%>
<table width="96%" border="0" cellspacing="1" cellpadding="1" align="center">
  <tr bgcolor="f2f2f2"> 
    <td height="2" width="6%" align="center"><%=rs("F_ID")%></td>
    <td width="6%" height="2" align="center" bgcolor="f2f2f2"><%=i%> </td>
    <td width="11%" align="center" bgcolor="f2f2f2"><%=rs("F_CityName")%></td>
    <td width="12%" align="center" bgcolor="f2f2f2"> 
      <%
	 if i=1 then 
	    Response.write "拉上"
	  else
		Response.write "<a href='CityTypeManage.asp?action=up&F_ID="&rs("F_ID")&"&grade="&i&"'>拉上</a>"
      end if
	  Response.write "|"
	  if i=rs.recordcount then 
	    response.write "拉下"
	  else
		response.write "<a href='CityTypeManage.asp?action=down&F_ID="&rs("F_ID")&"&grade="&i&"'>拉下</a>"
      end if
	%>
    </td>
    <td height="2" width="14%" align="center"> 
	<a href="javascript:jDelete('CityTypeManage.asp?CityID=<%=rs("F_ID")%>&Page=<%=cstr(pageno)%>')">删除</a> 
      | <a href='CityTypeManage.asp?action=edit&CityName=<%=rs("F_CityName")%>&CityID=<%=rs("F_ID")%>&Page=<%=cstr(pageno)%>#edit'>编辑</a> 
    </td>
  </tr>
</table>
 <%
  rs.movenext
  Next 
 %>
<hr size="1" width="96%"><br>
<%
 end if
 if mFlag=true then'add
%>
<a name="input"></a>
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center" height="54">
  <tr> 
    <form name="form1" method="post" action="CityTypeManage.asp?action=add&grade=<%=i%>" onSubmit="return CheckData()">
      <td> 
        <table width="100%" border="0" cellspacing="0" cellpadding="0" height="32">
          <tr> 
            <td height="6"><b>功能：[添加记录]</b></td>
          </tr>
          <tr>
            <td height="7">城市名称： 
              <input name="txtCityName" type="text" id="txtCityName" style="width:300;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" value="" size="54" maxlength="20">
              <br>
            </td>
          </tr>
          <tr> 
            <td height="33"> 
              <input type="submit" value="提交信息" name="B3" style="width:80;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff">
              &nbsp; 
              <input type="reset" value="从新来过" name="B3" style="width:80;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff">
            </td>
          </tr>
        </table>
      </td>
    </form>
  </tr>
</table>
<%else%>
<a name="edit"></a>
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center" height="54">
  <tr> 
    <form name="form2" method="post" action="CityTypeManage.asp?action=editsave&CityID=<%=request("CityID")%>" onSubmit="return CheckData2()">
      <td> 
        <table width="100%" border="0" cellspacing="0" cellpadding="0" height="32">
          <tr> 
            <td height="6"><b>功能：[修改记录]</b></td>
          </tr>
          <tr>
            <td height="7">城市名称： 
              <input name="txtCityName2" type="text" id="txtCityName2" style="width:300;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" value="<%=request("CityName")%>" size="54" maxlength="20">
              <br>
            </td>
          </tr>
          <tr> 
            <td height="35"> 
              <input type="submit" value="提交信息" name="B32" style="width:80;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff">
              &nbsp; 
              <input type="reset" value="从新来过" name="B32" style="width:80;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff">
            </td>
          </tr>
        </table>
      </td>
    </form>
  </tr>
</table>
<%end if%>
</body>
</html>
