VB machine room charging system 06 - on and off

Keywords: less

operate a computer

On board flow chart


Here, I think it's the addition, deletion, modification and query of data table. For those who don't have ideas, please refer to my full code
'operate a computer
Private Sub cmdonline_Click(Index As Integer)
    Dim mrc As ADODB.Recordset
    Dim txtsql As String
    Dim msgtext As String
    
    
    'Enter student ID or not
    If Not testtxt(cardno.Text) Then
        MsgBox "Please enter student ID!", vbOKOnly + vbExclamation, "warning"
        cardno.SetFocus
        Exit Sub
    Else
    
    
    'Verify that the user is on the computer
            txtsql = "select * from onLine_Info where cardno='" & Trim(cardno.Text) & "'"
            Set mrc1 = ExecuteSQL(txtsql, msgtext)
            
    If mrc1.EOF = False Then
        MsgBox "This account is already on the computer,Duplicate login not allowed!", vbOKOnly + vbExclamation, "warning"
        cardno.Text = ""
        studentName.Text = ""
        dept.Text = ""
        sex.Text = ""
        class.Text = ""
        grade.Text = ""
        status.Text = ""
        style.Text = ""
    Else
            
     
    'Verify student ID exists
        txtsql = "select * from student_Info where cardno ='" & cardno.Text & "'"
        Set mrc = ExecuteSQL(txtsql, msgtext)
         If mrc.EOF = True Then
            MsgBox txtsql
            MsgBox msgtext
            MsgBox "This user name does not exist, please re-enter!", vbOKOnly + vbExclamation, "warning"
            cardno.SetFocus
         Else
         
         
    'Verify balance is sufficient
         If Val(mrc.Fields(7)) < 5 Then
            MsgBox "Insufficient balance, please recharge first", vbOKOnly + vbExclamation, "warning"
            cardno.Text = ""
            Exit Sub
         Else
            cardno.Text = mrc.Fields(0)
            studentName.Text = mrc.Fields(2)
            dept.Text = mrc.Fields(4)
            sex.Text = mrc.Fields(3)
            class.Text = mrc.Fields(6)
            grade.Text = mrc.Fields(5)
            status.Text = mrc.Fields(10)
            style.Text = mrc.Fields(14)
            ondate.Text = Date
            ontime.Text = Time
            havemoney = mrc.Fields(7)

        
    'Update the number of people on board
        txtsql = "select * from onLine_Info"
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
        
        txtsql = "select * from User_Info"
        Set mrc2 = ExecuteSQL(txtsql, msgtext)
        
        mrc1.AddNew
        
        mrc1.Fields(0) = Trim(cardno.Text)
        mrc1.Fields(1) = Trim(style.Text)
        mrc1.Fields(2) = Trim(cardno.Text)
        mrc1.Fields(3) = Trim(studentName.Text)
        mrc1.Fields(4) = Trim(dept.Text)
        mrc1.Fields(5) = Trim(sex.Text)
        mrc1.Fields(6) = Date
        mrc1.Fields(7) = Time
        mrc1.Fields(8) = ""
        mrc1.Fields(9) = ""
        
        
        mrc.Fields(9) = mrc2.Fields(0)
        mrc1.Update
        onlineNumber.Caption = mrc1.RecordCount
        nowtime.Caption = Time
        MsgBox "Successful operation!", vbOKOnly + vbExclamation, "Tips"
        mrc1.Close
        
        
        


End If
End If
End If
End If
End Sub



Down machine

In short, the process of getting off the computer is to delete the data in the table on the computer and record the data on the computer.
The difficulty lies in the use of multiple tables, consumption time, consumption balance, amount calculation and so on.

flow chart



All the reference codes are as follows, hoping to help you establish the global logic of the computer.


'Down machine
Private Sub cmddown_Click()
'Judge whether the student number is entered
    Dim msgtext As String
    Dim txtsql As String
    Dim txtdate As String
    Dim txttime As String
    Dim intconsumetime As String
    Dim inttime As String
    Dim intstyle As String
    Dim cash As String
    Dim unittime As String
    Dim rate As String
    
                                                                      
    If cardno.Text = "" Then
        MsgBox "Please enter student ID!", vbOKOnly + vbExclamation, "warning"
    Else
'Determine whether the user is on the computer
        txtsql = "select * from OnLine_Info where cardno='" & Trim(cardno.Text) & "'"
        Set mrc = ExecuteSQL(txtsql, msgtext)
        
        If mrc.EOF = True Then
            MsgBox "The card number is not on the computer,Please reconfirm", vbOKOnly + vbExclamation, "warning"
            cardno.Text = ""
            studentname.Text = ""
            dept.Text = ""
            sex.Text = ""
            class.Text = ""
            grade.Text = ""
            status.Text = ""
            style.Text = ""
        Else
'Display account data
        txtsql = "select * from student_Info"
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
        
        txtsql = "select * from BasicData_Info"
        Set mrc2 = ExecuteSQL(txtsql, msgtext)
        
            style.Text = mrc.Fields(1)
            cardno.Text = mrc.Fields(0)
            studentname.Text = mrc.Fields(3)
            dept.Text = mrc.Fields(4)
            sex.Text = mrc.Fields(5)
            ondate.Text = Format(Trim(mrc.Fields(6)), "yyyy-mm-dd")
            ontime.Text = Format(Trim(mrc.Fields(7)), "hh:mm:ss")
            class.Text = mrc1.Fields(6)
            grade.Text = mrc1.Fields(5)
            status.Text = mrc1.Fields(10)
            txtupdate.Text = Format(Date, "yyyy-mm-dd")
            uptime.Text = Format(Time, "hh:mm:ss")


'Offline settlement: time,Amount of money
        txtdate = DateDiff("n", ondate, txtupdate)
        txttime = DateDiff("n", ontime, uptime)
        txtconsumetime.Text = Int(txttime) + Int(txtdate)
        intcousumetime = txtconsumetime.Text
        
        If intcousumetime < mrc2.Fields(4) Then               'Judge whether the consumption time is less than the preparation time
           txtconsumetime = "0"
           spendmoney.Text = "0"
           havemoney.Text = Trim(mrc.Fields(7))
           
        End If
           
        If intcousumetime < mrc2.Fields(3) Then               'The consumption amount is 1 when the consumption time is less than the minimum on-board time
           txtconsumetime = "0"
           spendmoney.Text = "1"
           havemoney.Text = Trim(mrc.Fields(7)) - Trim(spendmoney.Text)
           MsgBox "Get off the machine successfully!", vbonly + vbExclamation, "Tips"
           
        Else
        
        If mrc1.Fields(14) = "Temporary users" Then                  'Judge the consumption amount of temporary users
            spendmoney.Text = (Int(intcousumetime / 60) + 1) * Trim(mrc2.Fields(0))
            havemoney.Text = Trim(mrc1.Fields(7)) - Trim(spendmoney.Text)
        
        
        Else                                                 'Determine the consumption amount of fixed users
        
            spendmoney.Text = (Int(intcousumetime / 60) + 1) * Trim(mrc2.Fields(1))
            havemoney.Text = Trim(mrc1.Fields(7)) - Trim(spendmoney.Text)
        End If
        MsgBox "Get off the machine successfully!", vbonly + vbExclamation, "Tips"
        End If
        
'Empty text box
            style.Text = ""
            cardno.Text = ""
            studentname = ""
            dept.Text = ""
            sex.Text = ""
            ondate.Text = ""
            ontime.Text = ""
            class.Text = ""
            grade.Text = ""
            status.Text = ""
            txtupdate.Text = ""
            uptime.Text = ""
            spendmoney.Text = ""
            txtconsumetime = ""
            havemoney = ""

'Update on-board record
        mrc.Delete
        mrc.Update
        mrc.Close
        
'Update history on computer
        
        txtsql = "select * from Line_info where cardno='" & Trim(cardno.Text) & "'"
        Set mrc4 = ExecuteSQL(txtsql, msgtext)
        If Not mrc4.EOF Then
            mrc4.Fields(8) = Trim(txtupdate.Text)
            mrc4.Fields(9) = Trim(uptime.Text)
            mrc4.Fields(10) = Trim(txtconsumetime.Text)
            mrc4.Fields(11) = Trim(spendmoney.Text)
            mrc4.Fields(12) = Trim(havemoney.Text)
            mrc4.Fields(13) = "It's off"
            mrc4.Update
            mrc4.Close
        End If

'Update the number of people on board
        txtsql = "select * from online_info"
        Set mrc5 = ExecuteSQL(txtsql, msgtext)
        onlineNumber.Caption = "The current number of people on board is:" & mrc5.RecordCount
        mrc5.Close

'Show current time
        nowtime.Caption = Time
End If
End If
End Sub



epilogue

This column is mainly for readers who don't have ideas, so I post the source code to provide ideas, part of the code reference.
I believe that for the small white without ideas, it's not significant to see the blog with partial code.

Posted by QuietWhistler on Mon, 04 May 2020 18:28:47 -0700