📄 adduser.asp
字号:
<%response.expires=0%>
<!--#include file="asp/sqlstr.asp"-->
<!--#include file="asp/opendb.asp"-->
<!--#include file="asp/bgsub.asp"-->
<!--#include file="inc/public.asp"-->
<!--#include file="asp/keepformat.asp"-->
<%
function strlength(inputstr)
dim length,i
length=0
for i=1 to len(inputstr)
if asc(mid(inputstr,i,1))<0 then
length=length+2
else
length=length+1
end if
next
strlength=length
end function
oabusyname=request.cookies("oabusyname")
oabusyusername=request.cookies("oabusyusername")
oabusyuserdept=request.cookies("oabusyuserdept")
oabusyuserlevel=request.cookies("oabusyuserlevel")
if oabusyusername="" then
response.write("<script language=""javascript"">")
response.write("window.top.location.href='default.asp';")
response.write("</script>")
response.end
end if
%>
<%
set conn=opendb("oabusy","conn","accessdsn")
set rs=server.createobject("adodb.recordset")
sql="select * from userinf where username='" & oabusyusername&"'"
rs.open sql,conn,1
cook_allow_control_all_user=rs("allow_control_all_user")
conn.close
set conn=nothing
set rs=nothing
if cook_allow_control_all_user="no" then
response.write("<font color=red size=""+1"">对不起,您没有这个权限!</font>")
response.end
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="css/css.css">
<title>增加用户</title>
</head>
<body bgcolor="#ffffff" topmargin="5" leftmargin="5">
<%
call bghead()
%>
<center>
<table>
<tr>
<td><b>增加用户</b> </td>
<form method="post" action="deptcontrol.asp">
<td>
<input type="submit" name="submit" value="部门名称管理">
</td>
</form>
<form method="post" action="userlevelcontrol.asp">
<td>
<input type="submit" name="submit" value="职位名称管理">
</td>
</form>
</tr>
</table>
</center>
<%on error resume next
call bgmid()
oabusyuserdept=request.cookies("oabusyuserdept")
set conns=opendb("oabusy","conn","accessdsn")
set rss=createobject("adodb.recordset")
rss.open "select count(*) as count from userinf",conns
if rss("count")>500 then
response.write "<br><center><font color=red size=+1>对不起,用户数已达上限!</font></center>"
call bgback()
rss.close
conns.close
set rss=nothing
set conns=nothing
response.end
end if
rss.close
conns.close
set rss=nothing
set conns=nothing
if request("submit")="增加" then
errorinfo=""
username=trim(request.form("username"))
if strlength(username)>10 then
errorinfo=errorinfo&"用户名太长,不能超过5个汉字或10个英文字符!<br>"
end if
password=trim(request.form("password"))
if strlength(password)>20 then
errorinfo=errorinfo&"密码太长,不能超过20个字符!<br>"
end if
name=trim(request.form("name"))
if strlength(name)>10 then
errorinfo=errorinfo&"姓名太长,不能超过5个汉字或10个英文字符!<br>"
end if
userdept=request.form("userdept")
userlevel=request.form("userlevel")
if errorinfo="" then
'判断是否有与申请的用户名相同的
on error resume next
set conn=opendb("oabusy","conn","accessdsn")
conn.BeginTrans
set rs=server.createobject("adodb.recordset")
sql="select * from userinf where username=" & sqlstr(username)
rs.open sql,conn,1
if not rs.eof and not rs.bof then
%>
<center>
<br><br>
<center><font color="red" size="+1">用户名为<%=keepformat(username)%>的用户已经存在,请选择其他用户名</font><br><br>
<input type="button" onclick="history.go( -1 );return true;" value="返回"></center>
</center>
<%
else
sql = "Insert Into userinf (username,password,name,userdept,userlevel) Values( "
sql = sql & SqlStr(username) & ", "
sql = sql & SqlStr(password) & ", "
sql = sql & SqlStr(name) & ", "
sql = sql & SqlStr(userdept) & ", "
sql = sql & SqlStr(userlevel) & ")"
conn.Execute(sql)
set rs1=server.createobject("adodb.recordset")
sql="SELECT @@IDENTITY AS IdSum from userinf"
rs1.open sql,conn,1
IdSum=rs1("IdSum")
set rs1=nothing
if err.number<>0 then
conn.rollbacktrans
call DispErrorInfo1("对不起,增加用户出错!出错原因:"&err.description)
conn.close
set conn=nothing
call bgback()
response.end
else
conn.committrans
end if
%>
<br><br>
<center>
<font color="red" size="+1">用户名为<%=keepformat(username)%>的用户注册成功!</font>
</center>
<br><br>
<%
end if
else
%>
<div align="center">
<table widht="80%" border="0">
<tr><td>
<center><b><font color="red" size="+1">出错了</font></b></center><br><br>
<font color="#ee0000" size="+1"><%=errorinfo%></font>
<center><input type="button" value="返回" onclick="history.go( -1 );return true;"></center>
</td></tr></table>
</div>
<%
end if
else
%>
<br>
<center>
<script Language="JavaScript">
function maxlength(str,minl,maxl)
{
if(str.length <= maxl && str.length >= minl)
{
return true;
}
else
{
return false;
}
}
function form_check()
{
var l1=maxlength(document.form2.username.value,1,10);
if(!l1)
{
window.alert("用户名的长度不能超过5个汉字或10个英文字符!");
document.form2.username.focus();
return (false);
}
var l2=maxlength(document.form2.password.value,1,20);
if(!l2)
{
window.alert("密码的长度大于1位小于20位");
document.form2.password.focus();
return (false);
}
var a1=document.form2.password.value;
var a2=document.form2.repassword.value;
if(a1!=a2)
{
window.alert("两次输入的密码应相同");
document.form2.repassword.focus();
return (false);
}
var l3=maxlength(document.form2.name.value,1,20);
if(!l3)
{
window.alert("姓名的长度不能超过5个汉字或10个英文字符!");
document.form2.name.focus();
return (false);
}
}
</script>
<form action="adduser.asp" method=post name="form2" onsubmit="return form_check();">
<table border="1" cellspacing="0" cellpadding="5" bordercolorlight="#808080" bordercolordark="#D4D0C8" width="400">
<tr>
<td align="right">
用户名:</td><td><input type=text name="username" size=20 maxlength="10"><font color=red>*</font>
</td>
</tr>
<tr>
<td align="right">
密码:</td><td><input type="password" name="password" size=20 maxlength="20"><font color=red>*</font>
</td>
</tr>
<tr>
<td align="right">
密码确认:</td><td><input type="password" name="repassword" size=20 maxlength="20"><font color=red>*</font>
</td>
</tr>
<tr>
<td align="right">
姓名:</td><td><input type="text" name="name" size=20 maxlength="10"><font color=red>*</font>
</td>
</tr>
<tr>
<td align="right">
部门:</td><td>
<select size=1 name="userdept">
<%
set conn=opendb("oabusy","conn","accessdsn")
set rs=server.createobject("adodb.recordset")
sql="select * from dept"
rs.open sql,conn,1
while not rs.eof and not rs.bof
%>
<option value="<%=rs("dept")%>"><%=rs("dept")%></option>
<%
rs.movenext
wend
%>
</select><font color=red>*</font>
</td>
</tr>
<tr>
<td align="right">
职位:</td><td><select name="userlevel" size=1>
<option value="总管">总管</option>
<%
set conn=opendb("oabusy","conn","accessdsn")
set rs=server.createobject("adodb.recordset")
sql="select * from userlevel"
rs.open sql,conn,1
while not rs.eof and not rs.bof
%>
<option value="<%=rs("userlevel")%>"><%=rs("userlevel")%></option>
<%
rs.movenext
wend
%>
</select><font color=red>*</font>
</td>
</tr>
<tr>
<td colspan="2" align=center>
<font color=red>*</font>必须填 <input type="submit" name="submit" value="增加">
</td>
</tr>
</table>
</form>
</center>
<%
end if
call bgback()
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -