“ 子曰:“温故而知新,可以为师矣。”
大家好,我是秦时明月。上次我记录了利用“猫框”实现BS系统登录界面,今天我们实验一下BS应用系统之用户管理模块,前提是先抛开CSS样式在网页中应用和软件操作权限控制,只聊实现这一功能的操作方式。
先看一下我们要实现的界面效果:
01—第一次打开页面时的样子:
02—当你输入昵称“ALL”点“查询”之后的样子
03—当你输入查询昵称“jiafeimao”点“查询”之后的样子:
04—当你输入昵称和密码之后点击“添加”之后的界面
好了,通过以上的界面,我们知道了我们今天要试验的内容。接下来,我们来准备试验的文件。
1 当然是建表了wuser.dbf
2.BS网页文件clryxx.htm
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户管理模块</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body bgcolor="#ffffff">
<form id="form1" name="form1" method="post" action="clryxx.fsp">
<label for="textfield">请输入昵称:</label>
<input type="text" name="lkname" id="lkname" value="<%u(cname)%>" title="输入 ALL 显示所有用户名"/>
<input type="submit" name="button" id="button" value="查询" /> <label for="textfield"> [输入ALL显示所有用户]</label>
</form>
<% if not empty(cname)%>
<hr />
<table>
<tr>
<td align="center" bgcolor="#66CCFF"><strong>用户ID</strong></td>
<td align="center" bgcolor="#66CCFF"><strong>昵称</strong></td> <td align="center" bgcolor="#66CCFF"><strong>密码</strong></td>
<td bgcolor="#66CCFF"><strong>操作</strong></td>
</tr>
<tr>
<% scan %>
<form name="fm<%u(ID)%>" method=post action="clryxx.fsp">
<td><input name="uid" type=text value="<%u(uid)%>" readonly="readonly"/></td>
<td><input type=text name="uname" value="<%u(uname)%>"/></td>
<td><input type=password name="upass" value="<%u(upwd)%>"/></td>
<td><input type=hidden name="id" value="<%u(ID)%>" id="id" />
<button type="submit" name="act" id="act" value="1" onclick="return confirm('确定要修改吗?')">修改</button>
<button type="submit" name="act" id="act" value="2" onclick="return confirm('确定要删除吗?')">删除</button></td>
</form>
</tr>
<% endscan %>
</table>
<%endif %>
<hr />
<table>
<tr>
<td align="center" bgcolor="#66CCFF"><strong>用户ID</strong></td>
<td align="center" bgcolor="#66CCFF"><strong>昵称</strong></td> <td align="center" bgcolor="#66CCFF"><strong>密码</strong></td>
<td bgcolor="#66CCFF"><strong>操作</strong></td>
</tr>
<tr>
<form name="fmadd" method=post action="clryxx.fsp">
<td><input name="uid" type=text value="系统自动分配" readonly="readonly"/></td>
<td><input type=text name="uname" value="登录名"/></td>
<td><input type=password name="upass" value=""/></td>
<td><input type=hidden name="id" value="<%u(ID)%>" id="id" />
<button type="submit" name="act" id="act" value="3" onclick="return confirm('确定要添加吗?')">添加</button></td>
</form>
</tr>
</table>
</body>
</html>
看着很多,实际上要关注的是以下的代码,这是输入查询条件的代码
<form id="form1" name="form1" method="post" action="clryxx.fsp">
<label for="textfield">请输入昵称:</label>
<input type="text" name="lkname" id="lkname" value="<%u(cname)%>" title="输入 ALL 显示所有用户名"/>
<input type="submit" name="button" id="button" value="查询" /> <label for="textfield"> [输入ALL显示所有用户]</label>
</form>
这是中间列表部分的代码(列表,修改)
<% if not empty(cname)%>
<hr />
<table>
<tr>
<td align="center" bgcolor="#66CCFF"><strong>用户ID</strong></td>
<td align="center" bgcolor="#66CCFF"><strong>昵称</strong></td> <td align="center" bgcolor="#66CCFF"><strong>密码</strong></td>
<td bgcolor="#66CCFF"><strong>操作</strong></td>
</tr>
<tr>
<% scan %>
<form name="fm<%u(ID)%>" method=post action="clryxx.fsp">
<td><input name="uid" type=text value="<%u(uid)%>" readonly="readonly"/></td>
<td><input type=text name="uname" value="<%u(uname)%>"/></td>
<td><input type=password name="upass" value="<%u(upwd)%>"/></td>
<td><input type=hidden name="id" value="<%u(ID)%>" id="id" />
<button type="submit" name="act" id="act" value="1" onclick="return confirm('确定要修改吗?')">修改</button>
<button type="submit" name="act" id="act" value="2" onclick="return confirm('确定要删除吗?')">删除</button></td>
</form>
</tr>
<% endscan %>
</table>
<%endif %>
看下方的新增功能模块
<table>
<tr>
<td align="center" bgcolor="#66CCFF"><strong>用户ID</strong></td>
<td align="center" bgcolor="#66CCFF"><strong>昵称</strong></td> <td align="center" bgcolor="#66CCFF"><strong>密码</strong></td>
<td bgcolor="#66CCFF"><strong>操作</strong></td>
</tr>
<tr>
<form name="fmadd" method=post action="clryxx.fsp">
<td><input name="uid" type=text value="系统自动分配" readonly="readonly"/></td>
<td><input type=text name="uname" value="登录名"/></td>
<td><input type=password name="upass" value=""/></td>
<td><input type=hidden name="id" value="<%u(ID)%>" id="id" />
<button type="submit" name="act" id="act" value="3" onclick="return confirm('确定要添加吗?')">添加</button></td>
</form>
</tr>
</table>
利用了三个<form>标签,提交给处理文件action=”clryxx.fsp”,除了“查询”按钮,其他按钮都有属性name=”act”,那么我们就来看看clryxx.fsp的代码。
define class clryxx as session
procedure ondefault
private cname,cid,cuid,cuname,ccpwd,cact
&& 以下是获取网页传递过来的参数 无论是get or post
&& 至于谁被传递过来是由触发提交表单的按钮决定的
cname=allt(httpqueryparams("lkname"))
cact=allt(httpqueryparams("act"))
cid=allt(httpqueryparams("id"))
cuid=allt(httpqueryparams("uid"))
cuname=allt(httpqueryparams("uname"))
ccpwd=allt(httpqueryparams("upass"))
&& 以下根据 name="act" 的 值决定进行什么操作 3 ad 2 del 1 edit 其他是查询
do case
case cact="3" && 添加动作
return this.actadd(cuname,ccpwd)
case cact="2" && 删除动作
return this.actdel(cid) case cact="1" && 添加动作
return this.actedit( cid,cuid,cuname,ccpwd) other && 查询动作
return this.showlookinfo(cname)
endcase
endpro
proce showlookinfo
lpara s
if not used('wuser') then
sele 0
use wuser
endif
sele wuser
if UPPER(s)<>"ALL" then
set filter to "&s"$allt(uname)
endif
set dele on
go top
_currentcode="UTF-8"
chtml=getwwwrootpath("")+"clryxx.htm"
chtml= FWS_MergeFile(chtml)
use in select('wuser')
set dele off
return chtml
endproc
proc actadd
lpara cuname,ccpwd
if not used('wuser') then
sele 0
use wuser
endif
sele wuser
&& 这里是生成新序号
select max(uid) uid from wuser into cursor TJ
sele tj
private lsid
lsid=allt(subs(uid,2))
lsid="A"+padl(int(val(lsid))+1,4,"0")
use in select('tj')
sele wuser
appe blank
repl uid with lsid,uname with cuname,upwd with ccpwd
use in select('wuser')
return this.showlookinfo(cuname)
endpro
proc actdel
lpara cid
private cmdstr
if not used('wuser') then
sele 0
use wuser
endif
sele wuser
set dele on
cmdstr=" dele for id="+cid
&cmdstr
use in select('wuser')
set dele off
return this.showlookinfo("")
endpro
proc actedit
lpara cid,cuid,cuname,ccpwd
if not used('wuser') then
sele 0
use wuser
endif
sele wuser
set dele on
cmdstr=" loca for id="+cid
&cmdstr
if found()
repl uname with cuname
repl upwd with ccpwd
else
cuname=""
endif
use in select('wuser')
set dele off
return this.showlookinfo(cuname)
endproc
enddefi
猫框项目中启动调试服务器,然后在地址栏里输入http://IP:801/clryxx.fsp。而不是输入 clryxx.htm,不妨自己在地址栏试验一下,看有什么区别,为什么?欢迎在评论区留言。