<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="../../inc_asp/conn.asp"-->
<!--#include file="../../inc_asp/comfunc.asp"-->
<%
dim id,newsid,del_id
id=request.form("checkbox")
newsid=request.QueryString("newsid")
act=request("act")
if act="del_news" or request.form("Delnews")<>"" then
	if act="del_news" then
	del_id=newsid
	else
	del_id=id
	end if
	call del_new()
end if
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>资讯文章列表</h2>
<form id="form1" name="form1"  method="post" action="news.asp">
<table border="0" cellspacing="1" cellpadding="0" bgcolor="#CFCFCF" style="width:98%;margin:10px auto;">
  <tr align="center">
    <td width="7%" bgcolor="#FBFCE2">ID</td>
    <td width="3%" bgcolor="#FBFCE2">选择</td>
    <td width="36%" bgcolor="#FBFCE2">标题</td>
    <td width="9%" bgcolor="#FBFCE2">更新时间</td>
    <td width="13%" bgcolor="#FBFCE2">类目</td>
    <td width="14%" bgcolor="#FBFCE2">发布人</td>
    <td width="18%" bgcolor="#FBFCE2">操作</td>
  </tr>
<%
Const MaxPerPage=12
dim totalPut,CurrentPage,TotalPages,j,sql,rsa  
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if 
call openadmin()
set rsa=Server.CreateObject("adodb.recordset")
sql="select * from News t1 left join NewsClass t2 on(t1.News_Type = t2.NewsClass_Id) order by News_Time desc;"
rsa.open sql,conn1,1,1
num=rsa.recordcount 
if rsa.bof and rsa.eof then
response.write"<tr><td align='center' colspan='7'><font color='#ff0000'>暂无记录</font>　【<a href='addnews.asp'>添加记录</a>】</td></tr>"
end if
                    totalPut=rsa.recordcount

      				if currentpage<1 then
          				currentpage=1
      				end if

      				if (currentpage-1)*MaxPerPage>totalput then
	   					if (totalPut mod MaxPerPage)=0 then
	     					currentpage= totalPut \ MaxPerPage
	   					else
	      					currentpage= totalPut \ MaxPerPage + 1
	   					end if
      				end if

       				if currentPage=1 then
            			showContent
            			showpage totalput,MaxPerPage,"news.asp"
       				else
          				if (currentPage-1)*MaxPerPage<totalPut then
            				rsa.move  (currentPage-1)*MaxPerPage
            				dim bookmark
            				bookmark=rsa.bookmark
            				showContent
             				showpage totalput,MaxPerPage,"news.asp"
        				else
	        				currentPage=1
           					showContent
           					showpage totalput,MaxPerPage,"news.asp"
	      				end if
	   				end if

   				sub showContent
       			dim i
	   			i=0
do while not rsa.eof 
%>
  <tr align="center">
    <td bgcolor="#FFFFFF"><%=rsa("News_Id")%></td>
    <td bgcolor="#FFFFFF"><input name="checkbox" type="checkbox" value=<%=rsa("News_Id")%>></td>
    <td align="left" bgcolor="#FFFFFF"><%=rsa("News_Title")%></td>
    <td bgcolor="#FFFFFF"><%=rsa("News_Time")%></td>
    <td bgcolor="#FFFFFF"><%=rsa("NewsClass_Name")%></td>
    <td bgcolor="#FFFFFF"><%=rsa("News_Author")%></td>
    <td bgcolor="#FFFFFF"><a href="modnews.asp?newsid=<%=rsa("News_Id")%>">修改</a> | <a href="news.asp?act=del_news&newsid=<%=rsa("News_Id")%>">删除</a></td>
  </tr>
      <%  i=i+1
		 if i>=MaxPerPage then Exit Do
      rsa.movenext
      loop
      rsa.close
      set rsa=nothing
      %>
      <% call closeadmin() %>
  <tr align="center">
    <td colspan="7" align="left" bgcolor="#FFFFFF"> &nbsp;
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="button" name="button" id="button" onClick="CheckAll();" value="全选" />
    <input type="submit" name="Delnews" id="Delnews" value="删除所选" /></td>
  </tr>
  </form>
  <tr align="center" bgcolor="#F9FCEF">
    <td colspan="7"><%  
				End Sub   
  
				Function showpage(totalnumber,maxperpage,filename)  
  				Dim n
  				
				If totalnumber Mod maxperpage=0 Then  
					n= totalnumber \ maxperpage  
				Else
					n= totalnumber \ maxperpage+1  
				End If %>
                <form action=<%=filename%> method=Post  name="frmpage">
                <div> 共 <% = n %> 页/<%=num%>条记录 <a href="<%=filename%>?page=1">首页</a>&nbsp; 
                <% for p = 1 to n 
						if p=CurrentPage then%>
                        <strong><%=p%></strong>
                        <% else %>
                &nbsp;<a href="<%=filename%>?page=<%=p%>"><%=p%></a>&nbsp; 
                <% end if %>
                <% next %><a href="<%=filename%>?page=<%=n%>">末页</a></div></form>
                 <% End Function %></td>
  </tr>
</table>
</body>
</html>
<%
Sub del_new()
	if del_id="" then
	response.write"<script language='javascript'>"
	response.write"alert('请选择一条记录！');"
	response.write"</script>"
	else
	call openadmin()
	delsql="select * from news where News_Id in("&del_id&")" 
	Set rs=Server.CreateObject("ADODB.RecordSet")
	rs.open delsql,conn1,3,3
	do while not rs.eof
	rs.delete
	rs.update
	rs.movenext 
	loop
	rs.close
	set rs=nothing
	call closeadmin()
	response.write"<script language='javascript'>"
	response.write"alert('删除成功！');location='news.asp';"
	response.write"</script>"
	end if
End Sub
%>
<script type="text/javascript">
    var a;
   function CheckAll(){            
    if(a==1)
    {
    for(var i=0;i<window.document.form1.elements.length;i++)
       {                
          var e = form1.elements[i];
          e.checked =false;                  
       }
       a=0;
   }       
   else
   {
        for(var i=0;i<window.document.form1.elements.length;i++)
       {                
          var e = form1.elements[i];
          e.checked =true;                  
       }
       a=1;
   }     
 }
</script>