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

📄 topic.asp

📁 源代码简介: 即时添加
💻 ASP
字号:
<%@ Language=VBScript %>
<% option explicit %>
<!--#include file="conn.asp"-->
<!--#include file="../style.asp"-->
<!--#include file="chkadmin.asp"-->
<% 
dim curaction, curid, bedit, founderr, errmsg
curaction = request("action")
curid = request("id")
bedit = false
founderr = false
if curaction = "edit" then
	bedit = true
end if

dim sql
'删除记录
if curaction = "delete" then
	sql = "DELETE FROM topic WHERE id=" + cstr(curid)
	conn.execute sql
	if err.number <> 0 then
		response.write "数据库操作错误:" + err.description
		err.clear
	else
		response.write "记录已经删除。"
	end if
end if

'添加记录
if curaction = "newsave" then
	if trim(request("txttitle")) = "" then
		founderr = true
		errmsg = "<p>请输入类别!</p>"
	end if
	if founderr then
		response.write errmsg
	else
		sql = "INSERT INTO topic(title) VALUES('"
		sql = sql + cstr(request("txttitle")) + "')"
		conn.execute sql
		if err.number <> 0 then
			response.write "无法保存,数据库操作出错:" + err.description
		else
			response.write "记录已经添加到数据库。"
		end if
	end if
end if

'保存记录
if curaction = "editsave" then
	if trim(request("txttitle")) = "" then
		founderr = true
		errmsg = "<p>请输入类别!</p>"
	end if
	if founderr then
		response.write errmsg
	else
		sql = "UPDATE topic SET "
		sql = sql + "title='" + htmlencode(request("txttitle")) + "'"
		sql = sql + " WHERE id = " + cstr(curid)
		conn.execute sql
		if err.number <> 0 then
			response.write "无法保存,数据库操作出错:" + err.description
		else
			response.write "记录已经更新到数据库。"
		end if
	end if

end if
 %>
<html>
<head>
	<title>易得新闻中心管理系统</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
<!--
td {  font-family: "宋体"; font-size: 9pt}
body {  font-family: "宋体"; font-size: 9pt}
select {  font-family: "宋体"; font-size: 9pt}
A {text-decoration: none; color: #336699; font-family: "宋体"; font-size: 9pt}
A:hover {text-decoration: underline; color: #FF0000; font-family: "宋体"; font-size: 9pt} 
-->
</style>
<script language="javascript">
function confirmDel(id){
if ( confirm("你确定要删除吗?")) {
window.location.href = "topic.asp?action=delete&id=" + id
  }
}

</script>
</head>

<body>
<% 

dim rs
set rs = server.createobject("adodb.recordset")
sql = "SELECT * FROM topic"
rs.open sql, conn, 1, 1
if err.number <> 0 then
	response.write "数据库操作失败:"&err.description
	else
		if rs.eof and rs.bof then
			response.write "没有记录"
		else
 %>

<div align="center">
  <center>

<table width="100%" border="0" cellspacing="1" bgcolor="#000000">
<tr bgcolor=<%= THCOLOR %>>
<td width="70%" bgcolor="#F4CF9D">&nbsp;==&nbsp;类别&nbsp;==</td>
<td width="30%" bgcolor="#F4CF9D" align="center">操&nbsp;&nbsp;&nbsp; 作</td></tr>
<% do while not rs.eof 
dim tdcolor
tdcolor = TDCOLORL
if bedit then
	if clng(rs("id")) = clng(curid) then
		tdcolor = TDCOLORD
	end if
end if%>
<tr bgcolor=<%= tdcolor %>>
<td bgcolor="#FEF7ED">&nbsp;<%= rs("title") %></td>
<td bgcolor="#FEF7ED" align="center"><a href='topic.asp?action=edit&id=<%= cstr(rs("id")) %>'>编辑</a> 
<a href='javascript:confirmDel(<%= rs("id") %>)'>删除</a></td></tr>
<% rs.movenext
loop %>
</table>
  </center>
</div>
<% 
	End If
	rs.close
end if
 %>
<hr>
<% 
if bedit then
	sql = "SELECT * FROM topic WHERE id = " + cstr(curid)
	rs.open sql, conn, 1, 1
end if
 %>
<form action="topic.asp" method="POST">

<div align="center">
  <center>

<table cellspacing="1" border="0" width="482" bgcolor="#000000" height="42">
<tr>
    <td width="468" bgcolor=#F4CF9D colspan="2" height="1"><p align=center><% If bedit then %>专题新闻编辑<% Else  %>专题新闻添加<% End If %></p></td>
</tr>
<tr>
    <td width="42" bgcolor=#FEF7ED height="25">类别:</td>
    <td width="426" bgcolor=#FEF7ED height="25"><input type="Text" name="txttitle" size="50" value='<% If bedit then
	response.write rs("title")
end if
 %>'></td>
</tr>
<tr><td align=center colspan="2" bgcolor=#FEF7ED width="474" height="27">
<input type="Hidden" name="action" value='<% If bedit then%>editsave<% Else  %>newsave<% End If %>'>
<% If bedit then %>
<input type="Hidden" name="id" value='<%= cstr(curid) %>'>
<% End If %>
<input type="Submit" name="btnsave" value="保存">
<input type="Reset" value="取消"></td></tr>
</table>

  </center>
</div>

</form>
<% 
set rs = nothing
call endconnection()
 %>
</body>
</html>

⌨️ 快捷键说明

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