前言:
今天進(jìn)行上機(jī)部分的學(xué)習(xí),主要是宏觀邏輯的把控和對(duì)查詢(xún)語(yǔ)句的使用,首先我畫(huà)了個(gè)邏輯圖梳理思路,要做什么?先后順序?以及用到的知識(shí)點(diǎn)!
一、上機(jī)—輸入卡號(hào)
二、判斷卡號(hào)輸入是否規(guī)范
1.是否輸入?2.是否為數(shù)字?(用代碼限制輸入)
三、判斷是否注冊(cè)
查詢(xún)Student_info中的studentId
四、判斷卡內(nèi)是否有錢(qián)
查詢(xún)Student_info中的cash(提示后要及時(shí)清空Text)
五、上機(jī)成功—更新數(shù)據(jù)表Online_info
查詢(xún)正在上機(jī)的人數(shù)
六、代碼展示:
PRivate Sub cmdUp_Click() Dim txtSQL As String '查詢(xún)student_info,判斷卡號(hào)是否注冊(cè) Dim txtSQL2 As String '查詢(xún)online_info,判斷卡號(hào)是否正在上機(jī) Dim txtSQL4 As String '查詢(xún)basicdata_info中的limitcash Dim txtSQL5 As String '將該卡上機(jī)的信息填入到online_info表中 Dim txtSQL6 As String '查詢(xún)正在上機(jī)的人數(shù) 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 '判斷卡號(hào)是否為空 If Trim(txtCardID.Text) = "" Then MsgBox "請(qǐng)輸入卡號(hào)!", vbOKOnly + vbExclamation, "提示" txtCardID.SetFocus Exit Sub Else If IsNumeric(txtCardID.Text) = False Then MsgBox "卡號(hào)必須輸入數(shù)字!", vbOKOnly + vbExclamation, "提示" txtCardID.Text = "" txtCardID.SetFocus ',清空輸入框,焦點(diǎn)返回到輸入框 Exit Sub End If '查詢(xún)數(shù)據(jù)庫(kù)中基本信息表 txtSQL = "select * from student_Info where cardno= '" & Trim(txtCardID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, MsgText) '判斷該卡號(hào)是否注冊(cè) If mrc.BOF And mrc.EOF Then MsgBox "該卡號(hào)未注冊(cè),請(qǐng)先注冊(cè)!", vbOKOnly + vbExclamation, "提示" txtCardID.Text = "" txtCardID.SetFocus Exit Sub Else '判斷卡號(hào)是否已經(jīng)退卡,退卡后不能上機(jī) If Trim(mrc.Fields(10)) = "未激活" Then MsgBox "該卡已經(jīng)退卡", vbOKCancel + vbInformation, "提示" txtCardID.Text = "" txtCardID.SetFocus Exit Sub Else '查詢(xún)basicdata_info中的limitcash txtSQL4 = "select * from basicdata_info" Set mrc4 = ExecuteSQL(txtSQL4, MsgText4) If Val(mrc.Fields(7)) < Val(mrc4.Fields(5)) Then MsgBox "余額不足,請(qǐng)充值后上機(jī)!", vbOKOnly + vbExclamation, "提示" txtCardID.Text = "" txtCardID.SetFocus Exit Sub Else '判斷卡號(hào)是否正在上機(jī) txtSQL2 = "select * from online_info where cardno='" & Trim(txtCardID.Text) & "'" Set mrc2 = ExecuteSQL(txtSQL2, MsgText2) '查詢(xún)student_info中的cash txtSQL = "select * from student_info where cardno='" & Trim(txtCardID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, MsgText) If mrc2.EOF = False Then MsgBox "該卡正在上機(jī)!" 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 '顯示該卡號(hào)的一些基本信息 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 '將上機(jī)前的余額提出來(lái),用于下機(jī)時(shí)計(jì)算余額 txtRemain.Text = mrc.Fields(7) '將該卡上機(jī)的信息填入到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 '查詢(xún)正在上機(jī)的人數(shù) 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小結(jié):其實(shí)上機(jī)這個(gè)點(diǎn)并不難,困難的是如何將各個(gè)表聯(lián)系起來(lái),在敲之前一定先做一個(gè)宏觀的把控,先做什么后做什么,這樣做起來(lái)也會(huì)很順暢!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注