本文主要是介绍机房收费系统——上机和下机,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
机房收费系统的难点之一就是上机和下机的部分,不仅要考虑基本的功能实现,还有下机的用户消费情况的分析,我仅提供我自己简单编写的代码和思路图,希望可以等到大家的指导。
上机:
附代码:'上机操作主要有显示上机信息(获取时间),更新数据库中的上机表中的信息
Private Sub CmdOk_Click()
Dim StrSQL As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String
Dim StrSQL6 As String
Dim strMsgText As String
Dim strMsgText2 As String
Dim strMsgText3 As String
Dim strMsgText4 As String
Dim strMsgText5 As String
Dim strMsgText6 As String
Dim objRst As ADODB.Recordset
Dim objRst2 As ADODB.Recordset
Dim objRst3 As ADODB.Recordset
Dim objRst4 As ADODB.Recordset
Dim objRst5 As ADODB.Recordset
Dim objRst6 As ADODB.Recordset
'判断卡号是否为空
If Trim(txtCardNo.Text) = "" Then
MsgBox "请输入卡号!", vbOKOnly + vbExclamation, "警告!"
txtCardNo.SetFocus
Exit Sub
Else
If IsNumeric(txtCardNo.Text) = False Then
MsgBox "卡号输入必须为数字", vbOKOnly + vbExclamation, "警告!"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
End If
'查询数据库里学生基本信息表
StrSQL = "select * from student_Info where cardno='" & Trim(txtCardNo.Text) & "'"
Set objRst = ExecuteSQL(StrSQL, strMsgText)
'判读该卡号是否注册
If objRst.BOF And objRst.EOF Then
MsgBox "该卡号未注册,请先注册信息!", vbOKOnly + vbExclamation, "警告!"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
Else
'判断卡号是否正在上机
strSQL2 = "select * from online_Info where cardno='" & Trim(txtCardNo.Text) & "'and status= '上机'"
Set objRst2 = ExecuteSQL(strSQL2, strMsgText2)
If objRst2.EOF = False Then
Label20.Caption = "该卡正在上机,不能重复上机!"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
End If
strSQL3 = "select * from student_Info where cardno='" & Trim(txtCardNo.Text) & "'"
Set objRst3 = ExecuteSQL(strSQL3, strMsgText3)
strSQL4 = "select * from basicdata_Info "
Set objRst4 = ExecuteSQL(strSQL4, strMsgText4)
If objRst3.Fields(14) < objRst4.Fields(5) Then
MsgBox "金额不足,请充值!", vbOKOnly + vbExclamation, "提示"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
Else
'显示该卡号的一些基本信息
txtSID.Text = objRst3.Fields(1)
txtdepartment.Text = objRst3.Fields(4)
txtType.Text = objRst3.Fields(8)
txtname.Text = objRst3.Fields(3)
txtsex.Text = objRst3.Fields(2)
txtloginondate.Text = Date
txtloginontime.Text = Time
'将上机前的余额提出来,用于下机时计算余额
txtbalance.Text = objRst3.Fields(14)
ontime = Time
Label20.Caption = "欢迎光临!"
'将该卡上机的信息填入到online_Info表里
strSQL5 = "select * from online_Info "
Set objRst5 = ExecuteSQL(strSQL5, strMsgText5)
objRst5.AddNew
objRst5.Fields(0) = txtCardNo.Text
objRst5.Fields(1) = txtSID.Text
objRst5.Fields(2) = txtname.Text
objRst5.Fields(3) = Trim(txtType.Text)
objRst5.Fields(4) = txtdepartment.Text
objRst5.Fields(5) = txtsex.Text
objRst5.Fields(6) = Date
objRst5.Fields(7) = Time
objRst5.Fields(8) = UserName
objRst5.Fields(9) = txtbalance.Text
objRst5.Fields(10) = "上机"
objRst5.Update
'查询此时正在上机的人数
StrSQL6 = "select * from online_Info where status='上机'"
Set objRst6 = ExecuteSQL(StrSQL6, strMsgText6)
If objRst6.EOF = True Then
Label18.Caption = 0
Else
Label18.Caption = objRst6.RecordCount
End If
End If
End If
End If
End Sub
下机:
附代码:
'下机的操作主要有,获取下机信息,更新注册表、上机表中的相关字段
'添加下机表中信息,计算上机时间和上机费用、余额等并添加到相应的数据表中
Private Sub cmdOff_Click()
Dim StrSQL As String
Dim StrSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String
Dim StrSQL6 As String
Dim strMsgText As String
Dim strMsgText1 As String
Dim strMsgText2 As String
Dim strMsgText3 As String
Dim strMsgText4 As String
Dim strMsgText5 As String
Dim strMsgText6 As String
Dim objRst As ADODB.Recordset
Dim objRst1 As ADODB.Recordset
Dim objRst2 As ADODB.Recordset
Dim objRst3 As ADODB.Recordset
Dim objRst4 As ADODB.Recordset
Dim objRst5 As ADODB.Recordset
Dim objRst6 As ADODB.Recordset
Dim intTime As Single
Dim intTime1 As Single
Dim fixedRate As Single
Dim pay As Currency
Dim returncash As Currency
Dim temporary As Single
'判断卡号的输入情况
If Trim(txtCardNo.Text) = "" Then
MsgBox "请输入卡号!", vbOKOnly, "警告!"
txtCardNo.SetFocus
Exit Sub
Else
If IsNumeric(txtCardNo.Text) = False Then
MsgBox "卡号输入必须为数字", vbOKOnly + vbExclamation, "警告!"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
End If
End If
'判读该卡号是否注册
StrSQL = "select * from student_Info where cardno='" & Trim(txtCardNo.Text) & "'"
Set objRst = ExecuteSQL(StrSQL, strMsgText)
If objRst.BOF And objRst.EOF Then
MsgBox "该卡号未注册,请先注册信息!", vbOKOnly, "警告!"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
End If
'判断该卡是否正在上机
StrSQL1 = "select * from online_Info where status='上机'"
Set objRst1 = ExecuteSQL(StrSQL1, strMsgText1)
If objRst1.EOF And objRst1.BOF = True Then
Label20.Caption = "该卡没有上机,不能进行下机处理!"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
Else
'显示下机的一些信息
' strSQL2 = "select * from online_Info where cardno='" & txtCardNo.Text & "'"
' Set objRst2 = ExecuteSQL(strSQL2, strMsgText2)
txtloginoffdate.Text = Date
outtime = Time
outdate = Date
txtloginofftime.Text = Time
Dim loginontime As String
Dim loginondate As String
loginondate = objRst1.Fields("loginondate")
loginontime = objRst1.Fields("loginontime")
ontime = CDate(objRst1.Fields("loginontime"))
ondate = CDate(objRst1.Fields("loginondate"))
'
txtname.Text = objRst1.Fields(2)
txtloginondate.Text = objRst1.Fields(6)
txtloginontime.Text = objRst1.Fields(7)
objRst1.Fields(10) = "下机"
strSQL2 = "select * from student_Info where cardno='" & Trim(txtCardNo.Text) & "'"
Set objRst2 = ExecuteSQL(strSQL2, strMsgText2)
txtSID.Text = objRst2.Fields(1)
txtdepartment.Text = objRst2.Fields(4)
txtsex.Text = objRst2.Fields(2)
txtType.Text = objRst2.Fields(8)
strSQL4 = "select * from online_Info where cardno='" & Trim(txtCardNo.Text) & "' "
Set objRst4 = ExecuteSQL(strSQL4, strMsgText4)
objRst4.Fields(10) = "正常下机"
strSQL3 = "select * from line_Info "
Set objRst3 = ExecuteSQL(strSQL3, strMsgText3)
objRst3.AddNew
objRst3.Fields(0) = txtCardNo.Text
objRst3.Fields(1) = txtSID.Text
objRst3.Fields(2) = txtname.Text
objRst3.Fields(3) = Trim(txtType.Text)
objRst3.Fields(4) = Trim(txtdepartment.Text)
objRst3.Fields(5) = txtsex.Text
objRst3.Fields(6) = objRst1.Fields(6)
objRst3.Fields(7) = objRst1.Fields(7)
objRst3.Fields(8) = Date
objRst3.Fields(9) = Time
objRst3.Fields(13) = objRst4.Fields(10)
objRst3.Fields(14) = UserName
'计算上机的时间
txtloginoffdate.Text = Date
txtloginofftime.Text = Time
txtdate = DateDiff("n", ondate, outdate)
txttime = DateDiff("n", ontime, outtime)
txttime.Text = Int(txttime) + Int(txtdate)
intTime = txttime.Text
objRst3.Fields(10) = Trim(txttime.Text)
'计算上机的费用
strSQL5 = "select * from basicdata_Info "
Set objRst5 = ExecuteSQL(strSQL5, strMsgText5)
'查询固定用户30分钟的费用
fixedRate = Val(objRst5.Fields(0))
'判断上机时间是否超过了准备时间,没超过则花费为0
If intTime < (objRst5.Fields(4)) Then
txtmoney.Text = 0
objRst3.Fields(11) = txtmoney.Text
returncash = Trim(txtbalance.Text) - Trim(txtmoney.Text)
objRst3.Fields(12) = returncash
objRst3.Update
objRst4.Fields(9) = objRst3.Fields(12)
objRst4.Update
objRst2.Fields(14) = objRst3.Fields(12)
objRst2.Update
Exit Sub
Else
'判断上机时间是否超过至少上机时间,没有则当成已经上了30分钟
If intTime <= objRst5.Fields(3) Then
txtmoney.Text = fixedRate
objRst3.Fields(11) = txtmoney.Text
returncash = Trim(txtbalance.Text) - Trim(txtmoney.Text)
objRst3.Fields(12) = returncash
objRst3.Update
objRst4.Fields(9) = objRst3.Fields(12)
objRst4.Update
objRst2.Fields(14) = objRst3.Fields(12)
objRst2.Update
Exit Sub
Else
'判断消耗的时间能否正好是30的倍数,判断是不是有超出不满足30分钟的部分,这部分仍然按照30分钟收费
If Val(intTime) Mod 30 = 0 Then
txtmoney.Text = Val(Val(intTime) \ 30) * fixedRate
objRst3.Fields(11) = txtmoney.Text
returncash = Trim(txtbalance.Text) - Trim(txtmoney.Text)
objRst3.Fields(12) = returncash
objRst3.Update
objRst4.Fields(9) = objRst3.Fields(12)
objRst4.Update
objRst2.Fields(14) = objRst3.Fields(12)
objRst2.Update
Else
txtmoney.Text = Val(Val(intTime) \ 30 + 1) * fixedRate
objRst3.Fields(11) = txtmoney.Text
returncash = Trim(txtbalance.Text) - Trim(txtmoney.Text)
objRst3.Fields(12) = returncash
objRst3.Update
objRst4.Fields(9) = objRst3.Fields(12)
objRst4.Update
objRst2.Fields(14) = objRst3.Fields(12)
objRst2.Update
End If
End If
End If
StrSQL6 = "select * from online_Info where status='上机'"
Set objRst6 = ExecuteSQL(StrSQL6, strMsgText6)
If objRst6.EOF = True Then
Label18.Caption = objRst6.RecordCount
End If
Label20.Caption = "欢迎下次再来!"
End If
End Sub
因为当时创建的数据库中有上机表和上机记录表,所以每次在更新数据的时候都需要分别对两个表进行修改,我们可以用一张表同时存储两部分信息,减少数据的冗余,并且可以节省程序运行的时间,加快查询速度。代码仍然在优化,继续、、、
这篇关于机房收费系统——上机和下机的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!