四、登录与密码修改功能
注意:将“学生信息管理系统”文件夹放在D盘上,
单都保存在“form”子文件夹中,报表都保存在“report” 子文件夹中,数据库文件、表文件都保存在“data” 子文件夹中,菜单、主程序和可视类文件直接保存在“学生信息管理系统”文件夹下。
1、创建“用户登录”表单,如下图所示:
功能:
(1) 若用户未输入用户名,单击“确定”按钮时,会弹出相应的对话框进行提示:“请输
入用户名”,同时,文本框“text1”将得到光标。
(2) 用户输入用户名后,单击“确定”按钮,如果不是注册的合法用户(即输入的用户
名在用户表中不存在),会弹出相应的对话框进行提示:“用户名不存在”,同时,文
本框“text1”中的内容将被清空,并获取光标。
(3) 若用户未输入密码,单击“确定”按钮时,会弹出相应的对话框进行提示:“请输入
密码”,同时,文本框“text2”将得到光标。
(4) 用户输入用户名和密码后,单击“确定”按钮,如果密码不正确,会弹出相应的对
话框进行提示:“密码不正确”,同时,文本框“text2”中的内容将被清空,并获取
光标。
(5) 如果用户名和密码均合法,则会弹出对话框提示“欢迎使用本程序”。 (6) 单击“取消”按钮时,文本框“text1”和“text2”中的内容将被清空,“text1”获取
光标。
(7) 单击“退出”按钮时,表单结束运行,并退出VF。
步骤:
(1) 为了保存用户的信息,在“学生信息管理”数据库下建立名为“用户表”的表文件,
表文件保存在“data”子文件夹中,该表包括如下3个字段:用户名 C(10),密码C
(6),用户类型 C(8)。其中用户类型字段取值为“管理员”或“普通用户”。 (2) 建立表单,添加所需控件,并修改控件属性。
(3) 将“text2”文本框的“passwordchar”属性置为“*”。 (4) 在“确定”按钮的“click”事件中添加如下代码: use D:\学生信息系统\data\用户表.dbf
If ALLTRIM(thisform.text1.Value) == ""
MessageBox("请输入用户名", 16, "提示")
thisform.text1.setfocus
return
Endif
locate for alltrim(用户名)==alltrim(thisform.text1.Value)
if found()==.f.
MessageBox("用户名不存在", 16, "错误提示")
thisform.text1.Value =""
thisform.text1.setfocus
return
endif
If ALLTRIM(thisform.text2.Value) == ""
MessageBox("请输入密码", 16, "错误提示")
thisform.text2.setfocus
return
Endif
If not(ALLTRIM(thisform.text2.Value) == ALLTRIM(密码))
MessageBox("密码不正确", 16, "错误提示")
thisform.text2.Value=""
thisform.text2.setfocus
return
Endif
&&设置用户记录的密码
release thisform &&关闭表单
MessageBox("欢迎使用本程序",48,"提示")
(5) 在“取消”按钮的“click”事件中添加如下代码: thisform.text1.Value="" thisform.text2.Value="" thisform.text1.setfocus (6) 在“退出”按钮的“click”事件中添加如下代码: thisform.release
quit
2、创建实现用户修改密码的表单,如下图所示:
功能:
(1) 用户在正确输入用户名和原有密码后可以设置新的密码,设置新密码时需要输入两
次,并且这两次输入的密码要一致,单击“确定”按钮后可以完成密码的修改。若
用户名不存在,则会弹出对话框进行提示,同时文本框“text1”将被清空,并获得
光标;若原密码不正确也会进行提示,时文本框“text2”将被清空,并获得光标;
若新密码和确认密码不一致时也进行提示,同时文本框“text3”和“text4”将被清
空,“text3”获得光标。
(2) 单击“取消”按钮时,四个文本框“中的内容都将被清空,“text1”获取光标。 (3) 单击“退出”按钮时,表单结束运行。
步骤:
(1) 在“确定”按钮的“click”事件中添加如下代码:
use D:\学生信息系统\data\用户表.dbf
If ALLTRIM(thisform.text1.Value) == ""
MessageBox("请输入用户名", 16, "错误提示")
thisform.text1.setfocus
return
Endif
locate for alltrim(用户名)==alltrim(thisform.text1.Value) if found()==.f.
MessageBox("用户名不存在", 16, "错误提示")
thisform.text1.Value =""
thisform.text1.setfocus
return
endif
If ALLTRIM(thisform.text2.Value) == ""
MessageBox("请输入密码", 16, "错误提示")
thisform.text2.setfocus
return
Endif
If not(ALLTRIM(thisform.text2.Value) == ALLTRIM(密码))
MessageBox("密码不正确", 16, "错误提示")
thisform.text2.Value=""
thisform.text3.Value=""
thisform.text4.Value=""
thisform.text2.setfocus
return
Endif
If ALLTRIM(thisform.text3.Value) == ""
MessageBox("请输入新密码", 16, "错误提示")
thisform.text3.setfocus
return
Endif
If ALLTRIM(thisform.text4.Value) == ""
MessageBox("请再次输入新密码", 16, "提示")
thisform.text4.setfocus
return
Endif
If ALLTRIM(thisform.text3.Value) != ALLTRIM(thisform.text4.Value)
MessageBox("新密码与确认密码不同", 16, "错误提示")
thisform.text3.Value=""
thisform.text4.Value=""
thisform.text3.setfocus
return
Endif
&&设置用户记录的密码
replace 密码 with ALLTRIM(thisform.text3.Value)
release thisform &&关闭表单
MessageBox("密码已经成功修改,请在下次登录时使用新密码",48,"提示")
(2) 在“取消”按钮的“click”事件中添加如下代码: thisform.text1.Value="" thisform.text2.Value="" thisform.text3.Value="" thisform.text4.Value="" thisform.text1.setfocus (3) 在“退出”按钮的“click”事件中添加如下代码: thisform.release