1. 程式人生 > >機房上機,細心很重要

機房上機,細心很重要

機房上下機是一個非常重要的功能,敲窗體之前一定要先搞請上下機邏輯關係,其次就是要把限定的條件想周到這樣操作起來就容易多了。
上機,就是將以註冊的,在用的,金額充足等符合上機要求的卡號進行上機。
上機流程圖
在這裡插入圖片描述
一定要搞清楚上機的要求是什麼?和那幾個表相聯絡?在敲程式碼
上機部分展示

Private Sub Command1_Click()
    '卡號是否為空
    If txtCardNo = "" Then
        MsgBox "請輸入卡號!", 48, "提示"
        txtCardNo.Text = ""
        txtCardNo.SetFocus
        Exit Sub
    End If
    
     '判斷卡號是否為數字
        If Not IsNumeric(Trim(txtCardNo.Text)) Then
            
            MsgBox "請輸入數字!", 48, "提示"
            txtCardNo.SetFocus
            txtCardNo.Text = ""
            Exit Sub
        End If
        
        '判斷卡號是否註冊
        txtsql = "select * from student_info where cardno ='" & txtCardNo.Text & "'"
        Set mrc = ExecuteSQL(txtsql, msgtext)
        If mrc.EOF = True Then
            MsgBox "此卡號尚未註冊!", 48, "提示"
            txtCardNo.Text = ""
            txtCardNo.SetFocus
            Exit Sub
        Else
        
        '判斷卡號是否登出
        If Trim(mrc.Fields(10)) = Trim("未使用") Then
            MsgBox "該卡已經登出", 48, "提示"
            txtCardNo.Text = ""
            txtCardNo.SetFocus
            Exit Sub
        Else
          
        '判斷是否上機
        txtsql = "select * from online_info where cardno= '" & txtCardNo.Text & "'"
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
                
        If mrc1.EOF = False Then
            MsgBox "該卡正在上機,不能重複上機!", 48, "提示"
            '顯示該卡好的上機資訊
            txtType.Text = mrc1!cardtype
            txtStudentNO.Text = mrc1!studentno
            txtDept.Text = mrc1!department
            txtName.Text = mrc1!studentname
            ComboSex.Text = mrc1!sex
            txtonDate.Text = mrc1!ondate
            txtonTime.Text = mrc1!ontime
            txtsql = "select * from student_info where cardno='" & txtCardNo.Text & "'"
            Set mrc = ExecuteSQL(txtsql, msgtext)
            txtBalance.Text = mrc!cash
            '下機日期和時間要空著
            txtoffDate.Text = ""
            txtoffTime.Text = ""
            costTime.Text = ""
            costMoney.Text = ""
            mrc.Update
            mrc.Close
            Exit Sub
        Else
        
        '若該卡沒有上機,則顯示上機資訊
        txtsql = "select * from student_info where cardno= '" & Trim(txtCardNo.Text) & "'"
        Set mrc = ExecuteSQL(txtsql, msgtext)
            If mrc.EOF = False Then
                txtType.Text = mrc!Type
                txtStudentNO.Text = mrc!studentno
                txtDept.Text = mrc!department
                txtName.Text = mrc!studentname
                ComboSex.Text = mrc!sex
                txtonDate.Text = Date
                txtBalance.Text = mrc!cash
            '獲取系統時間
            txtonTime.Text = Format(DateTime.Time, "hh:mm:ss")
            txtBalance.Text = mrc!cash
            End If
        End If
    End If
End If
        
                    
        '判斷餘額是否小於最小金額,如需要充值在上機,強制下機
        
        txtsql = "select * from student_Info where cardno = '" & txtCardNo.Text & "'"
        Set mrc = ExecuteSQL(txtsql, msgtext)
        
        txtsql = "select * from basicdata_info "
        Set mrc4 = ExecuteSQL(txtsql, msgtext)
        If Val(mrc.Fields(7)) < Val(mrc4.Fields(5)) Then
            MsgBox "餘額小於最小限制金額,請充值後再上機!", 48, "提示"
            
            txtCardNo.Text = ""
            txtStudentNO.Text = ""
            txtDept.Text = ""
            txtType.Text = ""
            txtName.Text = ""
            ComboSex.Text = ""
            txtonDate.Text = ""
            txtonTime.Text = ""
            txtBalance.Text = ""
            txtCardNo.SetFocus
            Exit Sub
        End If
                        
                    
        '更新online表
        txtsql = "select * from OnLine_info"
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
            mrc1.AddNew
            mrc1!cardno = txtCardNo.Text
            mrc1!studentno = txtStudentNO.Text
            mrc1!department = txtDept.Text
            mrc1!cardtype = txtType.Text
            mrc1!studentname = txtName.Text
            mrc1!sex = ComboSex.Text
            mrc1!ondate = txtonDate.Text
            mrc1!ontime = txtonTime.Text
            mrc1!computer = Trim(VBA.Environ("computername"))
            mrc1!Date = Date
                    
            mrc1.Update
            mrc1.Close
                    
        '更新line表
        txtsql = "select * from Line_info where cardno = '" & txtCardNo.Text & "'"
        Set mrc2 = ExecuteSQL(txtsql, msgtext)
            mrc2.AddNew
            mrc2!cardno = txtCardNo.Text
            mrc2!studentno = txtStudentNO.Text
            mrc2!department = txtDept.Text
            mrc2!studentname = txtName.Text
            mrc2!sex = ComboSex.Text
            mrc2!ondate = txtonDate.Text
            mrc2!ontime = txtonTime.Text
            mrc2!cash = txtBalance.Text
            mrc2!Status = "正常上機"
            mrc2!computer = Trim(VBA.Environ("computername"))
                    
            mrc2.Update
            mrc2.Close
                    
        '更新上機人數
        txtsql = "select count(*) from OnLine_info "
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
            lblpeople.Caption = Trim(mrc1.Fields(0))
        '更新臨時使用者數
        txtsql = "select count(*) from OnLine_info where cardtype='臨時使用者 '"
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
            lblplain.Caption = Trim(mrc1.Fields(0))
        '更新固定使用者數
        txtsql = "select count(*) from OnLine_info where cardtype='固定使用者 '"
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
            lblmember.Caption = Trim(mrc1.Fields(0))
        
            mrc1.Close
                    
            MsgBox "上機成功!", 48, "提示"
                
        
End Sub

上機相對還是蠻簡單的,上機成功後一定要及時更新上機記錄表,正在上機表
後期陸續更新,歡迎評論區留言!