?? index.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>
<a href='PwdChange.asp' onclick="return newwin(this.href)"><font color=red>更改密碼</font></a>
<%
'如果為管理員則顯示類別管理和用戶管理
If Session("UserName") = "Admin" Then
Response.Write " <a href='Cate_Admin.asp'><font color=red>類別管理</font></a>"
Response.Write " <a href='UserList.asp'><font color=red>用戶管理</font></a>"
sql_where = ""
Else
'如果不是系統管理員,則只能管理自己提交的新聞,所以在這里設置WHERE子句的條件
sql_where = " Poster='" & Session("UserName") & "'"
End If
%>
<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>
<input type="button" value="全 選" onclick="sltAll()" id=button1 name=button1>
<input type="button" value="清 空" onclick="sltNull()" id=button2 name=button2>
<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 + -