机房收费系统终于做完了,在此过程经历了风风雨雨,挫挫折折,痛并快乐着。
在机房收费系统中有很重要的一块就是下机结账的计算,在此小弟和大家分享一下,小弟的成果。
在我们点击下机按钮时,上机卡号会结账下机,在此同时后台会计算我们的消费情况,并把消费信息显示在该界面上。
在了解消费情况计算前我们先来看一个界面,那就是我们基本数据的设定。因为我们的一切消费计算都是依赖于这些基础数据的。
消费计算具体的实现方法分三个部分:消费时间计算,消费金额计算,消费余额计算。下面是整个下机结账过程的代码实现。
Private Sub cmdOff_Click() Dim rstOnline As ADODB.Recordset Dim rstStudent As ADODB.Recordset Dim strOff As String Dim strMsg As String Dim rstDataBase As Recordset Dim intLineTime As Integer Dim intConsumeTime As Integer Dim curConsume As Currency Dim curBalance As Currency Static Serial As Integer '判断卡号输入框是否为空 If txtCardID.Text = "" Then MsgBox "请输入卡号!", vbOKOnly + vbExclamation, "警告" txtCardID.SetFocus Exit Sub End If '判断卡号输入框是否输入的为数字 If Not IsNumeric(txtCardID.Text) Then MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告" txtCardID.Text = "" txtCardID.SetFocus Exit Sub End If '//查询在线卡状态表,判断此卡是否在线// strOff = "select * from Online_info where cardid='" & txtCardID & "'" Set rstOnline = ExecuteSQL(strOff, strMsg) '判断卡是否在线 If rstOnline.EOF Then lblMsg.Caption = "该卡还没有上机!" Exit Sub txtCardID = "" txtCardID.SetFocus End If '//查询基本数据表,获得设定的基本数据// strOff = "select * from DataBase_info" Set rstDataBase = ExecuteSQL(strOff, strMsg) '//计算消费时间// { 实际在线时间=上机时间-下机时间 消费时间= 取整((实际在线时间 - 准备时间)/递增单位时间)*递增单位时间 ///在此的时间单位均为分钟 ;取整必须用round函数四舍五入,不可用int或Fix函数 } '实际在线时间 intLineTime = (Date - DateValue(rstOnline!LoginDate)) * 1440 + (Hour(Time) - _ Hour(TimeValue(rstOnline!LoginTime))) * 60 + (Minute(Time) - _ Minute(TimeValue(rstOnline!LoginTime))) '判断实际在线时间是否小于准备时间 If intLineTime <= rstDataBase!PrepareTime Then intConsumeTime = 0 '消费时间 '判断实际在线时间是否小于最低消费时间 ElseIf intLineTime < rstDataBase!MinTime Then intConsumeTime = rstDataBase!MinTime '消费时间 Else '消费时间 intConsumeTime = Round(intLineTime / rstDataBase!unitTime) * rstDataBase!unitTime End If '//计算消费金额//{ 消费金额= 消费时间/30分钟 * 半小时费率 } curConsume = intConsumeTime / 30 * rstDataBase!FixedRate '判断消费金额是否小于最低消费 If curConsume > 0 And curConsume < rstDataBase!MinConsume Then curConsume = rstDataBase!MinConsume End If '//查询学生信息表// strOff = "select balance from student_info where cardID='" & txtCardID & "'" Set rstStudent = ExecuteSQL(strOff, strMsg) '//计算余额//{ 账户余额= 原账户余额 – 消费金额 } curBalance = rstStudent!balance - curConsume '//下机信息显示// txtCardID = rstOnline!Cardid txtCardType = rstOnline!CardType txtStudentID = rstOnline!StudentID txtStudentName = rstOnline!StudentName txtStudentSex = rstOnline!StudentSex txtStudentDepart = rstOnline!StudentDepart txtLoginDate = rstOnline!LoginDate txtLoginTime = rstOnline!LoginTime txtLogoutDate = Date txtLogoutTime = Time lblMsg.Caption = "欢迎下次再来!" txtLineTime = intLineTime txtConsume = curConsume txtBalance = curBalance '//更新学生信息表的余额// rstStudent!balance = curBalance rstStudent.Update rstStudent.Close '//更新上机记录表// Serial = Serial + 1 strOff = "INSERT Line_info VALUES(" & Serial & "," & rstOnline!Cardid & "," & _ rstOnline!StudentID & ",'" & rstOnline!StudentName & "','" & _ rstOnline!StudentSex & "','" & rstOnline!StudentDepart & "','" & _ rstOnline!LoginDate & "','" & rstOnline!LoginTime & "','" & _ txtLogoutDate & "','" & txtLogoutTime & "'," & _ intLineTime & "," & curConsume & "," & curBalance & ",'" & _ "正常下机" & "','" & rstOnline!Computer & "')" Call ExecuteSQL(strOff, strMsg) '删除相应的在线卡状态表记录 rstOnline.Delete lblOnTotal.Caption = lblOnTotal.Caption - 1 End Sub
作者信息(http://gelupu.blog.163.com/)