Selected students offline for the first computer room charging system

The idea of ​​selecting students offline is relatively simple. The following is my flow chart.

Code snippet display:

According to the flow chart, we first need to select the students who want to dismount, so in MSHFlexGrid1, select a row, this row should be changed color to distinguish whether it is selected.

Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim col As Integer
    If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = "??" Then '?判断是否选中这一行,没有选中,点击后即可选中
        MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = ""

For col = 0 To MSHFlexGrid1.Cols - 1 '从第0行到总列数
            '恢复颜色为白色
            MSHFlexGrid1.col = col
            MSHFlexGrid1.CellBackColor = vbWhite
        Next col
    Else
        MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = "??"
        '??????
        For col = 0 To MSHFlexGrid1.Cols - 1
            MSHFlexGrid1.col = col
            MSHFlexGrid1.CellBackColor = &HFFFF00
        Next col

    End If

If a certain row is selected, the "selected students to disembark" button is available, otherwise it is not available

If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = "√" Then
        SelStuOffline.Enabled = True
    Else
        SelStuOffline.Enabled = False
    End If

Select the student's off-machine code

Private Sub SelStuOffline_Click()'Select the student offline
    Dim sz(999) As String'The array used to store the student ID of the code check
    Dim xh(999) As
    String'The line number used to store the code check Dim txtCash As String 'Balance
    Dim consume As
    String'Store the consumption amount Dim consumtime As String'Store the total time
    
    Dim z As Integer'Store the variable
    Dim i As Integer used for the student number with checkmark'Variable
    Dim s As Integer called when changing the color ' variable number is stored with a check of the line used
    Dim j as Integer 'line number
    Dim t' time
    Dim bob as Boolean 'flag is used to show all the button click, and the beginning defaults to false
    Dim txtSQL of as String
    Dim txtSQL1 of as String
    Dim Msgtext As String
    Dim OnLine As ADODB.Recordset'Connect to the student table
    Dim mrc1 As ADODB.Recordset'On behalf of the online table there is a time limit
    Dim line As ADODB.Recordset
    BAS of As ADODB.Recordset Dim
    Dim STU of As ADODB.Recordset
    Dim MRC2 of As ADODB.Recordset
    
    With MSHFlexGrid1
    
        the If = 0 .RowSel the Then
            MsgBox "Please select the card to the next machine", vbOKOnly + vbExclamation, "prompt"
        Else
            'is selected by the recording machine Add a check mark in the last line and store all the card number information of these records in the sz array
            i =                 0'The first of the array is 0
            For j = 1 To .Rows-1
If .TextMatrix(j, 5 ) = "√"
                    Then'Record the line number with check mark sz(i) = .TextMatrix(j, 0)'Save the card number data in the sz array
                    xh(i) = Val(j)'Save the line number to
                    i = i + 1
                End If
            Next j
            
            For z = 0 To i-1 in the xh array
                txtSQL = "select * from BasicData_info"
                Set bas = ExecuteSQL(txtSQL, Msgtext)
                
                txtSQL = "select * from student_info where cardno= '" & sz(z) & "' and status='" & "使用" & "'"
                Set stu = ExecuteSQL(txtSQL, Msgtext)
                
                txtSQL = "select * from OnLine_info where cardno='" & sz(z) & "'"
                Set OnLine = ExecuteSQL(txtSQL, Msgtext)
                
                consumtime = DateDiff("n", Trim(OnLine!Date), Now) '计算消费金额
                If Val(consumtime) <= Val(bas!preparetime) Then 'The consumption time is less than the minimum prescribed time, and the consumption amount is 0.                     If Val(consumtime) Mod Val(bas!unitTime) = 0 Then'Calculate the consumption time                 Else
                    consume = 0


                        t = Int(consumtime / bas!unitTime)
                    Else
                        t = Int(consumtime / bas!unitTime) + 1
                    End If
                    
                    If stu.EOF Then
                        MsgBox "This card number is not registered or has been refunded", vbOKOnly + vbExclamation, "Prompt"
                        Exit Sub
                        
                    Else'Judging
                        whether it is a fixed user or a temporary user
                        If Trim(stu!Type) = Trim("fixed user") Then
                            consume = t * bas.Fields(0)
                        Else
                            consume = t * bas.Fields(1)
                        End If
                    End If
                End If
                
                txtCash = Val(stu!cash) - consume '计算余额
                
                '更新line表
                txtSQL = "select * from Line_info where cardno='" & sz(z) & "' and ondate='" & OnLine!OnDate & "' and ontime='" & OnLine!OnTime & "'"
                Set mrc1 = ExecuteSQL(txtSQL, Msgtext)
                mrc1.Fields(1) = sz(z)
                mrc1.Fields(2) = Trim(stu.Fields(1))
                mrc1.Fields(3) = Trim(stu.Fields(2))
                mrc1.Fields(4) = Trim(stu.Fields(4))
                mrc1.Fields(5) = Trim(stu.Fields(3))
                mrc1.Fields(6) = Trim(stu.Fields(6))
                mrc1.Fields(7) = Trim(stu.Fields(7))
                mrc1.Fields(10) = consumtime
                mrc1.Fields(11) = consume
                mrc1.Fields(12) = Val(txtCash)
                mrc1.Fields(13) = "正常下机"
                mrc1.Fields(14) = GetThisComputerName
                mrc1.Fields(8) = Date
                mrc1.Fields(9) = Time
              
                stu.Close
                OnLine.Close
                
                '更新学生表
                txtSQL = "select * from student_info where cardno='" & Trim(sz(z)) & "'"
                Set mrc2 = ExecuteSQL(txtSQL, Msgtext)
                mrc2.Fields(7) = txtCash
                mrc2.Update
                '更新online表
                txtSQL1 = "delete from OnLine_Info where cardno='" & Trim(sz(z)) & "'"
                Set OnLine = ExecuteSQL(txtSQL1, Msgtext)
              
            Next z
            
            '更新msflexgrid1界面
            For s = 0 To i - 1
                If .Rows > 2 Then
                    .RemoveItem xh(s)
                Else
                    .Clear
                    .Enabled = False
                End If
            Next s
        End If
    End With
    
End Sub

Guess you like

Origin blog.csdn.net/weixin_45309155/article/details/106310216