<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Global/oftenMeasures.asp"-->
<!--#include file="../Conn/conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" href="../css/indexTwo.css" type="text/css">
<title><%=backstageTitle%></title>
</head>
<script type="text/javascript" src="../js/List.js"></script>
<body>
<%
SortID=request("SortID")
SortName=""
if request("action")="DelOne" then
	NewsID=request("NewsID")
	sql="select id,Picture from TbNews where id="&NewsID
	rs.open sql,conn,1,3
	if not rs.eof then
		DeleteOneFile(rs("Picture"))
		rs.delete
		rs.update
	end if
	rs.close
	response.write "<script> alert('删除成功');window.document.location.href='?SortID="&SortID&"';   </script>"
end if
if request("action")="list_del" then
	id=request.Form("id")
	if id="" then
		response.write "<script> alert('请选择信息，不得少于1条');window.document.location.href='?SortID="&SortID&"';   </script>"
		response.End()
	else
		sql="select id from TbNews where id in("&id&")"
		rs.open sql,conn,1,1
		if not rs.eof then
			do while not rs.eof
				sql2="select id,Picture from TbNews where id="&rs("id")
				rs2.open sql2,conn,1,3
				if not rs2.eof then
					DeleteOneFile(rs2("Picture"))
					rs2.delete
					rs2.update
				end if
				rs2.close
				rs.movenext
			loop
		end if
		rs.close
		response.Redirect("?SortID="&SortID&"")
		response.End()
	end if
end if

if request("action")="issd" then
	NewsID=request("NewsID")
	sql="select id,issd from TbNews where issd=1"
	rs.open sql,conn,1,3
	if not rs.eof then
		rs("issd")=0
		rs.update
	end if
	rs.close
	sql="select id,issd from TbNews where id="&NewsID
	rs.open sql,conn,1,3
	if not rs.eof then
		rs("issd")=1
		rs.update
	end if
	rs.close
	response.write "<script> alert('设置成功');window.document.location.href='?SortID="&SortID&"';   </script>"
end if

'上移动
if request("movetype")="up" then
	currentID=request("newsidMove")
	currentOrder=request("newsOrderMove")
	'判断当前条记录是否为第一条，如果不是第一条就取出上一条记录的ID和顺序序号
	sql="select top 1 * from TbNews where Sort ="&SortID&" and [order]>"&clng(currentOrder)&" order by [order] asc"
	rs.open sql,conn,1,3
	if rs.eof then
		response.Write("已经时最上面一条了，不能再上移动了")
	else
		upid=rs("ID")
		uporder=rs("order")
		rs("order")=clng(currentOrder)
		rs.update
	end if
	rs.close
	'更新当前记录的顺序序号为上一条记录的顺序序号
	sql="select top 1 * from TbNews where Sort ="&SortID&" and ID="&clng(currentID)
	rs.open sql,conn,1,3
	if rs.eof then
		response.Write("出现错误，无法找到当前记录")
	else
		rs("order")=clng(uporder)
		rs.update
	end if	
	rs.close
end if

'下移动
if request("movetype")="down" then
	currentID=request("newsidMove")
	currentOrder=request("newsOrderMove")
	'判断当前条记录是否为最后一条，如果不是最后一条就取出下一条记录的ID和顺序序号
	sql="select top 1 * from TbNews where Sort ="&SortID&" and [order]<"&clng(currentOrder)&" order by [order] desc"
	rs.open sql,conn,1,3
	if rs.eof then
		response.Write("已经时最下面一条了，不能再上移动了")
	else
		nextid=rs("ID")
		nextorder=rs("order")
		rs("order")=clng(currentOrder)
		rs.update
	end if
	rs.close
	'更新当前记录的顺序序号为上一条记录的顺序序号
	sql="select top 1 * from TbNews   where Sort ="&SortID&" and ID="&clng(currentID)
	rs.open sql,conn,1,3
	if rs.eof then
		response.Write("出现错误，无法找到当前记录")
	else
		rs("order")=clng(nextorder)
		rs.update
	end if	
	rs.close
end if


sql="select * from TbNewsSort where id="&SortID
rs.open sql,conn,1,1
if not rs.eof then
	SortName=rs("name")
end if
rs.close
sql="select * from TbNewsSet where id=7"
rs.open sql,conn,1,1
if not rs.eof then
	NewsBack=rs("mode")
end if
rs.close

%>
<table width="100%" border="0" cellspacing="1" class="Navi2">
  <tr>
    <th colspan="2"><%=SortName&"——"%>列表</th>
	<th><a href="News_Add.asp?SortID=<%=SortID%>" class="link2">添加</a>
	<%
	if NewsBack=1 then
		response.Write("&nbsp;&nbsp;&nbsp;&nbsp;<a href='News_Manager_Sort.asp' class='link2'>返回</a>")
	end if
	%>	
	</th>
  </tr>
