前言:
今天进行上机部分的学习,主要是宏观逻辑的把控和对查询语句的使用,首先我画了个逻辑图梳理思路,要做什么?先后顺序?以及用到的知识点!
一、上机—输入卡号
二、判断卡号输入是否规范
1.是否输入?2.是否为数字?(用代码限制输入)
三、判断是否注册
查询Student_info中的studentId
四、判断卡内是否有钱
查询Student_info中的cash(提示后要及时清空Text)
五、上机成功—更新数据表Online_info
查询正在上机的人数
六、代码展示:
PRivate Sub cmdUp_Click() Dim txtSQL As String '查询student_info,判断卡号是否注册 Dim txtSQL2 As String '查询online_info,判断卡号是否正在上机 Dim txtSQL4 As String '查询basicdata_info中的limitcash Dim txtSQL5 As String '将该卡上机的信息填入到online_info表中 Dim txtSQL6 As String '查询正在上机的人数 Dim MsgText As String Dim MsgText2 As String Dim MsgText4 As String Dim MsgText5 As String Dim MsgText6 As String Dim mrc As ADODB.Recordset Dim mrc2 As ADODB.Recordset Dim mrc4 As ADODB.Recordset Dim mrc5 As ADODB.Recordset Dim mrc6 As ADODB.Recordset '判断卡号是否为空 If Trim(txtCardID.Text) = "" Then MsgBox "请输入卡号!", vbOKOnly + vbExclamation, "提示" txtCardID.SetFocus Exit Sub Else If IsNumeric(txtCardID.Text) = False Then MsgBox "卡号必须输入数字!", vbOKOnly + vbExclamation, "提示" txtCardID.Text = "" txtCardID.SetFocus ',清空输入框,焦点返回到输入框 Exit Sub End If '查询数据库中基本信息表 txtSQL = "select * from student_Info where cardno= '" & Trim(txtCardID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, MsgText) '判断该卡号是否注册 If mrc.BOF And mrc.EOF Then MsgBox "该卡号未注册,请先注册!", vbOKOnly + vbExclamation, "提示" txtCardID.Text = "" txtCardID.SetFocus Exit Sub Else '判断卡号是否已经退卡,退卡后不能上机 If Trim(mrc.Fields(10)) = "未激活" Then MsgBox "该卡已经退卡", vbOKCancel + vbInformation, "提示" txtCardID.Text = "" txtCardID.SetFocus Exit Sub Else '查询basicdata_info中的limitcash txtSQL4 = "select * from basicdata_info" Set mrc4 = ExecuteSQL(txtSQL4, MsgText4) If Val(mrc.Fields(7)) < Val(mrc4.Fields(5)) Then MsgBox "余额不足,请充值后上机!", vbOKOnly + vbExclamation, "提示" txtCardID.Text = "" txtCardID.SetFocus Exit Sub Else '判断卡号是否正在上机 txtSQL2 = "select * from online_info where cardno='" & Trim(txtCardID.Text) & "'" Set mrc2 = ExecuteSQL(txtSQL2, MsgText2) '查询student_info中的cash txtSQL = "select * from student_info where cardno='" & Trim(txtCardID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, MsgText) If mrc2.EOF = False Then MsgBox "该卡正在上机!" txtSID.Text = mrc2.Fields(2) txtName.Text = mrc2.Fields(3) txtSex.Text = mrc2.Fields(5) txtDepartment = mrc.Fields(4) txtType.Text = mrc2.Fields(1) txtUpdate.Text = mrc2.Fields(6) txtUptime.Text = mrc2.Fields(7) Exit Sub Else '显示该卡号的一些基本信息 txtSID.Text = mrc.Fields(1) txtName.Text = mrc.Fields(2) txtSex.Text = mrc.Fields(3) txtDepartment = mrc.Fields(4) txtType.Text = mrc.Fields(14) txtUpdate.Text = Date txtUptime.Text = Time End If '将上机前的余额提出来,用于下机时计算余额 txtRemain.Text = mrc.Fields(7) '将该卡上机的信息填入到online_info表中 txtSQL5 = "select * from online_info" Set mrc5 = ExecuteSQL(txtSQL5, MsgText5) mrc5.AddNew mrc5.Fields(0) = txtCardID.Text mrc5.Fields(1) = txtType.Text mrc5.Fields(2) = txtSID.Text mrc5.Fields(3) = txtName.Text mrc5.Fields(4) = txtDepartment.Text mrc5.Fields(5) = txtSex.Text mrc5.Fields(6) = Date mrc5.Fields(7) = Time mrc5.Fields(8) = Trim(Environ("computername")) mrc5.Update '查询正在上机的人数 txtSQL6 = "select * from online_info" Set mrc6 = ExecuteSQL(txtSQL6, MsgText6) If mrc6.EOF = True Then lblnumber.Caption = 0 Else lblnumber.Caption = mrc6.RecordCount End If End If End If End If End If End Sub小结:其实上机这个点并不难,困难的是如何将各个表联系起来,在敲之前一定先做一个宏观的把控,先做什么后做什么,这样做起来也会很顺畅!
新闻热点
疑难解答