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

📄 sort_ok.asp

📁 这《ASP网络编程从入门到精通》书中的全部源程序
💻 ASP
字号:

<!--#include file="conn.asp"-->
<%
if session("admin")="" then				'用户没有登录
	'给出提示,返回到登录界面
	response.write "<Script>window.alert('您目前还没有登录,请先登录!');location.replace('index.asp');</Script>"
end if
action = request("action")				'读取action 的值
select case action					'select条件语句

case "add"						'action 的值为add
	show=request.form("show")			'是否首页显示
	sort_id=request.form("sort_id")			'上级ID
	set rs=server.createobject("adodb.recordset")	'创建RecordSet 对象
	'从数据库中查询id 为空的记录,将结果保存在rs 中
	rs.open "select * from sort where id is null",conn,1,3
	rs.addnew					'添加新记录
	rs("sort")=request.form("sort")			'分类名称

	if show="" then					'首页显示,0为首页不显示,1为首页显示
		rs("show")="0"
	else
		rs("show")=show
	end If

	if sort_id="" then				'上级ID的值,为空表示最上层分类
		rs("sort_id")="0"
	else
		rs("sort_id")=sort_id
	end If
	rs.update					'更新数据库
	rs.close					'关闭RecordSet 对象
	set rs=nothing
	if sort_id="" or sort_id = "0" then		'判断sort_id 的值,并根据sort_id 的值返回到不同的界面
		response.write "<Script>window.alert('分类添加成功');location.replace('sort_manage.asp');</Script>"
	else
		response.write "<Script>window.alert('分类添加成功');location.replace('sort.asp?sort_id="&sort_id&"');</Script>"
	end If

case "edit"						'action 的值为edit
	show=request.form("show")			'是否首页显示
	sort_id=request.form("sort_id")			'上级ID

	set rs=server.createobject("adodb.recordset")	'创建RecordSet 对象
	'从数据库中查询id 列的值为request.form("id")的记录,将结果保存在rs 中
	rs.open "select * from sort where id="&request.form("id"),conn,1,3

	rs("sort")=request.form("sort")			'分类名称
	if show="" then					'首页显示,0为首页不显示,1为首页显示
		rs("show")="0"
	else
		rs("show")=show
	end If
	if sort_id="" then				'上级ID的值,为空表示最上层分类
		rs("sort_id")="0"
	else
		rs("sort_id")=sort_id
	end If
	rs.update					'更新数据库
	rs.close					'关闭RecordSet 对象
	if sort_id="0" then				'判断sort_id 的值,并根据sort_id 的值返回到不同的界面
		response.write "<Script>window.alert('分类修改成功');location.replace('sort_manage.asp');</Script>"
	else
		response.write "<Script>window.alert('分类修改成功');location.replace('sort.asp?sort_id="&sort_id&"');</Script>"
	end If
case "delete"						'删除操作
	delid=request.QueryString("id")			'读取要删除记录的id
	sort_id=Request.QueryString("sort_id")		'读取sort_id 的值
	If sort_id = "" Then
		sort_id = 0
	End If
	Del sort_id,delid
	if sort_id="0" then				'判断sort_id 的值,并根据sort_id 的值返回到不同的界面
		response.write "<Script>window.alert('分类删除成功');location.replace('sort_manage.asp');</Script>"
	else
		response.write "<Script>window.alert('分类删除成功');location.replace('sort.asp?sort_id="&sort_id&"');</Script>"
	end If
end select

conn.close
set conn=nothing
Function Del(sort_id,id)				'定义过程
	Set drs = Server.CreateObject("ADODB.RecordSet")'创建RecordSet 对象
	'从数据库中查询sort_id 的值为id 的记录,将结果保存在drs 中
	drs.Open "Select * from sort where sort_id="&id,conn,1,3
	If drs.EOF or drs.BOF Then			'不存在满足条件的记录,即该分类是最下级分类
		'删除该分类
		conn.Execute("delete * from sort where ID="&id)
		Exit Function				'跳出Function 过程
	Else						'还存在下级分类
		Do While Not drs.EOF 			'循环处理每一个下级分类
			nid = drs("id")			'下级分类的id
			Del id,nid			'删除该下级分类
			drs.MoveNext			'指向下一条记录
		Loop
	End If
	drs.Close					'关闭RecordSet 对象
	Set drs = nothing					
	conn.Execute("delete * from sort where id="&id)	'删除该分类
End Function
%>

⌨️ 快捷键说明

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