</table>
<FORM method="POST" name="from" action="">
<input type="hidden" name="SortID" value="<%=SortID%>" />
  <table width="100%" border="0" cellspacing="1" class="Navi2">
    <tr>
      <td style="text-align:center">&nbsp;</td>
      <td style="text-align:center">新闻标题</td>
      <td style="text-align:center">加入时间</td>
      <td style="text-align:center">上移</td>
	  <td style="text-align:center">下移</td>
      <td style="text-align:center">操作</td>
    </tr>
	<%
	'sql_parameter    查询内容，为空侧表示查询内容为*
	'sql_table        数据库中的表,不能为空
	'sql_terms        查询条件，为空则表示无条件
	'sql_in           in语句参数，空为ID
	'sql_order        排列方式，为空则表示 id desc
	'sql_pagesize     每页的尺寸，为空20条
	'file_name        文件名，为空表示当前页
	'file_terms       文件后的条件，为空表示无条件
	'getList(sql_parameter,sql_table,sql_terms,sql_in,sql_order,sql_pagesize,file_name,file_terms)
	call getList("id,title,order,Sdate,sort,Picture,issd","TbNews","sort="&SortID&"","","[order] desc","","","SortID="&SortID&"")
	%>
    <tr>
	<th colspan="6" align="left">
	<a href="#" style="text-decoration:none;color:red;" onClick="checkAll('id')">全选&nbsp; &nbsp;</a>
	<a href="#" style="text-decoration:none;color:red;" onClick="unCheckAll('id')">全不选&nbsp; &nbsp;</a>
	<a href="#" style="text-decoration:none;color:red;" onClick="switchAll('id')">反选</a> &nbsp;&nbsp;
	<a href="#" style="text-decoration:none;color:red;" onClick="return deleteWarntwo();">删除选中的新闻</a>&nbsp;&nbsp;	</th>
  </tr>
  </table>
</FORM>
</body>
</html>
<!--#include file="../Conn/conn_close.asp"-->
<%
sub showList(page,maxpage,pagesize,record,file_name,file_terms)
	do while not rs.eof
		response.Write("<tr onmouseout=""style.backgroundColor=''"" onMouseover=""style.backgroundColor='#bfdfff'"">")
		response.Write("  <td style='width:10px;'><input type='checkbox' name='id' value='"&rs("id")&"' /></td>")
		response.Write("<td>"&rs("title"))
		if rs("Picture")<>"" then
			response.Write("&nbsp;&nbsp;<img src='../../"&rs("Picture")&"' width='20' height='20'>")
		end if
		response.Write("</td>")
		response.Write("<td style='text-align:center;'>"&rs("Sdate")&"</td>")
		response.Write("<td style='text-align:center;'>")
		call ShowUp(rs("id"),rs("sort"),rs("order"))
		response.Write("</td>")
		response.Write("<td style='text-align:center;'>")
		call ShowDown(rs("id"),rs("sort"),rs("order"))
		response.Write("</td>")
		response.Write("<td style='text-align:center;'>")
		if SortID=5 or SortID=6 or SortID=7 or SortID=8 then
			if rs("issd")=1 then
				response.Write("<a href='?action=issd&SortID="&SortID&"&NewsID="&rs("id")&"' class='hong'>已设为首页显图</a>")
				response.Write("&nbsp;&nbsp;")
			else
				response.Write("<a href='?action=issd&SortID="&SortID&"&NewsID="&rs("id")&"' class='link2'>首页显图</a>")
				response.Write("&nbsp;&nbsp;")
			end if
		end if
		response.Write("<img src='../images/icon_edit.gif' >&nbsp;")
		response.Write("<a href='News_Edit.asp?NewsID="&rs("id")&"' class='link2'>修改</a>")
		response.Write("&nbsp;&nbsp;")
		response.Write("<img src='../images/icon_dele.gif' >&nbsp;")
		response.Write("<a href='?NewsID="&rs("id")&"&SortID="&SortID&"&action=DelOne' class='link2'>删除</a></td>")
		response.Write("</tr>")
		rs.movenext
    loop	
	response.Write("<tr>")
	response.Write("<td colspan='6' height='40' valign='bottom' style='text-align:center;'>")
	if file_terms<>"" then
		urlFrist=file_name&"?pages=1&"&file_terms
		urlup=file_name&"?pages="&(page-1)&"&"&file_terms
		urlnext=file_name&"?pages="&(page+1)&"&"&file_terms
		urlend=file_name&"?pages="&maxpage&"&"&file_terms
	else
		urlFrist=file_name&"?pages=1"
		urlup=file_name&"?pages="&(page-1)
		urlnext=file_name&"?pages="&(page+1)
		urlend=file_name&"?pages="&maxpage
	end if
	
	response.Write("<a href="&urlFrist&" class='link2'>首页 </a>")
	if page>1 then
    	response.Write("&nbsp;<a href="&urlup&" class='link2'>上页</a>")
	else
		response.Write("&nbsp;<a href='#' class='link2'>上页</a>")
    end if
    if page<maxpage then
        response.Write("&nbsp;<a href="&urlnext&" class='link2'>下页</a>")
	else
		 response.Write("&nbsp;<a href='#' class='link2'>下页</a>")
    end if
	response.Write("&nbsp;<a href="&urlend&" class='link2'>尾页</a>")	
	response.Write("&nbsp;页次:"&page&"/"&maxpage&"")
	response.Write("&nbsp;每页:"&pagesize&"记录")
	response.Write("&nbsp;共有:"&record&"条记录")
	response.Write("</td></tr>")
end sub
sub ShowUp(NewsID,SortID,NewsOrder)
	sql2="select top 1 * from TbNews where  Sort ="&SortID&" and [order]>"&NewsOrder&" order by [order] asc"
	rs2.open sql2,conn,1,1
	if not rs2.eof then
		response.Write("<a href='?SortID="&SortID&"&movetype=up&newsidMove="&NewsID&"&newsOrderMove="&NewsOrder&"' class='link2'>↑</a>")	
	end if
	rs2.close
end sub
sub ShowDown(NewsID,SortID,NewsOrder)
	sql2="select top 1 * from TbNews where  Sort ="&SortID&" and [order]<"&NewsOrder&" order by [order] asc"
	rs2.open sql2,conn,1,1
	if not rs2.eof then
		response.Write("<a href='?SortID="&SortID&"&movetype=down&newsidMove="&NewsID&"&newsOrderMove="&NewsOrder&"' class='link2'>↓</a>")	
	end if
	rs2.close
end sub
%>
