機房收費系統——上機窗體
阿新 • • 發佈:2018-11-10
上機窗體是在註冊完之後需要上機的時候開始使用,但是具體的一些限制還是需要注意一下,比如該卡
號是否註冊,是否退卡等等,接下來就看看這個過程。
具體程式碼如下所示:
Private Sub cmdOnline_Click() '定義資料庫物件 Dim mrcStudent As adodb.Recordset Dim mrcCancelCard As adodb.Recordset Dim mrcOnline As adodb.Recordset Dim mrcLine As adodb.Recordset Dim mrcBasicData As adodb.Recordset '定義字串語句 Dim OnlineSQL As String Dim StudentSQL As String Dim BasicDataSQL As String Dim LineSQL As String '定義返回查詢資訊變數 Dim Onmsgtext As String Dim StuMsgtext As String Dim BMsgtext As String Dim LMsgtext As String '判斷是否輸入卡號 If Trim(txtCardNo.Text) = "" Then MsgBox "請輸入卡號!", 0 + 48, "溫馨提示" txtCardNo.SetFocus Exit Sub Else '判斷輸入的是否是數字 If Not IsNumeric(txtCardNo.Text) Then MsgBox "請輸入數字", 0 + 48, "溫馨提示" txtCardNo.Text = "" txtcard.SetFocus Exit Sub Else '判斷此卡是否存在 StudentSQL = "select * from student_info where cardno='" & Trim(txtCardNo.Text) & "'" Set mrcStudent = ExecuteSQL(StudentSQL, StuMsgtext) '判斷是否註冊 If mrcStudent.EOF Then MsgBox "此卡尚未註冊!", 0 + 48, "提示" txtCardNo.SetFocus txtCardNo.Text = "" mrcStudent.Close Exit Sub Else '判斷是否退卡 If mrcStudent.EOF = False And mrcStudent.Fields(10) = "未使用" Then MsgBox "該卡號已經退卡,不能上機!", 0 + 48, "警告" txtCardNo.Text = "" txtCardNo.SetFocus mrcStudent.Close Else '判斷餘額是否大於最小上機金額 If Val(mrcStudent.Fields(7)) < Val(Register.txtRecharge) Then MsgBox "親,餘額不足,請充值!", 0 + 48, "提示" mrcStudent.Close Exit Sub Else '判斷是否上機 OnlineSQL = "select * from online_info where cardno='" & txtCardNo.Text & "'" Set mrcOnline = ExecuteSQL(OnlineSQL, Onmsgtext) If Not mrcOnline.EOF Then MsgBox "此卡正在上機!", 0 + 48, "提示" Exit Sub Else '更新上下機介面 txtSID.Text = mrcStudent.Fields(1) txtDept.Text = mrcStudent.Fields(4) txtSex.Text = mrcStudent.Fields(3) txtondate.Text = Date txtOntime.Text = Time txttype.Text = mrcStudent.Fields(14) txtName.Text = mrcStudent.Fields(2) txtBalance.Text = mrcstduent.Fields(7) '餘額更新 '更新Online表 OnlineSQL = "select * from online_info where cardno='" & Trim(txtCardNo.Text) & "'" Set mrcOnline = ExecuteSQL(OnlineSQL, Onmsgtext) mrcOnline.AddNew mrcOnline.Fields(0) = Trim(txtcard.Text) mrcOnline.Fields(1) = Trim(txttype.Text) mrcOnline.Fields(2) = Trim(txtSID.Text) mrcOnline.Fields(3) = Trim(txtName.Text) mrcOnline.Fields(4) = Trim(txtDept.Text) mrcOnline.Fields(5) = Trim(txtSex.Text) mrcOnline.Fields(6) = Trim(txtondate.Text) mrcOnline.Fields(7) = Trim(txtOntime.Text) '獲取計算機的名字 mrcOnline.Fields(8) = Trim(VBA.Environ("computername")) mrcOnline.Fields(9) = Date mrcOnline.Update mrcOnline.Close '顯示正在上機的人數 OnlineSQL = "select * from online_info" Set mrcOnline = ExecuteSQL(OnlineSQL, Onmsgtext) If mrcOnline.EOF = True Then lblPeople.Caption = 0 Else lblPeople.Caption = mrcOnline.RecordCount End If label23.Caption = "歡迎光臨" End If End If End If End If End If End If End Sub
注意:這個窗體查詢了5個表,所以要定義5個連線資料庫的物件