# Computer room charging system (4)

Recently, the computer room charging system has entered the final sprint period. The most core part of the computer room charging system is the up and down buttons. At first, I always felt dizzy. I didn't know how to design the codes of these two buttons. But with the help of many students, I finally figured out the logic and completed the design of these two buttons.

The design of these two buttons has the same subtlety, forming a closed cycle. With the help of these two mind maps, I have made clear the logic of these two buttons. The previous steps of the two buttons are very similar, but the button for getting off the computer is less to judge whether the card number can be used. Because it can be used to get on the computer, it is unnecessary to judge whether the card number can be used again. The next step will be a little more because we need to judge the consumption amount,

```Private Sub cmdOffline_Click()

Dim txtSQL As String
Dim MsgText As String

'Is the card number empty
If txtCardno = "" Then
MsgBox "Please enter the card number!", vbOKOnly, "Tips"
txtCardno.SetFocus
txtCardno = ""
Exit Sub
End If

'Whether the card number exists
txtSQL = "select * from student_Info where cardno='" & Trim(txtCardno.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "The card number does not exist!", vbOKOnly, "Tips"
txtCardno.SetFocus
txtCardno = ""
Exit Sub
End If

'Is the card number on the computer
txtSQL = "select * from OnLine_Info where cardno='" & Trim(txtCardno.Text) & "'"
Set mrc3 = ExecuteSQL(txtSQL, MsgText)
If mrc3.EOF Then
MsgBox "The user is not on the computer!", vbOKOnly, "Tips"
txtCardno.SetFocus
txtCardno = ""
txtType.Text = ""
txtStudentno.Text = ""
txtName.Text = ""
txtDepartment.Text = ""
comboSex.Text = ""
txtOnlinedate.Text = ""
txtOnlinetime.Text = ""
txtOfflinedate.Text = ""
txtOfflinetime.Text = ""
txtTime.Text = ""
txtRemaincash.Text = ""
txtUsedcash.Text = ""
Exit Sub
End If

'Update interface information
txtType.Text = Trim(mrc3.Fields(1))
txtStudentno.Text = Trim(mrc3.Fields(2))
txtName.Text = Trim(mrc3.Fields(3))
txtDepartment.Text = Trim(mrc3.Fields(4))
comboSex.Text = Trim(mrc3.Fields(5))
txtOnlinedate.Text = Trim(mrc3.Fields(6))
txtOnlinetime.Text = Trim(mrc3.Fields(7))
txtOfflinedate.Text = Trim(Date)
txtOfflinetime.Text = Trim(Time)
txtTime.Text = Trim(DateDiff("n", Trim(txtOnlinetime.Text), Trim(Time))) 'Convert time difference to minutes

'Get data from basic data table
txtSQL = "select * from BasicData_Info "
Set mrc1 = ExecuteSQL(txtSQL, MsgText)

'Calculate consumption amount
Dim MinTime As Integer
Dim AllTime As Single
Dim Rate As Single
Dim Money As Integer

MinTime = mrc1.Fields(3)
AllTime = txtTime.Text

'The on-board time is less than the preparation time, not counting the time,No money
If Trim(txtTime.Text) < MinTime Then
txtTime.Text = 0 & ""
Money = 0
Else
If AllTime > MinTime Then
Do While AllTime > MinTime
AllTime = AllTime - 30
If mrc.Fields(14) = "Fixed users" Then
Money = Money + 2
Else
Money = Money + 3
End If
Loop
End If
End If
txtUsedcash.Text = Money

'Calculate balance
txtSQL = "select * from student_Info where cardno='" & Trim(txtCardno.Text) & "'and status='" & "Use" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)

txtRemaincash.Text = Val(Trim(mrc.Fields(7))) - Val(Trim(txtUsedcash.Text))

txtSQL = "Update student_Info set cash='" & Trim(txtUsedcash.Text) & "' where cardno='" & Trim(txtCardno.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)

MsgBox "Get off the machine successfully!", vbOKOnly, "Tips"

'To update Line surface
txtSQL = "select * from Line_Info "
Set mrc2 = ExecuteSQL(txtSQL, MsgText)

If Not mrc2.EOF Then
mrc2.Fields(1) = Trim(txtCardno.Text)
mrc2.Fields(2) = Trim(txtStudentno.Text)
mrc2.Fields(3) = Trim(txtName.Text)
mrc2.Fields(4) = Trim(txtDepartment.Text)
mrc2.Fields(5) = Trim(comboSex.Text)
mrc2.Fields(6) = Trim(txtOnlinedate.Text)
mrc2.Fields(7) = Trim(txtOnlinetime.Text)
mrc2.Fields(8) = Trim(txtOfflinedate.Text)
mrc2.Fields(9) = Trim(txtOfflinetime.Text)
mrc2.Fields(10) = Trim(txtTime.Text)
mrc2.Fields(11) = Trim(txtUsedcash.Text)
mrc2.Fields(12) = Trim(txtRemaincash.Text)
mrc2.Fields(13) = "Get off the machine normally"
mrc2.Fields(14) = Trim(Environ("computername"))
mrc2.Update
mrc2.Close
End If

mrc3.Delete

'Update the number of people on board
txtSQL = "select count(*) from OnLine_Info "
Set mrc3 = ExecuteSQL(txtSQL, MsgText)
Label15.Caption = "The current number of people on board is:" & Trim(mrc3.RecordCount)

End Sub

Private Sub cmdOnline_Click()

Dim txtSQL As String
Dim MsgText As String
Dim miCount As Integer

txtType.Text = ""
txtStudentno.Text = ""
txtName.Text = ""
txtDepartment.Text = ""
comboSex.Text = ""
txtOnlinedate.Text = ""
txtOnlinetime.Text = ""
txtOfflinedate.Text = ""
txtOfflinetime.Text = ""
txtTime.Text = ""
txtRemaincash.Text = ""
txtUsedcash.Text = ""

'Is card number empty
If txtCardno = "" Then
MsgBox "Please enter the card number!", vbOKOnly, "Tips"
txtCardno.SetFocus
txtCardno = ""
Exit Sub
End If

'Is the card number registered
txtSQL = "select * from student_Info where cardno='" & Trim(txtCardno.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "The card number has not been registered, please re-enter!", vbOKOnly, "Tips"
txtCardno.SetFocus
txtCardno = ""
Exit Sub
End If

'Is the card number on the computer
txtSQL = "select * from OnLine_Info where cardno='" & Trim(txtCardno.Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL, MsgText)
If mrc1.EOF = False Then
MsgBox "The card number is on the plane!", vbOKOnly, "Tips"
txtCardno = ""
txtCardno.SetFocus
txtType.Text = ""
txtStudentno.Text = ""
txtName.Text = ""
txtDepartment.Text = ""
comboSex.Text = ""
txtOnlinedate.Text = ""
txtOnlinetime.Text = ""
txtOfflinedate.Text = ""
txtOfflinetime.Text = ""
txtTime.Text = ""
txtRemaincash.Text = ""
txtUsedcash.Text = ""
Exit Sub

End If

'Whether the card number has insufficient balance
If mrc.Fields(7) <= 5 Then
If MsgBox("The balance of this card number is insufficient. Do you want to recharge it?", vbOKCancel, "Tips") = vbOK Then
frmrecharge.Show , Me
End If
Exit Sub
End If

'Card number usage status
If mrc.Fields(10) = "not used" Then
If MsgBox("This card has not been activated. Do you want to modify the student information?", vbOKCancel, "Tips") = vbOK Then
frmmodifysinfo.Show , Me
End If
Exit Sub
End If

'Set basic data or not
txtSQL = "select * from basicdata_Info"
Set mrc3 = ExecuteSQL(txtSQL, MsgText)
If mrc3.EOF Then
If MsgBox("The basic data of this card has not been set and cannot be logged in. Do you want to set it?", vbOKCancel, "Tips") = vbOK Then
frmsetbasicdata.Show , Me
End If
Exit Sub
End If

'Successful on-board, update on-board interface information
txtSQL = "select * from student_Info where cardno='" & Trim(txtCardno.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'Display data
txtStudentno.Text = Trim(mrc.Fields(1))
txtDepartment.Text = Trim(mrc.Fields(4))
txtType.Text = Trim(mrc.Fields(14))
txtName.Text = Trim(mrc.Fields(2))
comboSex.Text = Trim(mrc.Fields(3))
txtOnlinedate.Text = Trim(Date)
txtOnlinetime.Text = Trim(Time)
txtRemaincash.Text = Val(Trim(mrc.Fields(7)))

'Update the information of the computer table
txtSQL = "select * from OnLine_Info"
Set mrc1 = ExecuteSQL(txtSQL, MsgText)

mrc1.Fields(0) = Trim(txtCardno.Text)
mrc1.Fields(1) = Trim(txtType.Text)
mrc1.Fields(2) = Trim(txtStudentno.Text)
mrc1.Fields(3) = Trim(txtName.Text)
mrc1.Fields(4) = Trim(txtDepartment.Text)
mrc1.Fields(5) = Trim(comboSex.Text)
mrc1.Fields(6) = Trim(txtOnlinedate.Text)
mrc1.Fields(7) = Trim(txtOnlinetime.Text)
mrc1.Fields(8) = Trim("ZOEY")
mrc1.Fields(9) = Trim(Date)
mrc1.Update
lblOnlineNum.Caption = mrc1.RecordCount
'Display the current number of people on board
mrc1.Close

txtSQL = "select * from Line_Info"
Set mrc2 = ExecuteSQL(txtSQL, MsgText)
mrc2.Fields(1) = Trim(txtCardno.Text)
mrc2.Fields(2) = Trim(txtStudentno.Text)
mrc2.Fields(3) = Trim(txtName.Text)
mrc2.Fields(4) = Trim(txtDepartment.Text)
mrc2.Fields(5) = Trim(comboSex.Text)
mrc2.Fields(6) = Trim(txtOnlinedate.Text)
mrc2.Fields(7) = Trim(txtOnlinetime.Text)
mrc2.Fields(13) = Trim("Normal operation")
mrc2.Fields(14) = Trim("ZOEY")
mrc2.Update
mrc2.Close

'Update the number of people on board
txtSQL = "select count(*) from OnLine_Info "
Set mrc1 = ExecuteSQL(txtSQL, MsgText)

Label15.Caption = "The current number of people on board is:" & Trim(mrc1.RecordCount + 1)

End Sub```
The design of the whole code can only be completed with the help of many students. Thank you to those who have helped me. Without you, I would not be today.

Tags: less

Posted on Mon, 04 May 2020 03:45:29 -0400 by kurdishvoice