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

📄 houseclean.asp

📁 ASP+SQL Server动态网站开发从基础到实践教程
💻 ASP
字号:
<%
'houseclean.asp
'Created 14th March 2003
'>----------------------------------<
'>             FUNCTIONS			<
'> Deletes users that have been 	<
'> for longer than the time			<
'> specified in setup. 				<
'> Will also delete rooms that have <
'> no-one in them.					<
'>----------------------------------<

'delete people that have been idle for 20 mins
dim arrExpiredUsers()
i = 0
varTime = FormatDateTime(varDate, 4)
call openDB
rs.Open "SELECT * FROM USERS WHERE Active=1 ORDER BY Username", conn, 0, 1
if rs.EOF then
	'There are no users
else
	rs.movefirst
	do
		varUserID = rs("UserID")
		varRoomID = rs("RoomID")
		varLastPost = rs("LastPost")
		'now find out how long they have been idle for
		varLastPost = FormatDateTime(varLastPost, 4)
		varLastPost = CDate(varLastPost)
		varNow = now()
		'need the date as hh:mm
		varNow = FormatDateTime(varNow, 4)
		varNow = CDate(varNow)
		varIdle =  DateDiff("n", varLastPost, varNow)
		
		if varIdle >= varKickOutTime  OR varIdle < -varKickOutTime then
			arrayEU = "yes"
			redim Preserve arrExpiredUsers(i)
			arrExpiredUsers(i) = varUserID & ":" & varRoomID
			i = i + 1
		end if
		
		rs.movenext
	loop until rs.EOF
end if
call closeDB
'play with the array
if arrayEU = "yes" then
	For F = LBound(arrExpiredUsers) To UBound(arrExpiredUsers)
		'split the data
		varData = split(arrExpiredUsers(F), ":")
		call writeDB("INSERT INTO MESSAGES(UserID, RoomID, Message, Style, Colour, [Time]) VALUES(" & varData(0) & ", '" & varData(1) & "', 'Has Logged Off', 'i', 'red', '" & varTime & "');")
		response.write "Logged out user " & varData(0) & " from room " & varData(1)
		call writeDB("UPDATE USERS SET RoomID=0, [Time]='" & varDate & "', Active=0 WHERE UserID = " & varData(0) & ";")
	Next
end if

'delete empty rooms
Dim arrHCRooms()
i = 0
'get the rooms from the database
call openDB
varSQL = "SELECT * FROM ROOMS;"
rs.Open varSQL, conn
if rs.EOF then
	'There are no rooms
else
	rs.movefirst
	do
		varRoomID = rs("RoomID")
		arrayR = "yes"
		redim Preserve arrHCRooms(i)
		arrHCRooms(i) = varRoomID
		i = i + 1
		rs.movenext
	loop until rs.EOF
end if
call closeDB
if arrayR = "yes" then
	For F = LBound(arrHCRooms) To UBound(arrHCRooms)
		call openDB
		varSQL = "SELECT Count(UserID) AS NoUsers FROM USERS WHERE RoomID = " & arrHCRooms(F) & ";"
		rs.Open varSQL, conn
		varNoUsers = rs("NoUsers")
		call closeDB
		if varNoUsers = 0 AND NOT arrHCRooms(F) = 1 then
			call writeDB("DELETE FROM ROOMS WHERE RoomID = " & arrHCRooms(F) & ";")
		end if	
	Next
end if
%>

⌨️ 快捷键说明

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