The First Computer Room Charging System

Posted by marschen on Wed, 31 Jul 2019 03:08:35 +0200

For general users, the process of recharge record is the same as that of inquiring on-line record. The only difference is that the line_info table is replaced by the recharge_info table. The other similarities are not repeated. The following is a summary of general users'inquiry on-line status:

Operational procedures:

Click on Query - - Pop up the form of Conditional Query for Query
Click to show all - - - then show all users who are on the computer.
To complete the second step, you can click on all users to get off the computer and select to get off the computer - - - according to different ways to operate and connect the database to get off.

Use database tables:

Stud_info (Storing Student Information)
online_info
lind_info
Basic data_info (specifying unit price and time limit)

Specific process:

(The specific operation is the same as the operation process and will not be explained)

The code is as follows:

1. Display all

Private Sub ShowAll_Click()
    'Yes Online_Info Table operation
    Dim mrconline As ADODB.Recordset 'Used to store recordsets
    Dim onlineSQL As String 'For storage SQL Sentence
    Dim onlineMsgText As String 'Used to store return information
    
    onlineSQL = "select * from OnLine_Info"
    Set mrconline = ExecuteSQL(onlineSQL, onlineMsgText)
    
    If mrconline.EOF Then
        MsgBox "No students on the computer!", vbOKCancel + vbExclamation, "warning"
    Else
        With MSHFlexGrid
            Do While mrconline.EOF = False
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrconline.Fields(0))
                .TextMatrix(.Rows - 1, 1) = Trim(mrconline.Fields(3))
                .TextMatrix(.Rows - 1, 2) = Trim(mrconline.Fields(6))
                .TextMatrix(.Rows - 1, 3) = Trim(mrconline.Fields(7))
                .TextMatrix(.Rows - 1, 4) = Trim(mrconline.Fields(8))
                mrconline.MoveNext
            Loop
        End With
        mrconline.Close
    End If
    ShowAll.Enabled = False
    ManagementOn.Enabled = True
End Sub

2. Get off the plane altogether:

Private Sub AllOff_Click()
    Dim ADDTime As String 'Boarding time
    Dim Money As Double 'Consumption amount
    Dim Balance As Long 'balance
    Dim i As Integer 'For array rows
    'Yes student_info Table operation
    Dim mrcstudent As ADODB.Recordset 'Used to store recordsets
    Dim studentSQL As String 'For storage SQL Sentence
    Dim studentMsgText As String 'Used to store return information
    'Yes Oline_info Table operation
    Dim mrconline As ADODB.Recordset 'Used to store recordsets
    Dim onlineSQL As String 'For storage SQL Sentence
    Dim onlineMsgText As String 'Used to store return information
    'Yes line_info Table operation
    Dim mrcline As ADODB.Recordset 'Used to store recordsets
    Dim lineSQL As String 'For storage SQL Sentence
    Dim lineMsgText As String 'Used to store return information
    'Yes basic_info Table operation
    Dim mrcbasic As ADODB.Recordset 'Used to store recordsets
    Dim basicSQL As String 'For storage SQL Sentence
    Dim basicMsgText As String 'Used to store return information
     
    onlineSQL = "select * from online_info"
    Set mrconline = ExecuteSQL(onlineSQL, onlineMsgText)
    
    basicSQL = "select * from basicdata_info"
    Set mrcbasic = ExecuteSQL(basicSQL, basicMsgText)
    
    'Define an unknown array of rows
    ReDim a(mrconline.RecordCount) As String
    
    If mrconline.EOF = True Then
        MsgBox "No logon record, no logoff!", vbOKOnly + vbInformation, "Tips"
        Exit Sub
    Else
        mrconline.MoveFirst
    End If
    
    For i = 0 To mrconline.RecordCount - 1
        a(i) = Trim(mrconline.Fields(0))
    
        studentSQL = "select * from student_info where cardno='" & Trim(mrconline.Fields(0)) & "'"
        Set mrcstudent = ExecuteSQL(studentSQL, studentMsgText)
        
        lineSQL = "select * from Line_Info where status= 'Normal boarding' and cardno='" & Trim(mrconline.Fields(0)) & "'"
        Set mrcline = ExecuteSQL(lineSQL, lineMsgText)
        
        'abs()Absolute value function in function; datediff("Company",Date 1,Date 2) Calculating time difference; val()Function Character to Number
        ADDTime = Abs(Val(DateDiff("n", Trim(mrconline.Fields(9)), Now)))
        If ADDTime < Val(mrcbasic.Fields(4)) Then
            Balance = Trim(mrcstudent.Fields(7))
        Else
            If ADDTime < Val(mrcbasic.Fields(3)) Then
                Money = "1"
                Balance = Val(mrcstudent.Fields(7)) - Money
            Else
                If mrconline.Fields(1) = "Fixed users" Then
                    'round()Round off two decimal digits; cdbl()take string Convert to double type
                    Money = Round(CDbl(ADDTime) * mrcbasic.Fields(0) / 60)
                    Balance = Val(mrcstudent.Fields(7)) - Money
                Else
                    Money = Round(CDbl(ADDTime) * mrcbasic.Fields(1) / 60)
                    Balance = Val(mrcstudent.Fields(7)) - Money
                End If
            End If
        End If
        If Balance < 0 Then
            MsgBox "Card number:" & a(i) & "The balance is insufficient to get off the plane!", vbOKCancel + vbQuestion, "Tips"
            mrconline.MoveNext
        Else
            'Change data table Student
            mrcstudent.Fields(7) = Trim(Balance)
            mrcstudent.Fields(11) = "Unsettled accounts"
            mrcstudent.Update
            mrcstudent.Close
            'Update data table line
            mrcline.Fields(8) = Date
            mrcline.Fields(9) = Time
            mrcline.Fields(10) = ADDTime
            mrcline.Fields(11) = Trim(Money)
            mrcline.Fields(12) = Trim(Balance)
            mrcline.Fields(13) = "Get off the plane normally"
            mrcline.MoveNext
            mrconline.Delete
            mrconline.MoveNext
        End If
    Next i
    mrconline.Close
    mrcline.Close
    mrcbasic.Close
    MsgBox "All the students are off the plane!", vbOKOnly + vbExclamation, "Tips"
    MSHFlexGrid.Clear
    ShowAll.Enabled = True
    ManagementOn.Enabled = False
    frmMain.lblNOWPeople.Caption = 0
    With MSHFlexGrid
        .Rows = 1
        .TextMatrix(0, 0) = "Card number"
        .TextMatrix(0, 1) = "Full name"
        .TextMatrix(0, 2) = "Boarding date"
        .TextMatrix(0, 3) = "Boarding time"
        .TextMatrix(0, 4) = "Room number"
        .TextMatrix(0, 5) = "Checked"
    End With
