⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.asp

📁 ASP入门与提高实用教程 源文件(上传网站)
💻 ASP
字号:
<!--#include file="ConnDB.asp"-->
<!--#include file="ChkPwd.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻管理</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<link rel="stylesheet" href="style.css">
<script language="javascript">
function newwin(url) {
  var wth=window.screen.width; 
  var hth=window.screen.heigth;
  var lefth;
  var topth;
  if(wth==1024)  {
	  hth=600;
	  lefth =147;
	  wth=600;
	  topth=44;
   }
  else if(wth==800)	  {
	  hth=500;
	  lefth =35;
	  wth=500;
	  topth=10;
	}
  else	{
	  hth=600;
	  wth=500;
	}
  var oth="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left="+lefth+",top="+topth;
  oth = oth+",width="+wth+",height="+hth ;
  var newwin=window.open(url,"newwin",oth);
  newwin.focus();
  return false;
}

//检查选择的新闻,并执行删除操作
function selectChk()
{
  var s = false; //用来记录是否存在被选中的复选框
  var Newsid, n=0; 
  var strid, strurl;
  var nn = self.document.all.item("News"); //返回复选框Cate的数量
  for (j=0; j<nn.length; j++) {
    if (self.document.all.item("News",j).checked) {
      n = n + 1;
      s = true;
      Newsid = self.document.all.item("News",j).id+"";  //转换为字符串
      //生成要删除新闻编号的列表
      if(n==1) {
        strid = Newsid;
      }
      else {
        strid = strid + "," + Newsid;
      }
    }
  }
  strurl = "NewsDelt.asp?id=" + strid;
  if(!s) {
    alert("请选择要删除的新闻!");
    return false;
  }	
  if (confirm("你确定要删除这些新闻吗?")) {
    form1.action = strurl;
    form1.submit();
  }
}
function sltAll()
{
	var nn = self.document.all.item("Cate");
	for(j=0;j<nn.length;j++)
	{
		self.document.all.item("Cate",j).checked = true;
	}
}
function sltNull()
{
	var nn = self.document.all.item("Cate");
	for(j=0;j<nn.length;j++)
	{
		self.document.all.item("Cate",j).checked = false;
	}
}
</script>
</head>

<body link="#000080" vlink="#080080">
<form id="form1" name="form1" method="POST">
<p align=center><font style='FONT-SIZE:12pt' color=red><b>新 闻 管 理</b></font></p>
<table align=center border='0' width='100%'>
<tr><td align='left'><a href='index.asp'>全部新闻</a>
<%                                                
  Dim rs,rsCate
  Set rs = Server.CreateObject("ADODB.RecordSet")
  set rsCate = Server.CreateObject("ADODB.RecordSet")
  '定义变量
  Dim iflag,sql_where
  '参数flag表示指定的新闻类别  
  iflag = Request.QueryString("flag")
  '设置SQL语句,读取所有的新闻类别到rs.Cate
  sql = "SELECT * FROM Category ORDER BY CateId"
  Set rsCate = conn.Execute(sql)
  '显示新闻类别链接,注意根据类别编号设置参数flag
  DO WHILE Not rsCate.EOF
    stitle = rsCate("CateName")
    cid = rsCate("CateId")  
%> | <a href='index.asp?flag=<%=cid%>'><font style='TEXT-DECORATION: none;color:black'><%=stitle%></font></a>                                                                                              
<%                                                 
    rsCate.MoveNext                                               
  Loop
%></td><td align=right>
<a href='search.asp'><font color=red>新闻查询</font></a> 
&nbsp;&nbsp;<a href='PwdChange.asp' onclick="return newwin(this.href)"><font color=red>更改密码</font></a> 

<%                                                                             
  '如果为管理员则显示类别管理和用户管理
  If Session("UserName") = "Admin" Then
    Response.Write "&nbsp;&nbsp;<a href='Cate_Admin.asp'><font color=red>类别管理</font></a>"
    Response.Write "&nbsp;&nbsp;&nbsp;<a href='UserList.asp'><font color=red>用户管理</font></a>"
    sql_where = ""
  Else
    '如果不是系统管理员,则只能管理自己提交的新闻,所以在这里设置WHERE子句的条件
    sql_where = " Poster='" & Session("UserName") & "'"
  End If
