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

📄 category_class.asp

📁 这是我根据动网新闻核心自行设计的校园新闻系统
💻 ASP
📖 第 1 页 / 共 2 页
字号:

<%
pageadmin=10
%>
<%
class LBCategory
	'类别的公有属性
	public CategoryId
	public CategoryName
	public CategoryType
	public CategoryOrder
	public Id
	public Version
	public ActionConn

	'类别的私有属性
	Private FieldCount

	'构造函数
	Private Sub Class_Initialize
		set ActionConn=conn
		Reset()
	end sub

	'解析函数
	Private Sub Class_Terminate
		Reset()
		'ActionConn.Close
		'Set ActionConn=Nothing
	end sub

	'重置函数
	private Sub ReSet()
		Version="LBNOW CREATE @ 2004-03-08 AND LAST UPDATE @ 2004-03-23"
		CategoryId=0
		CategoryName=""
		CategoryType=""
		CategoryOrder=0
		Id=""
		FieldCount=5
	End Sub

	'=============================================
	'
	'取得父列表下的空id
	'最后修改:2004-03-08
	'
	'=============================================
	Private Function GetEmptyId(fid)
		dim CSql
		dim CRsCount
		dim CRs
		dim Ci
		dim FidLength
		FidLength=len(fid)
		dim EmptyId
		EmptyId="null"
		dim IdCount
		IdCount="99999"

		'取出父id下的所有一级id
		if fid="-1" then
			CSql="select CategoryId as CategoryId from Category where CategoryType='"&CategoryType&"' and len(CategoryId)="&len(IdCount)&" order by CategoryId"
		else
			Csql="select right(CategoryId,"&len(IdCount)&") as CategoryId from Category where CategoryType='"&CategoryType&"' and left(CategoryId,"&FidLength&")='"&fid&"' and len(CategoryId)="&(FidLength+len(IdCount))

		end if
		set CRs=server.createobject("adodb.recordset")
		CRs.open Csql,ActionConn,3,1
		CRsCount=CRs.recordcount

		'取空的Id
		for Ci=0 to clng(IdCount)
			if Ci<CRsCount then
				if clng(CRs(0))<>Ci then
					EmptyId=Ci
					exit for
				end if
			else
				EmptyId=Ci
				exit for
			end if
			'response.write EmptyId&"<BR>"&clng(CRs(0))&"<BR>"&Ci&"<BR>"&CRsCount&"<BR>"&"_________"&"<BR>"
			CRs.movenext
		next

		'判断是否取得ID
		if EmptyId="null" then
			GetEmptyId= "error"
		else
			'位数不够加0
			dim Zero
			Zero=""
			for i=1 to (len(IdCount)-len(EmptyId))
				Zero=Zero+"0"
			next
			EmptyId=Cstr(Zero&Cstr(EmptyId))
			if fid<>"-1" then
				EmptyId=fid&cstr(EmptyId)
			end if
			GetEmptyId= EmptyId
		end if

		CRs.close
		Set CRs=nothing
	End Function

	'=============================================
	'
	'判断父指定类别是否存在
	'返回:ture,false
	'最后修改:2004-03-08
	'
	'=============================================
	Public Function IsEof(iFid)
		dim CRs
		set CRs=ActionConn.execute("select id from Category where CategoryType='"&CategoryType&"' and Categoryid='"&iFid&"'")
		if CRs.eof then
			IsEof= true
		else
			IsEof= false
		end if
		CRs.close
		set CRs=nothing
	End Function

	'=============================================
	'
	'新增类别
	'返回:生成的categoryid值, error
	'最后修改:2004-03-08
	'
	'=============================================
	Public Function Add(aFid)
		dim AId
		if aFid<>"-1" and IsEof(aFid) then
			Add="error"
		else
			dim CRs
			CRs=ActionConn.execute("select max(id) from Category")
			dim idd
			if isnull(CRs(0)) or CRs(0)=empty then
				idd=1
			else
				idd=CRs(0)+1
			end if
			set CRs=nothing
			AId=GetEmptyId(aFid)
			if AId<>"error" then
				ActionConn.execute("insert into [Category] (id,CategoryId,CategoryName,CategoryType,CategoryOrder) values ("&idd&",'"&AId&"','"&CategoryName&"','"&CategoryType&"',"&idd&")")
				Add=AId
			else
				Add="error"
			end if
		end if
	End Function

	'=============================================
	'
	'修改指定类别
	'返回:success
	'最后修改:2004-03-08
	'
	'=============================================
	Public Function Modify(mFid)
		ActionConn.execute("update Category set CategoryName='"&CategoryName&"' where CategoryId='"&mFid&"' and CategoryType='"&CategoryType&"'")
		Modify="success"
	End Function

	'=============================================
	'
	'删除指定类别
	'返回:success
	'最后修改:2004-03-08
	'
	'=============================================
	Public Function Delete(dFid)
		if dFid="-1" then
			ActionConn.execute("delete * from category where categoryType='"&CategoryType&"'")
		else
			ActionConn.execute("delete * from Category where CategoryType='"&CategoryType&"' and left(CategoryId,"&len(dFid)&")='"&dFid&"'")
			Delete="success"
		end if
	End Function

	'=============================================
	'
	'以类属性返回一个类别的信息
	'返回:重设属性
	'最后修改:2004-03-08
	'
	'=============================================
	public Function GetCategory(gcid)
		dim CRs
		dim Ci
		dim vt(1,5)
		set CRs=ActionConn.execute("select id,CategoryId,CategoryName,CategoryType,CategoryOrder from Category where categoryid='"&gcid&"' and categoryType='"&CategoryType&"' order by categoryid")
		if not CRs.eof then
			Id=CRs(0)
			CategoryId=CRs(1)
			CategoryName=CRs(2)
			CategoryType=CRs(3)
			CategoryOrder=CRs(4)
		end if
		Set CRs=nothing
	End Function


	'=============================================
	'
	'返回一种categorytype的类别总数
	'返回:列表总数
	'最后修改:2004-03-08
	'
	'=============================================

	Public Function RSCount(rct)
		dim CRs
		set CRs=ActionConn.execute("select count(id) from category where CategoryType='"&rct&"'")
		dim RCount
		RCount=CRs(0)
		CRs.close
		set CRs=nothing
		RSCount=Rcount
	End Function


	'=============================================
	'
	'类别排序列表,返回数组
	'返回:数组(0:显示特征,1:id,2:categoryid,3:categoryname,4:categoroytype,5:categoryorder)
	'最后修改:2004-03-08
	'
	'=============================================
	Public Function List(lid)
		dim RCount
		RCount=RSCount(CategoryType)
		dim ol()
		redim ol(RCount,FieldCount)
		ol(0,0)="根目录"
		ol(0,1)=RCount
		List=OrderListDG (categoryType,lid,ol,1)
	End Function

	'=============================================
	'
	'类别列表递归算法,返回数组
	'返回:数组(0:显示特征,1:id,2:categoryid,3:categoryname,4:categoroytype,5:categoryorder)
	'最后修改:2004-03-08
	'
	'=============================================
	Private Function OrderListDG (cType,cId,olist,onum)
		dim Cidlength
		dim zero
		dim i
		dim CRs
		if cId="-1" then
			Set CRs=ActionConn.execute("select id,categoryid,categoryname,categorytype,categoryorder from category where categorytype='"&cType&"' and len(categoryid)=5 order by categoryOrder asc,id asc")
		else
			Set CRs=ActionConn.execute("select id,categoryid,categoryname,categorytype,categoryorder from category where categorytype='"&cType&"' and len(categoryid)="&len(cId)+5&" and left(categoryid,"&len(cId)&")='"&cId&"' order by categoryOrder asc,id asc")
		end if
		do while not CRs.eof
			zero=""
			olist(onum,1)=CRs(0)
			olist(onum,2)=CRs(1)
			olist(onum,3)=CRs(2)
			olist(onum,4)=CRs(3)
			olist(onum,5)=CRs(4)
			Cidlength=len(CRs(1))
			for i=2 to Cidlength/5
				zero=zero&"  "
			next
			if zero="" then
				olist(onum,0)=zero&"+("&Crs(0)&")"&CRs(2)
			else
				olist(onum,0)=zero&"|-("&Crs(0)&")"&CRs(2)
			end if
			onum=onum+1
			OrderListDG cType,CRs(1),olist,onum
			CRs.movenext
		loop
		CRs.close
		Set CRs=nothing
		OrderListDG=olist
	End Function

	'=============================================
	'
	'返回下拉列表
	'返回:下拉列表
	'最后修改:2004-03-12
	'
	'=============================================
	Public Function DownList(dlid)
		dim dlist
		dim downl
		downl=""
		dlist=List(dlid)
		for i=1 to ubound(dlist)
			downl=downl&"<option value='"&dlist(i,2)&"'>"&dlist(i,0)&"</option>"
		next
		Response.write downl
	End Function
	'=============================================
	'
	'返回下拉列表
	'返回:以id为值下拉列表
	'最后修改:2004-03-12
	'
	'=============================================
	Public Function DownListid(dlid)
		dim dlist
		dim downl
		downl=""
		dlist=List(dlid)
		for i=1 to ubound(dlist)
			downl=downl&"<option value='"&dlist(i,1)&"'>"&dlist(i,0)&"</option>"
		next
		Response.write downl
	End Function
	'=============================================
	'
	'返回下拉列表,有选择
	'返回:下拉列表
	'最后修改:2004-3-26
	'
	'=============================================
	Public Function DownListSelected(dlid,dcategoryid)
		dim dlist

⌨️ 快捷键说明

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