经过两天的不断研究,终于将第一次机房的上机做了出来,不多废话,先贴流程图 上机
上机的基本思路就是,先查询卡号是否存在,是否已经上机,如果符合要求就添加上机记录和上机状态,这个还是比较简单的,不是特别的复杂
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
这里要注意的是添加上机记录的时候,表数据是不完整的,下机时间以及金额等字段是需要下机的时候进行更新,这里最好标记下来。
获取计算机名称的方法:txtComputername.Text = VBA.Environ("computername"),
标签:mrc1,mrc2,上机,之上,第一次,机房,Fields,mrc,Text From: https://blog.51cto.com/u_15854472/5915750