%>
&nbsp;&nbsp;<a href='logout.asp'><font color=red>退出登录</font></a>                                                       
</td>
  </tr>
</table>
<table align=center border="1" cellspacing="0" width="100%" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" style='FONT-SIZE: 9pt'>
  <tr>
   <td width="56%" align="center" bgcolor="#FEEC85"><strong>题 目</strong></td>
   <td width="24%" align="center" bgcolor="#FEEC85"><strong>时 间</strong></td>
   <td width="10%" align="center"  bgcolor="#FEEC85"><strong>修 改</strong></td>
   <td width="10%" align="center"  bgcolor="#FEEC85"><strong>选择</td>
  </tr>
<%
  '根据参数iflag和sql_where变量设置SQL语句,读取新闻数据
  If iflag = "" Then
    If sql_where = "" Then
      sql = "SELECT * FROM News ORDER BY Posttime DESC"
    Else
      sql = "SELECT * FROM News WHERE " & sql_where & " ORDER BY Posttime DESC"
    End If  	
  Else
    If sql_where = "" then
      sql = "SELECT * FROM News WHERE CateId=" & iflag & " ORDER BY Posttime DESC"
    Else
      sql = "SELECT * FROM News WHERE CateId=" & iflag & " And " & sql_where & " ORDER BY Posttime DESC"
    End If 
  End If 	
  rs.Open sql,conn,1,1
  '如果记录集rs为空,则显示“目录还没有记录”
  If rs.EOF Then
    Response.Write "<tr><td colspan=4 align=center>目前还没有记录。</td></tr></table>"
  Else
    '设置分页显示,每页显示20条新闻记录
	rs.PageSize = 20
	'读取参数page,表示当前的页码,使用CLng将其转换为长整型
    Page = CLng(Request("Page"))
    '处理不合法的页码
    If Page < 1 Then Page = 1
    If Page > rs.PageCount Then Page = rs.PageCount
    '设置当前页码为Page
	rs.AbsolutePage = Page
	'循环显示当前页的记录
    For i = 1 to rs.PageSize
      '如果到达记录集结尾,则跳出循环
      if rs.EOF then Exit For
%>
  <tr><td><a href="newsView.asp?id=<%=rs("id")%>" onClick="return newwin(this.href)"><%=rs("title")%></a>
    <%If rs("attpic")=true then  Response.write "(附图)" End If%></td>
	<td align="center"><%=rs("posttime")%></td>
    <td align="center"><a href="newsedit.asp?id=<%=rs("id")%>" onClick="return newwin(this.href)">修 改</a></td>
    <td align="center"><input type="checkbox" name="News" id="<%=rs("id")%>" style="font-size: 9pt" value="ON"></td>
  </tr>
<%
      rs.MoveNext()
    Next
%>
</table>
<% '显示分页页码
    If rs.pagecount>1 then
      Response.Write "<table border='0'><tr><td><b>分页:</b></td>"
      For i = 1 To rs.PageCount
        Response.Write "<td><a href='index.asp?flag=" & iflag & "&page=" & i & "'>"
        Response.Write "[<b>" & i & "</b>]</a></td>"
      Next
      Response.Write "</tr></table>"
    End If
  End If
%>
		
		<p align="center">
		<input type="button" value="添加新闻" onclick="newwin('NewsAdd.asp')" name=add>
		 &nbsp;&nbsp;<input type="button" value="全 选" onclick="sltAll()" id=button1 name=button1>
		 &nbsp;&nbsp;<input type="button" value="清 空" onclick="sltNull()" id=button2 name=button2>
		 &nbsp;&nbsp;<input type="submit" value="删 除" name="tijiao" onclick="selectChk()"></p>

<br><br>
<input type=hidden name="News">                               
<p align=center><a href="default.asp">[返回新闻中心]</a></p>
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -