After two days of continuous research, I finally made the first computer room on the computer, no nonsense, first post the flowchart
on board
The basic idea of getting on the machine is to first check whether the card number exists and whether it has already been on the machine. If it meets the requirements, add the machine record and the machine status. This is relatively simple, not particularly complicated.
Dim mrc1 As ADODB.Recordset '用来存储OnLine_info 的sql语句
Dim txtSQL1 As String '用来接收返回的结果
If txtCardName.Text = "" Then
MsgBox "卡号不能为空", vbOKCancel + vbExclamation, "警告"
Exit Sub
End If
txtSQL = "exec proc_sutdentinfo_select @cardno = '" & txtCardName.Text & "'" '连接数据库判断文本是否存在
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "卡号不存在", vbOKCancel + vbExclamation, "警告"
Exit Sub
Else
txtSQL1 = "exec proc_OnLine_info @cardno = '" & txtCardName.Text & "'" '连接Online表判断是否已经上机
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then '如果查不到说明没有上机
txtCardName.Text = mrc.Fields(0)
txtSID.Text = mrc.Fields(1)
txtName.Text = mrc.Fields(2)
ComboSex.Text = mrc.Fields(3)
txtDepartment.Text = mrc.Fields(4)
txtType.Text = mrc.Fields(10)
txtUpDate.Text = Date
txtUpTime.Text = Time
txtBalance.Text = mrc.Fields(9)
txtComputername.Text = VBA.Environ("computername")
mrc.Close '关闭学生表
mrc1.AddNew
mrc1.Fields(0) = txtCardName.Text
mrc1.Fields(1) = txtType.Text
mrc1.Fields(2) = txtSID.Text
mrc1.Fields(3) = txtName.Text
mrc1.Fields(4) = txtDepartment.Text
mrc1.Fields(5) = ComboSex.Text
mrc1.Fields(6) = txtUpDate.Text
mrc1.Fields(7) = txtUpTime.Text
mrc1.Fields(8) = txtComputername.Text
mrc1.Fields(9) = Now
mrc1.Update
mrc1.Close '关闭上机表
Else
MsgBox "此卡号已上机", vbOKCancel + vbExclamation, "警告"
Exit Sub
End If
End If
Dim mrc2 As ADODB.Recordset '用来访问line表存储记录
Dim txtSQL2 As String '用来接收返回的结果
txtSQL2 = "exec proc_Line_info" '连接Online表添加上机记录,下机的时候还要进行更改
Set mrc2 = ExecuteSQL(txtSQL2, MsgText)
mrc2.AddNew
mrc2.Fields(0) = txtCardName.Text
mrc2.Fields(1) = txtSID.Text
mrc2.Fields(2) = txtName.Text
mrc2.Fields(3) = txtDepartment.Text
mrc2.Fields(4) = ComboSex.Text
mrc2.Fields(5) = txtUpDate.Text
mrc2.Fields(6) = txtUpTime.Text
mrc2.Fields(10) = txtBalance.Text
mrc2.Fields(11) = "正常上机"
mrc2.Fields(12) = Trim(txtComputername.Text)
mrc2.Update
MsgBox "上机成功", vbOKCancel + vbExclamation, "提示"
mrc2.Close
Label9.Caption = Label9.Caption + 1
It should be noted here that the table data is incomplete when adding the log on machine. The fields such as the off-machine time and amount need to be updated when off-machine. It is best to mark them here.
How to get the computer name: txtComputername.Text = VBA.Environ("computername"),