End Sub

3. Select a part to get off the machine

Private Sub MSHFlexGrid_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim column As Integer 'Define row number variables
    'Judging whether to select
    If MSHFlexGrid.TextMatrix(MSHFlexGrid.Row, 5) = "√" Then
        MSHFlexGrid.TextMatrix(MSHFlexGrid.Row, 5) = ""
        For column = 0 To MSHFlexGrid.Cols - 1
            MSHFlexGrid.Col = column
            MSHFlexGrid.CellBackColor = vbWhite
        Next column
    Else
        If MSHFlexGrid.TextMatrix(MSHFlexGrid.Row, 5) <> "Checked" Then
            MSHFlexGrid.TextMatrix(MSHFlexGrid.Row, 5) = "√"
            For column = 0 To MSHFlexGrid.Cols - 1
                MSHFlexGrid.Col = column
                MSHFlexGrid.CellBackColor = vbGreen
            Next column
        End If
    End If
End Sub
Private Sub SomeOff_Click()
    Dim a As Integer 'Used to judge the number of people who choose to get off the plane
    Dim Line1 As Integer 'Be used for FOR Cyclic variables
    Dim line As Integer 'Be used for FOR Cyclic variables
    Dim ADDTime As Double 'Boarding time
    Dim Money As Double 'Consumption amount
    Dim Balance As Double 'balance
    'Yes student_info Table operation
    Dim mrcstudent As ADODB.Recordset 'Used to store recordsets
    Dim studentSQL As String 'For storage SQL Sentence
    Dim studentMsgText As String 'Used to store return information
     'Yes Oline_info Table operation
    Dim mrconline As ADODB.Recordset 'Used to store recordsets
    Dim onlineSQL As String 'For storage SQL Sentence
    Dim onlineMsgText As String 'Used to store return information
    'Yes Online_info Table reoperation
    Dim mrconline1 As ADODB.Recordset 'Used to store recordsets
    Dim onlineSQL1 As String 'For storage SQL Sentence
    Dim onlineMsgText1 As String 'Used to store return information
    'Yes line_info Table operation
    Dim mrcline As ADODB.Recordset 'Used to store recordsets
    Dim lineSQL As String 'For storage SQL Sentence
    Dim lineMsgText As String 'Used to store return information
    'Yes basic_info Table operation
    Dim mrcbasic As ADODB.Recordset 'Used to store recordsets
    Dim basicSQL As String 'For storage SQL Sentence
    Dim basicMsgText As String 'Used to store return information
    flag = True
    a = 0
    For Line1 = MSHFlexGrid.Rows To 1 Step -1
        If MSHFlexGrid.TextMatrix(Line1 - 1, 5) = "√" Then
            a = a + 1
        End If
    Next Line1
    If a = 0 Then
        MsgBox "Please select the disembarkation crew!", vbOKOnly + vbExclamation, "warning"
        Exit Sub
    Else
        For line = MSHFlexGrid.Rows To 2 Step -1
            If MSHFlexGrid.TextMatrix(line - 1, 5) = "√" Then
                onlineSQL = "select * from online_info where cardno='" & Trim(MSHFlexGrid.TextMatrix(line - 1, 0)) & "'"
                Set mrconline = ExecuteSQL(onlineSQL, onlineMsgText)
    
                lineSQL = "select * from Line_Info where cardno='" & Trim(MSHFlexGrid.TextMatrix(line - 1, 0)) & "' and status= 'Normal boarding' "
                Set mrcline = ExecuteSQL(lineSQL, lineMsgText)
    
                basicSQL = "select * from basicdata_info"
                Set mrcbasic = ExecuteSQL(basicSQL, basicMsgText)
    
                studentSQL = "select * from student_info where cardno='" & Trim(MSHFlexGrid.TextMatrix(line - 1, 0)) & "'"
                Set mrcstudent = ExecuteSQL(studentSQL, studentMsgText)
    
                'abs()Absolute value function in function; datediff("Company",Date 1,Date 2) Calculating time difference; val()Function Character to Number
                ADDTime = Abs(Val(DateDiff("n", Trim(mrconline.Fields(9)), Now)))
                If ADDTime < Val(mrcbasic.Fields(4)) Then
                    mrcstudent.Fields(7) = Trim(mrcstudent.Fields(7))
                End If
                If ADDTime < Val(mrcbasic.Fields(3)) Then
                    Money = "1"
                    Balance = Val(mrcstudent.Fields(7)) - Money
                End If
                If mrconline.Fields(1) = "Fixed users" Then
                    'round()Round off two decimal digits; cdbl()take string Convert to double type
                    Money = Round(CDbl(ADDTime) * mrcbasic.Fields(0) / 60)
                    Balance = Val(mrcstudent.Fields(7)) - Money
                Else
                    Money = Round(CDbl(ADDTime) * mrcbasic.Fields(1) / 60)
                    Balance = Val(mrcstudent.Fields(7)) - Money
                End If
                If Balance < 0 Then
                    MsgBox "The balance of this card is insufficient to get off!", vbOKCancel + vbQuestion, "Tips"
                    mrconline.MoveNext
                Else
                    mrcstudent.Fields(7) = Trim(Balance)
                    mrcstudent.Fields(11) = "Unsettled accounts"
                    mrcstudent.Update
                    mrcstudent.Close
                    mrcline.Fields(8) = Date
                    mrcline.Fields(9) = Time
                    mrcline.Fields(10) = ADDTime
                    mrcline.Fields(11) = Trim(Money)
                    mrcline.Fields(12) = Trim(Balance)
                    mrcline.Fields(13) = "Get off the plane normally"
                    mrcline.Update
                    mrcline.Close
                    mrconline.Delete
                    mrconline.Close
                    mrcbasic.Close
                    MSHFlexGrid.RemoveItem line - 1
                End If
            End If
        Next line
        MsgBox "The selected students are off the plane!", vbOKOnly + vbInformation, "Tips"
        ShowAll.Enabled = True
    End If
    'Display the number of people on board
    onlineSQL1 = "select * from OnLine_info"
    Set mrconline1 = ExecuteSQL(onlineSQL1, onlineMsgText1)
    If mrconline1.EOF Then
        frmMain.lblNOWPeople.Caption = 0
    Else
        frmMain.lblNOWPeople.Caption = mrconline1.RecordCount 'Calculate the total number of people on board
    End If
End Sub

4. Conditional Query
For conditional queries, see the following blog

Topics: SQL Database