这篇总结主要写了三个知识点:一是统计当前上机人数;二是学生信息维护的修改按钮;三是修改密码!
一、如何动态统计当前上机人数。
刚开始的时候弄的特别麻烦,又是设置全局变量,又是写大量的代码,但是还是效果不理想,之后才发现其实只要在主界面加一个Timer控件就行了!具体实现步骤:①在主窗体界面加一个Timer控件。②双击进入代码窗体,写下如下代码:
<span style="font-size:18px;">Private Sub Timer1_Timer1() Dim mrc As ADODB.Recordset Dim txtSQL As String Dim Msgtext As String txtSQL ="select getdate()" '获取数据库系统时间 Set mrc = ExecuteSQL (txtSQL,Msgtext) Label1.caption =Formate(mrc.Fields(0),"yyyy-mm-dd hh:mm:ss") End sub</span>
二、如何实现学生信息维护窗体中的修改按钮功能!
主要实现的功能是:在学生信息维护窗体中选中查询到的某一行信息,点击修改后,弹出修改窗体,而里面存在有刚刚选择的那一行信息!其实里面主要涉及到一个全局变量,而我之前没想到!具体操作步骤:①在模块中定义一个全局变量P,代码如下:
<span style="font-size:18px;">Public P as Integer</span>
②在学生信息维护窗体界面实现:单击选择的是整行,把选择的那一行信息的卡号赋值给全局变量P,代码如下:
<span style="font-size:18px;">Dim txtSQL, Msgtext As String Dim mrc As ADODB.Recordset Dim mrcc As ADODB.Recordset MSFlexGrid1.SelectionMode = flexSelectionByRow '单击的时候选择的是整行 txtSQL = "select * from student_Info where cardno ='" & Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0)) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) p = Trim(mrc.Fields(0)) '把卡号信息传递给全局变量P mrc.Close frmModifyStuInfo.Show '显示出frmModifyInfo的窗体</span>
③把查询到的信息填写到修改窗体里面,代码如下:
<span style="font-size:18px;">Private Sub Form_Load() Dim Msgtext As String Dim txtSQL As String Dim mrc As ADODB.Recordset '全局变量p的值从学生基本信息维护窗体赋予的,然后查询出此卡号信息 txtSQL = "select * from student_Info where cardno = '" & p & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) '将查询的数据填入窗体的文本框中 Text1.Text = Trim(mrc.Fields(1)) Text2.Text = Trim(mrc.Fields(2)) Text3.Text = Trim(mrc.Fields(4)) Text4.Text = Trim(mrc.Fields(5)) Text5.Text = Trim(mrc.Fields(6)) Text6.Text = Trim(mrc.Fields(0)) Text7.Text = Trim(mrc.Fields(7)) Text8.Text = Trim(mrc.Fields(10)) Text9.Text = Trim(mrc.Fields(8)) Combo1.Text = Trim(mrc.Fields(3)) Combo2.Text = Trim(mrc.Fields(14)) mrc.Close Combo1.AddItem "男" '把数据加载到组合框中 Combo1.AddItem "女" Combo2.AddItem "固定用户" Combo2.AddItem "临时用户" End Sub </span>
三、修改密码时的思路。
①判断旧密码是否正确(是否是正在登陆用户的密码,遍历用户表),若不是,提示信息!
②判断新密码和确认密码是否一致,若不一致则提示!
③修改成功后将表中的用户密码进行更改!(优化:当新密码没输入的时候,不能输入确认密码;当新密码与原密码一致时提示!)代码如下:
<span style="font-size:18px;">Private Sub cmdOK_Click() Dim strSQL As String Dim MsgString As String Dim mrs As ADODB.Recordset '调出User表中的登录用户的一行信息 strSQL = "select * from User_info where UserID = '" & UserName & "'" Set mrs = ExecuteSQL(strSQL, MsgString) If txtOldPwd.Text <> Trim(mrs.Fields(1)) Then MsgBox "原密码不正确,请重新输入!", vbOKOnly + vbExclamation, "提示" txtOldPwd.Text = "" txtOldPwd.SetFocus Else If Trim(txtNewPwd.Text) = "" Then MsgBox "请输入新密码!", vbExclamation + vbOKOnly, "提示" txtNewPwd.Text = "" txtNewPwd.SetFocus Else If Trim(txtNewPwd.Text) = Trim(txtOldPwd.Text) Then MsgBox "新密码与原密码一致,请重新输入!", vbOKOnly + vbExclamation, "提示" txtNewPwd.Text = "" txtReNewPwd.Text = "" txtNewPwd.SetFocus Else If Trim(txtReNewPwd.Text) = "" Then MsgBox "请输入确认密码!", vbOKOnly + vbExclamation, "提示" txtReNewPwd.SetFocus Else If txtReNewPwd.Text <> txtNewPwd.Text Then MsgBox "两次输入密码不一致,请重新输入密码!", vbOKOnly + vbExclamation, "提示" txtReNewPwd.Text = "" txtReNewPwd.SetFocus Else mrs.Fields(1) = txtNewPwd.Text mrs.Update mrs.Close MsgBox "修改密码成功!", vbOKOnly + vbInformation, "修改密码" txtOldPwd.Text = "" txtNewPwd.Text = "" txtReNewPwd.Text = "" Me.Hide End If End If End If End If End If End Sub</span>
<span style="font-size:18px;">Private Sub txtOldPwd_LostFocus() '当旧密码文本框失去焦点时判断输入是否正确 Dim Msgtext As String Dim txtSQL As String Dim mrc As ADODB.Recordset txtSQL = "select * from User_Info where UserID = '" & UserName & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) If txtOldPwd.Text = "" Then Exit Sub End If If txtOldPwd.Text <> Trim(mrc.Fields(1)) Then MsgBox "原密码不正确,请重新输入!", vbOKOnly + vbExclamation, "提示" txtOldPwd.Text = "" txtOldPwd.SetFocus End If End Sub</span>
<span style="font-size:18px;">Private Sub Timer1_Timer() '利用Timer事件保证,当新密码为空的时候,确认密码也为空 If txtNewPwd.Text = "" Then txtReNewPwd.Text = "" End If End Sub </span>
以上三点都是自己在做机房的过程中遇到的问题,但是印象好像有点模糊了,所以,总结下来,算是回顾一遍。希望这些可以帮到你!