机房收费系统之下机过程

下机过程涉及到的对表的处理要比上机过程多,最重要的一点是对上机消费的计算。首先需要先计算出上机持续的时间onlinetime,然后再用基本数据表中的rate(价格)乘以onlinetime算出消费的金额,再让学生表student_info中的cash减去消费的金额,得到新的余额newcash。在此之前,需要先做一些判断。

'下机
Private Sub cmdDown_Click()
    onLineTime = DateDiff("n", onTime, MyTime) '计算上机的分钟数
    
    txtSQL = "select * from basicdata_info"
    Set mrcbsc = ExecuteSQL(txtSQL, MsgText)
    
    '保证输入了卡号
    If Trim(txtCardID.Text) = "" Then       '没有输入卡号,提示
        MsgBox "请输入卡号", vbOKOnly + vbExclamation, "警告"
        txtCardID.SetFocus
        Exit Sub
    Else    '输了卡号以后,确保卡号是注册过的
        txtSQL = "select * from student_info where cardno='" & Trim(txtCardID.Text) & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
            If mrc.EOF = True Then
                MsgBox "卡号不存在", vbOKOnly + vbExclamation, "提示"
                txtCardID.Text = ""
                txtCardID.SetFocus
                mrc.Close
                Exit Sub
            Else
                
                '判断此卡是否已经下机或未上机
                txtSQL = "select * from online_info where cardno='" & Trim(txtCardID.Text) & "'"
                Set mrcOnLine = ExecuteSQL(txtSQL, MsgText)
                
                If mrcOnLine.BOF = True And mrcOnLine.EOF = True Then
                    MsgBox "此卡未上机或已下机"
                    Exit Sub
                Else
                    '计算上机的消费金额,总的余额减去消费金额,将数据更新到student_info中
                    txtSQL = "select * from basicdata_info"
                    Set mrcbsc = ExecuteSQL(txtSQL, MsgText)
                    MinTime = mrcbsc.Fields(3)  ' 将基本数据表中的最低消费时间赋给mintime
                    LeastRMB = mrcbsc.Fields(5) '将基本数据表中的最低消费金额赋给leastrmb
                    If onLineTime <= MinTime Then ' 如果上机时间小于最少上机时间,则减去最低消费
                     
                        NewCash = Val(Trim(mrc.Fields(7))) - Val(LeastRMB) 'mrc.fields(7)中的是cash
                        Dim SQL
                        SQL = "update student_info set cash='" & NewCash & "' "
                        Call ExecuteSQL(SQL, MsgText)
                        
                        txtConsumeBalance.Text = LeastRMB '消费金额显示
                    Else
                        
                        '上机时间大于最低上机时间
                        NewCash = Val(Trim(mrc.Fields(7))) - Val(onLineTime) / 60 * Val(mrcbsc.Fields(0))
                        
                        SQL = "update student_info set cash='" & NewCash & "' "
                        Call ExecuteSQL(SQL, MsgText)
                        txtConsumeBalance.Text = Val(onLineTime) / 60 * Val(mrcbsc.Fields(0)) '消费金额显示
                    End If
                    mrcOnLine.Delete
            
                End If
            End If
    End If
    
    
    txtConsumeTime.Text = Str(Val(onLineTime) / 60)
    
    txtXJdate.Text = Date
    txtXJtime.Text = Time
    'txtSQL = "update student_info set cash=" & NewCash & " where cardno='" & txtCardID.Text & "'"
    'Call ExecuteSQL(txtSQL, MsgText)
    txtBalance.Text = NewCash

    '添加到line表中,记录该卡的上机记录。该过程还没完成
    
    
    mrc.Close
    mrcOnLine.Close
    mrcbsc.Close
    ' mrcLine.Close
    MsgBox "下机成功"
End Sub

当然,这只是一个未完成的作品,还有很多需要完善的地方。希望通过自己多想,能够让逻辑更完善,出错更少。

评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值