?? user.asp
字號:
<link href="style.css" type="text/css" rel="stylesheet">
<!--#include file="conn.asp"-->
<%
if request("action")="" then
sql="select * from u"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,db,1,3
'實現(xiàn)用戶查看,添加,刪除,修改等...
%>
<table class=1 width="633" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td align="center" class="2">當(dāng)前所有用戶
<a href="user.asp?action=add" target="right">添加新用戶</a></td>
</tr>
</table>
<table class=1 width="633" border="1" align="center" cellpadding="3" cellspacing="0">
<tr align="center" valign="middle" >
<td align="center" class="2">id</td>
<td align="center" class="2">名字</td>
<td align="center" class="2">密碼</td>
<td align="center" class="2">是否鎖定</td>
<td align="center" class="2">借書數(shù)目</td>
<td align="center" class="2">借書詳情</td>
<td align="center" class="2">操作</td>
</tr>
<%do while not rs.eof %>
<tr align="center">
<td align="center" class="2"><%=rs("id")%></td>
<td align="center" class="2"><%=rs("name")%></td>
<td align="center" class="2"><%=rs("pwd")%></td>
<td align="center" class="2"><%if rs("lock") then response.Write("鎖定") else response.Write("未鎖定") end if%></td>
<td align="center" class="2"><%=rs("loan_num")%></td>
<td align="center" class="2"><a href="my_borrow.asp?id=<%=rs("id")%>" target="right">查看</a></td>
<td align="center" class="2">
<a href="user.asp?action=del&id=<%=rs("id")%>" target="right"> 刪除 </a>
<a href="user.asp?query=type_mod&id=<%=rs("id")%>" target="right"> 更改 </a>
<% if rs("lock") then %>
<a href="user.asp?query=type_mod&mod=yes&id=<%=rs("id")%>&islock=False&name=<%=rs("name")%>&pwd=<%=rs("pwd")%>" target="right">解鎖</a>
<%else%><a href="user.asp?query=type_mod&mod=yes&id=<%=rs("id")%>&islock=True&name=<%=rs("name")%>&pwd=<%=rs("pwd")%>" target="right">鎖定</a><%end if%>
</td>
</tr>
<%
rs.movenext
loop
%>
</table>
<%else
sql="select * from u"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,db,1,3
%>
<%'添加新的用戶
if request("action")="add" then
if request("add")<>"" then'檢查是否重名
set chk=db.execute("select * from u where name='"&trim(request("name"))&"'")
if chk.eof or chk.bof then '插入u表
rs.addnew
rs("name")=request("name")
rs("pwd")=request("pwd")
rs("lock")=0
rs("loan_num")=0
rs.update
response.write "<script>alert('添加成功咯');window.location.href='user.asp'</script>"
else response.write "<script>alert('用戶名重復(fù)');history.go(-1)</script>"
end if
else
%>
<form name="form1" method="post" action="">
<table class=1 width="333" border="0" align="center" cellpadding="3" cellspacing="0">
<tr >
<td colspan="2" align="center">添加新的用戶</td>
</tr>
<tr align="center">
<td align="center" class="2">用戶名:</td>
<td align="center" class="2">
<input name="name" type="text" id="name" size="15">
</td>
</tr>
<tr align="center">
<td align="center" class="2">密碼:</td>
<td align="center" class="2">
<input name="pwd" type="password" id="pwd" size="10">
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="添加">
<input type="reset" value="重置">
<input name="add" type="hidden" id="active" value="yes">
</td>
</tr>
</table>
</form>
<%end if%>
<%end if%>
<%'刪除用戶
if request("action")="del" then
if request("id")<>"" then
qq="select count(*) as xx from loans where uid="&request("id")
set q=db.execute(qq)
if q("xx")>0 then
response.write "<script>alert('存在借書記錄,不能刪除。');window.location.href='my_borrow.asp?id="&request("id")&"'</script>"
else
sql="delete from u where id="&request("id")
db.execute(sql)
response.write "<script>alert('刪除成功');window.location.href='user.asp'</script>"
end if
else
%>
<form action="" method="post">
<input name="id" type="text" size="15" value="請輸想刪除的用戶id">
<input type="submit" value="刪除">
<input type="reset" value="重置">
</form>
<%end if %>
<%end if %><%end if'刪除用戶 %>
<%'更改用戶 過程:如果有更改請求,如果有ID,導(dǎo)出數(shù)據(jù),如果確認(rèn)更改,執(zhí)行檢查過程;檢查成功則更新 否則返回錯誤
if request("query")="type_mod" then
if request("id")<>"" then
sql="select * from u where id="&request("id")
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql,db,1,3
if request("mod")="yes" then'確認(rèn)請求
set chk=db.execute("select * from u where name='"&request("name")&"'and id<>"&request("id"))
if not chk.eof then
response.write "<script>alert('已經(jīng)存在的名咯');history.go(-1)</script>"
response.End()
else
if request("islock")="True" then
qq="update u set name='"&request("name")&"',pwd='"&request("pwd")&"',lock='1' where id="&request("id")
else
qq="update u set name='"&request("name")&"',pwd='"&request("pwd")&"',lock='0' where id="&request("id")
end if
db.execute(qq)
response.write "<script>alert('更改成功');window.location.href='user.asp'</script>"
end if
else
%>
<table class=1 width="333" border="0" align="center" cellpadding="3" cellspacing="0">
<form action="" method="post">
<tr>
<td align="center" class="2">名字:</td>
<td align="center" class="2">
<input name="name" type="text" size="15" value="<%=rs1("name")%>"></td>
</tr>
<tr>
<td align="center" class="2">密碼:</td>
<td align="center" class="2">
<input name="pwd" type="password" size="15" value="<%=rs1("pwd")%>"></td>
</tr>
<tr>
<td align="center" class="2">是否鎖定:</td>
<td align="left" class="2">
當(dāng)前<%if rs1("lock") then
response.Write("鎖定")
else
response.Write("未鎖定")
end if%>
<select name="islock">
<%if rs1("lock") then %>
<option value="True" >鎖定</option>
<option value="False">不鎖定</option>
<%else%>
<option value="False" >不鎖定</option>
<option value="True">鎖定</option>
<%end if%>
</select>
</td>
</tr>
<tr>
<td align="center" class="2"></td>
<td align="center" class="2">
<input type="submit" value="更改">
<input type="reset" value="重置"></td>
</tr>
<input name="mod" type="hidden" value="yes">
</form>
</table>
<%end if%>
<%
else
response.write "<script>alert('未指定user id');window.location.href='user.asp'</script>"
end if
%>
<%end if%>
<br><br><br>
<div><a href="index.asp" target="right">首頁</a>
<a href="javascript:history.go(-1)" target="right">返回</a>
</div>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -