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

📄 common.inc

📁 档案管理系统
💻 INC
字号:

<%
dim adoConn	'定义数据库连接变量
response.expires=0

'-------------错误检查子程序,可在可能出错的语句后引用,但在页面起始处应有on error resume next----------
public sub checkError()
	if err.Number<>0 then raiseErr err.description
end sub

'-------------得到数据库连接------------
public function getConnection
	if isEmpty(adoConn) then
		set adoConn= server.createobject("ADODB.Connection")
		adoConn.Open "DSN=docmng;UID=sa;PWD="
	end if
	set getConnection=adoConn
end function

'-------------得到用户的id--------------
public function getUser()
	checkSession
	getUser=session("user")
end function

'-------------得到用户的等级------------
public function getUserRank()
	checkSession
	getUserRank=session("userrank")
end function

'-------------关闭数据库连接------------
public sub closeConnection()
	if not isEmpty(adoConn) then adoConn.Close()
end sub


'--------------检查session是否为空-----------
public sub checkSession
	if isEmpty(session("user")) then
		response.redirect "../default.htm"
	end if
end sub

'--------------提交错误信息到统一错误页面err.asp--------------
public sub raiseErr (sErr)
	closeConnection
	response.redirect "../err.asp?err=" & sErr
end sub

'--------------一个字符串打印子程序,val为option的value,curval为参考value\当val=curval时selected,text为标识---------
public sub WriteOption(val,curVal,text)
	response.write "<option value='" & val & "'"
	if val=curVal then response.write " selected "
	response.write ">" & text & "</option>"
end sub

public function getUserRankById(userid)
	checkSession
	dim adoRS
	dim strQuery
	strQuery="select * from userinfo where userid='" & "" & userid & "'"
	set adoRS=server.createobject("ADODB.Recordset")
	adoRS.Open strQuery, getConnection(), , , adCmdText
	if adoRS.EOF then
		getUserRankById = null
	else
		getUserRankById = adoRS("purview")
	end if
	set adoRS = Nothing
end function

public function isAdmin(userId)
	checkSession
	dim adoRS
	dim strQuery
	if getUserRankById(userId) = 1 then
		isAdmin = 1
		exit function
	end if
	strQuery="select * from documentclass where admin='" & "" & userId & "'"
	set adoRS=server.createobject("ADODB.Recordset")
	adoRS.Open strQuery, getConnection(), , , adCmdText
	if adoRS.EOF then
		isAdmin = 0
	else
		isAdmin = 1
	end if
	set adoRS = Nothing
end function

public function getRankStr(userId)
	checkSession
	dim strRet
	if getUserRankById(userId) = 1 then
		strRet = "系统管理员"
	elseif isAdmin("" & userId) <> 0 then
		strRet = "档案库管理员"
	else
		strRet = "普通用户" 
	end if
	getRankStr = strRet
end function

public sub addlog(operation, tablename)
	checkSession
	Dim strInsert
	strInsert = "insert into operationlog(operator,operation,tablename) values('"
	strInsert = strInsert & getUser() & "','" & operation & "','" & tablename & "')"
	getConnection().Execute strInsert
end sub

public sub addmsg(touser, msg)
	checkSession
	Dim strInsert
	strInsert = "insert into message(fromuser,touser,message,state) values('"
	strInsert = strInsert & getUser() & "','" & touser & "','" & msg & "',0)"
	getConnection().Execute strInsert
end sub

public sub writeUserListOption(userid)
	checkSession
	dim selUser
	dim adoRS
	dim strQuery
	selUser = "" & userid
	strQuery="select * from userinfo"
	set adoRS=server.createobject("ADODB.Recordset")
	adoRS.Open strQuery, getConnection(), , , adCmdText
	while not adoRS.EOF
		WriteOption adoRS("userid"),selUser,adoRS("userid")
		adoRS.MoveNext
	Wend
	set adoRS = Nothing
end sub

public sub writeYearOption(intYear)
	checkSession
	dim selYear
	if "" & intYear = "" then
		selYear = Year(Now)
	else
		selYear = CInt(intYear)
	end if
	for i=1990 to 2100
		WriteOption i,selYear,i
	Next
end sub

public sub writeMonthOption()
	for i=1 to 12
		WriteOption i,Month(Now),i
	Next
end sub

public sub writeDayOption()
	for i=1 to 31
		WriteOption i,Day(Now),i
	Next
end sub

public function insertBR(str)
	dim strRet
	dim strLeave
	strLeave = str
	strRet = ""
	while Len(strLeave) >=15
		strRet = strRet & Left(strLeave,14) & "<BR>"
		strLeave = Mid(strLeave,15)
	Wend
	strRet = strRet & strLeave
	insertBR = strRet
end function

public function getMsgRS()
	checkSession
	dim adoRS
	dim strQuery
	strQuery="select * from message where state=0 and touser='" & getUser() & "'"
	set adoRS=server.createobject("ADODB.Recordset")
	adoRS.Open strQuery, getConnection(), , , adCmdText
	set getMsgRS = adoRS
end function

public sub setMsgOver(id)
	checkSession
	Dim strQuery
	strQuery = "update message set state=1 where id=" & id
	getConnection().Execute strQuery
end sub
%>

⌨️ 快捷键说明

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