【机房】下机
【摘要】
机房收费系统的两个主要功能之一是下机。
首先要判断卡号是否为空
'判断卡号是否为空
If Trim(txtCardNo.Text) = "" Then
MsgBox "卡号为...
机房收费系统的两个主要功能之一是下机。
首先要判断卡号是否为空
'判断卡号是否为空
If Trim(txtCardNo.Text) = "" Then
MsgBox "卡号为空", 64, "温馨提示"
txtCardNo.SetFocus
Exit Sub
End If
- 1
- 2
- 3
- 4
- 5
- 6
判断这个卡号是否正在上机——连接online表
'判断该号是否上机
txtSQL = "select * from OnLine_info where cardno='" & Trim(txtCardNo.Text) & "'"
Set mrcOnLine = ExecuteSQL(txtSQL, MsgText)
If mrcOnLine.EOF = True Then
MsgBox "该号没有上机", 64, "温馨提示"
txtCardNo.Text = ""
txtCardNo.SetFocue
end if
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
然后需要判断上机时间是否小于准备时间、是否小于最小上机时间。
根据基本数据设定来判断,是否需要收费以及收费金额。
还需要将数据更新到online表和line表;需要将学生表中的数据展示出来。
完整代码展示:
Private Sub cmdOffLine_Click()
'消费时间
Dim ConsumeTime As String
Dim txtSQL As String
Dim MsgText As String
Dim Day, Minute As String
Dim mrcStu As ADODB.Recordset
Dim mrcdata As ADODB.Recordset
Dim mrcOnLine As ADODB.Recordset
Dim mrcLine As ADODB.Recordset
'判断卡号是否为空
If Trim(txtCardNo.Text) = "" Then
MsgBox "卡号为空", 64, "温馨提示"
txtCardNo.SetFocus
Exit Sub
End If
'判断该号是否上机
txtSQL = "select * from OnLine_info where cardno='" & Trim(txtCardNo.Text) & "'"
Set mrcOnLine = ExecuteSQL(txtSQL, MsgText)
'连接student表
txtSQL = "select * from student_info where cardno='" & Trim(txtCardNo.Text) & "'"
Set mrcStu = ExecuteSQL(txtSQL, MsgText)
If mrcOnLine.EOF = True Then
MsgBox "该号没有上机", 64, "温馨提示"
txtCardNo.Text = ""
txtCardNo.SetFocus
Else
Day = DateDiff("d", mrcOnLine.Fields(6), Date) '计算上机下机的日期差
Minute = DateDiff("n", mrcOnLine.Fields(7), Time) '计算上机下机的同日时间差
lblCTime.Text = 1440 * Val(Day) + Minute '计算总时间差,分钟为单位
'判断是否小于准备时间
ConsumeTime = lblCTime.Text
txtSQL = "select * from BasicData_info"
Set mrcdata = ExecuteSQL(txtSQL, MsgText)
'判断是否小于准备时间
If ConsumeTime < mrcdata.Fields(4) Then
lblCMoney.Text = "0"
lblCTime.Text = "0"
lbloffDate.Text = Date
lblOffTime.Text = Time
lblBaLance.Text = Trim(mrcStu.Fields(7))
Else
'判断是否小于最小上机时间
'判断消费时间小于最小上机时间时消费金额为0
If ConsumeTime < mrcdata!leasttime Then
lblCMoney.Text = "0" '消费金额为0元
lblCTime.Text = "0"
lbloffDate.Text = Date
lblOffTime.Text = Time
lblBaLance.Text = Trim(mrcStu.Fields(7))
Else
If Trim(mrcOnLine.Fields(1)) = "固定用户" Then
'cdbl将时间转换成double类型,round是将数据四舍五入,保留两位小数
lblCMoney.Text = Round((mrcdata.Fields(0) / 60 * ConsumeTime))
lblBaLance.Text = Val(mrcStu.Fields(7)) - Val(lblCMoney.Text)
Else
lblCMoney.Text = Round((mrcdata.Fields(1) / 60 * ConsumeTime)) '计算临时用户金额
lblBaLance.Text = Val(mrcStu.Fields(7)) - Val(lblCMoney.Text)
mrcStu.Fields(7) = Trim(lblBaLance.Text)
mrcStu.Fields(11) = "未结账"
End If
txtSQL = "select * from line_info where cardno='" & Trim(txtCardNo.Text) & "'"
Set mrcLine = ExecuteSQL(txtSQL, MsgText)
mrcLine.AddNew
mrcLine.Fields(1) = mrcOnLine.Fields(0) '卡号
mrcLine.Fields(2) = mrcOnLine.Fields(2) '学号
mrcLine.Fields(3) = mrcOnLine.Fields(3) '姓名
mrcLine.Fields(4) = mrcOnLine.Fields(1) '系别
mrcLine.Fields(5) = mrcOnLine.Fields(5) '性别
mrcLine.Fields(6) = mrcOnLine.Fields(6) '上机日期
mrcLine.Fields(7) = mrcOnLine.Fields(7) '上机时间
mrcLine.Fields(8) = Date '下机日期
mrcLine.Fields(9) = Time '下机时间
mrcLine.Fields(10) = ConsumeTime '消费时间
mrcLine.Fields(11) = Trim(lblCMoney.Text) '消费金额
mrcLine.Fields(12) = Trim(lblBaLance.Text) '余额
mrcLine.Fields(13) = "正常下机"
mrcLine.Fields(14) = Trim(VBA.Environ("computername"))
mrcLine.Update
mrcStu.Fields(7) = Trim(lblBaLance.Text)
mrcStu.Fields(11) = "未结账"
mrcStu.Update
'显示数据
'将student表内的数据展示出来
txtType.Text = Trim(mrcStu.Fields(14)) '类型
txtSID.Text = Trim(mrcStu.Fields(1)) '学号
txtName.Text = Trim(mrcStu.Fields(2)) '姓名
txtDept.Text = Trim(mrcStu.Fields(4)) '系别
txtSex.Text = Trim(mrcStu.Fields(3)) '性别
lblOnDate.Text = Trim(mrcLine.Fields(6)) '上机日期
lblontime.Text = Trim(mrcLine.Fields(7)) '上机时间
'计算消费金额
lbloffDate.Text = Date '下机日期
lblOffTime.Text = Time '下机时间
MsgBox "下机成功", 64, "温馨提示"
mrcOnLine.Delete
Call lblPeople_Click
End If
End If
End If
End Sub
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
下机和上机是一样的,都需要连接到多个表格,需要整明白逻辑,然后就好干了。
文章来源: blog.csdn.net,作者:张艳伟_Laura,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/Laura__zhang/article/details/107485567
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)