机房收费系统上下机是难点,我们首先要理清思路,确定好上机和下机的步骤,才能更好的实现功能。
上机:1.判断卡号是否为空
2.判断卡号是否注册
3.卡号是否正在上机
4.此卡余额是否足够
之后,从student_Info中查找相应数据记录,向Line_Info中添加记录,在OnLine_Info中添加相应记录,上机成功。
下机:1.判断卡号是否为空
2.判断卡号是否注册
3.卡号是否正在上机
4.计算消费金额:先判断是否小于准备时间,小于金额为0,然后判断是否小于至少上机时间,小于金额为0,否则,分为固定用户和临时用户。固定用户按固定用 户的消费标准来计算,临时用户按临时用户的消费标准来计算,再来算卡内余额,余额等于上机前卡内剩余金额减去消费金额。之后,显示下机信息,更新student_Info, 表更新Line_Info表,删除OnLine_Info表,下机成功。
Dim mrc As ADODB.Recordset '定义数据集对象 Dim txtSQL As String '定义字符串变量,表示查询语句 Dim Msgtext As String '定义字符串变量,返回查询语句 Dim cash As Double '余额 Dim Mrc1 As ADODB.Recordset '定义数据集对象 Dim onpeople As String '显示登录人数 txtSQL = "select * from BasicData_Info" Set Mrc1 = ExecuteSQL(txtSQL, Msgtext) If txtCard.Text = "" Then MsgBox "请输入准备上机的卡号!", vbOKOnly + vbExclamation, "警告" '判断要上机的卡号是否为空 Exit Sub txtCard.SetFocus txtCard.Text = "" End If txtSQL = "select * from student_Info where cardno = '" & txtCard.Text & "' " Set mrc = ExecuteSQL(txtSQL, Msgtext) ' 判断student_Info表中是否存在该卡号 If mrc.BOF And mrc.EOF Then '如果不存在该卡号 MsgBox "此卡号没有注册,请重新输入!", vbOKOnly + vbExclamation, "警告" Else cash = Trim(mrc.Fields(7)) '获取上机卡号的余额 txtSQL = "select * from Online_Info where cardno = '" & txtCard.Text & "' " '判断该卡号是否在上机 Set mrc = ExecuteSQL(txtSQL, Msgtext) If mrc.EOF Then If cash < Trim(Mrc1.Fields(5)) Then '判断余额是否足够 MsgBox "卡内余额不足,请充值后登陆!", vbOKOnly + vbExclamation, "警告" txtCard.Text = "" Exit Sub Else txtSQL = "select * from student_Info where cardno = '" & txtCard.Text & "' " '没有上机,去表student_Info 查找相应的数据记录 Set mrc = ExecuteSQL(txtSQL, Msgtext) txtStyle.Text = Trim(mrc.Fields(14)) txtStudentno.Text = Trim(mrc.Fields(1)) txtUserName.Text = Trim(mrc.Fields(2)) txtXiBie.Text = Trim(mrc.Fields(4)) txtsex.Text = Trim(mrc.Fields(3)) txtBalance.Text = Trim(mrc.Fields(7)) txtSQL = "insert into Online_Info values('" & txtCard.Text & "', '" & txtStyle.Text & "','" & txtStudentno.Text & "','" & txtUserName.Text & "','" & txtXiBie.Text & "','" & txtsex.Text & "','" & Date & "','" & Time & "','" & Trim(Winsock1.LocalHostName) & "','" & Now & "')" Set mrc = ExecuteSQL(txtSQL, Msgtext) '添加到Online_info 表中 Label7.Caption = onpeople txtShangdate.Text = Date txtShangTime.Text = Time End If Else MsgBox "此卡正在上机中!", vbOKOnly + vbExclamation, "警告" '该卡号正在上机,给出提示 End If End If txtStyle.Enabled = False txtStudentno.Enabled = False txtUserName.Enabled = False txtXiBie.Enabled = False txtsex.Enabled = False txtBalance.Enabled = False txtShangdate.Enabled = False txtShangTime.Enabled = False txtOutdate.Enabled = False txtOuttime.Enabled = False txtConsumeMoney.Enabled = False txtConsumeMoney.Enabled = False
Dim mrc As ADODB.Recordset '定义数据集对象 Dim mrc1 As ADODB.Recordset '定义数据集对象 Dim mrc2 As ADODB.Recordset '定义数据集对象 Dim mrc3 As ADODB.Recordset '定义数据集对象 Dim txtSQL As String String定义字符串变量,表示查询语句 Dim Msgtext As String '定义字符串变量,返回查询语句 Dim onlinetime As Integer '在线时间 Dim consume As Single '花费钱的时间 Dim balance As Single '用户的余额 Dim Fixeduser As Single '固定用户的单位金额 Dim temporaryuser As Single '临时用户的单位金额 '判断卡号框是否为空 If txtCard.Text = "" Then MsgBox "请输入卡号!", vbOKOnly, "警告" txtCard.SetFocus Exit Sub Else '判断卡号输入的是否是数字 If Not IsNumeric(txtCard.Text) Then MsgBox "卡号请输入数字!", vbOKOnly, "警告" txtCard.Text = "" txtCard.SetFocus Exit Sub Else '判断此卡号是否存在 txtSQL = "select * from student_Info where cardno = '" & Trim(txtCard.Text) & "'" Set mrc1 = ExecuteSQL(txtSQL, Msgtext) If mrc1.EOF Then MsgBox "该卡号尚未注册!请重新输入!", vbOKOnly, "警告" txtCard.SetFocus Exit Sub Else '判断该卡号是否可以使用(是否已被退卡) If mrc1.Fields(10) = "不使用" Then MsgBox "该卡号已经退卡,不能下机!", vbOKOnly, "警告" txtCard.SetFocus Exit Sub Else '判断该卡号是否正在上机 TxtSQL = "select * from Online_Info where cardno = '" & Trim(txtCard.Text) & "'" Set mrc = ExecuteSQL(TxtSQL, Msgtext) ' If mrc.EOF Then MsgBox "该卡号没有上机!", vbOKOnly, "警告" Exit Sub txtCard.SetFocus End If End If End If End If End If '查询基本数据表,获得设定的基本数据 TxtSQL = "select * from BasicData_Info " Set mrc2 = ExecuteSQL(TxtSQL, Msgtext) '计算消费时间 '实际在线时间 onlinetime = (Date - DateValue(mrc!Ondate)) * 1440 + (Hour(Time) - _ Hour(TimeValue(mrc!OnTime))) * 60 + (Minute(Time) - _ Minute(TimeValue(mrc!OnTime))) '把固定用户、临时用单位时间的费用分别赋给费用 Fixeduser = Val(mrc2.Fields(0)) '把固定用户的金额赋给变量 temporaryuser = Val(mrc2.Fields(1)) '把临时用户的金额赋给变量 '判断实际在线时间是否小于准备时间,若小于则消费时间为0 If onlinetime <= Val(Trim(mrc2.Fields(4))) Then txtConsumeMoney.Text = 0 Else '判断实际在线时间是否小于最低消费时间,若小于消费为0 If onlinetime <= Val(Trim(mrc2.Fields(3))) Then txtConsumeMoney.Text = 0 Else '实际在线时间大于最低消费时间则按单位时间算,分固定用户和临时用户 If onlinetime >= Val(Trim(mrc2!leasttime)) And onlinetime < Val(Trim(mrc2!UnitTime)) And Trim(mrc1.Fields(14)) = "固定用户" Then txtConsumeMoney.Text = Fixeduser Else If onlinetime >= Val(Trim(mrc2!leasttime)) And onlinetime < Val(Trim(mrc2!UnitTime)) And Trim(mrc1.Fields(14)) = "临时用户" Then txtConsumeMoney.Text = temporaryuser Else '当实际在线时间大于单位时间,就按有几个单位时间算,分固定用户和临时用户 If onlinetime > Val(Trim(mrc2!leasttime)) And Trim(mrc1.Fields(14)) = "固定用户" Then consume = onlinetime / Val(Trim(mrc2!UnitTime)) txtConsumeMoney.Text = Val(consume) * Val(Fixeduser) Else If onlinetime > Val(Trim(mrc2!leasttime)) And Trim(mrc1.Fields(14)) = "临时用户" Then consume = onlinetime / Val(Trim(mrc2!UnitTime)) txtConsumeMoney.Text = Val(consume) * Val(temporaryuser) End If End If End If End If End If End If '计算余额(账户余额=原账户余额-消费金额) balance = mrc1!cash - Val(txtConsumeMoney.Text) '下机信息显示 txtOutdate.Text = Date txtOuttime.Text = Time txtStudentno.Text = Trim(mrc.Fields(2)) txtUserName.Text = Trim(mrc.Fields(3)) txtXiBie.Text = Trim(mrc.Fields(4)) txtStyle.Text = Trim(mrc.Fields(1)) txtsex.Text = Trim(mrc.Fields(5)) txtShangdate.Text = Trim(mrc.Fields(6)) txtShangTime.Text = Trim(mrc.Fields(7)) txtConsumeMin.Text = onlinetime txtBalance.Text = balance MsgBox "下机成功!欢迎下次再来!", vbOKOnly, "提示" '更新学生信息表的余额 mrc1.Fields(7) = balance mrc1.Update mrc1.Close '更新上机记录表(line表) TxtSQL = "select * from Line_Info" Set mrc3 = ExecuteSQL(TxtSQL, Msgtext) mrc3.AddNew mrc3.Fields(1) = Trim(txtCard.Text) mrc3.Fields(2) = Trim(txtStudentno.Text) mrc3.Fields(3) = Trim(txtUserName.Text) mrc3.Fields(4) = Trim(txtXiBie.Text) mrc3.Fields(5) = Trim(txtsex.Text) mrc3.Fields(6) = Trim(txtShangdate.Text) mrc3.Fields(7) = Trim(txtShangTime.Text) mrc3.Fields(8) = Trim(txtOutdate.Text) mrc3.Fields(9) = Trim(txtOuttime.Text) mrc3.Fields(10) = Trim(Val(txtConsumeMin.Text)) mrc3.Fields(11) = Trim(Val(txtConsumeMoney.Text)) mrc3.Fields(12) = Trim(Val(txtBalance.Text)) mrc3.Fields(13) = "正常下机" mrc3.Fields(14) = Trim(Winsock1.LocalHostName) mrc3.Update '删除在线表中的信息 TxtSQL = "select * from online_Info where cardno = '" & Trim(txtCard.Text) & "'" Set mrc = ExecuteSQL(TxtSQL, Msgtext) mrc.Delete mrc.Update txtCard.Text = "" txtStyle.Enabled = False txtStudentno.Enabled = False txtUserName.Enabled = False txtXiBie.Enabled = False txtsex.Enabled = False txtBalance.Enabled = False txtShangdate.Enabled = False txtShangTime.Enabled = False txtOutdate.Enabled = False txtOuttime.Enabled = False txtConsumeMin.Enabled = False txtConsumeMoney.Enabled = False