【VB与数据库】——机房收费系统之上下机

        机房管理系统到现在也有了一定了解,最大的感觉就是所有的问题都不算事!因为如果要是被问题难住的话那么第一个问题出现的时候,你就被挡在门之外了,再也没有机会感受靠自己完成的源码,实现窗体的功能的喜悦了,看看这自己的机房收费系统功能在一天不断完成,心情还是有些小激动的哈。

    在机房收费系统有一个比较重要的问题就是上机和下机,在这个过程中自己感觉有很强的逻辑性,所以只要理清逻辑关系,弄明白表之间的操作,还是比较简单的。感觉用图形更利于表达。

上机


下机


    上机相对于下机比较简单,由于在上机的过程中只是简单涉及到student中表中是否存在卡号,以及BasicData_Info表中至少上机金额的查找,以及对Online_Info中添加记录。

Dim mrc As ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
Dim cash As Double
Dim Object As ADODB.Recordset
Dim txtSQL2 As String
Dim MsgText2 As String
    txtSQL2 = "select * from BasicData_Info"
    Set Object = ExecuteSQL(txtSQL2, MsgText2)
    
    If Testtxt(Trim(txtCard.Text)) Then
        MsgBox "请输入准备上机的卡号!", vbOKOnly + vbExclamation, "警告"                   '判断要上机的卡号是否为空
        Exit Sub
    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(Object.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 表中
                Label9.Visible = True
                txtShangdate.Text = Date
                txtShangTime.Text = Time
            End If
        Else
            MsgBox "此卡正在上机中!", vbOKOnly + vbExclamation, "警告"        '该卡号正在上机,给出提示
        End If
        
    End If
    


     下机之所以要不及上机麻烦是因为他需要计算上机的时间和上机所花费的费用,然后对应去表中中查找记录,更新,删除Online_Info表中记录,添加到Online表中

Dim txtSQL As String
Dim txtSQL2 As String
Dim txtSQL3 As String
Dim txtSQL4 As String

Dim MsgText As String
Dim MsgText2 As String
Dim MsgText3 As String
Dim MsgText4 As String

Dim mrc As ADODB.Recordset
Dim Object As ADODB.Recordset
Dim Object2 As ADODB.Recordset
Dim Object3 As ADODB.Recordset

Dim Ondate As Date
Dim Ontime As Date
Dim txtdate As Single
Dim txttime As Single
Dim outdate As Date
Dim outtime As Date
Dim Style As String
Dim intTime As Single
Dim Balance As Single
Dim basicPay As Single
Dim returnCash As Single

    If Testtxt(txtCard.Text) Then
        MsgBox "请输入要下机的卡号!", vbOKOnly + vbExclamation, "警告"
        Exit Sub
    End If
    txtSQL = "select * from student_Info where cardno = '" & txtCard.Text & "' "
    Set mrc = ExecuteSQL(txtSQL, MsgText)
     '判断卡号是否存在
    If mrc.BOF And mrc.EOF Then                                                  '如果不存在,则给出提示
        MsgBox "该卡号不存在,请重新输入或选择新注册!", vbOKOnly + vbExclamation, "警告"
        txtCard.SetFocus
        Exit Sub
    Else                                                                         '如果存在,判断是否在上机
        Balance = Trim(mrc.Fields(7))
        txtSQL2 = "select * from Online_Info where cardno = '" & txtCard.Text & "' "
        Set Object = ExecuteSQL(txtSQL2, MsgText2)
        If Object.BOF And Object.EOF Then                                         '该卡号没有在上机,则给出提示信息
            MsgBox "该卡号没有在上机,不能进行下机处理!", vbOKOnly + vbExclamation, "警告"
            txtCard.SetFocus
            Exit Sub
        Else
            '上机时间的计算
            txtShangdate.Text = Trim(Object.Fields(6))
            txtShangTime.Text = Trim(Object.Fields(7))
            txtStudentNO.Text = Trim(Object.Fields(2))
            txtUserName.Text = Trim(Object.Fields(3))
            txtXiBie.Text = Trim(Object.Fields(4))
            txtSex.Text = Trim(Object.Fields(5))
            txtOuttime.Text = Format(Time, "hh:mm:ss")
            txtOutdate.Text = Format(Date, "yyyy-mm-dd")
            txtBalance.Text = Balance
            outdate = Format(txtOutdate.Text, "yyyy-mm-dd")
            outtime = Format(txtOuttime.Text, "hh:mm:ss")
            Ondate = Format(Trim(Object.Fields(6)), "yyyy-mm-dd")
            Ontime = Format(Trim(Object.Fields(7)), "hh:mm:ss")
            txtdate = DateDiff("n", Ondate, outdate)
            txttime = DateDiff("n", Ontime, outtime)
            txtConsumeMin.Text = Int(txttime) + Int(txtdate)
            intTime = txtConsumeMin.Text
            Style = Trim(Object.Fields(1))
            txtStyle.Text = Style
            '上机金额的计算
            txtSQL3 = "select * from BasicData_Info "
            Set Object2 = ExecuteSQL(txtSQL3, MsgText3)
            <span style="font-size:12px;">
            If Style = "固定用户" Then             '判断用户的类型
                basicPay = Val(Trim(Object2.Fields(0)))
                '判断上机时间是否超过准备时间
                If intTime < Val(Object2.Fields(4)) Then
                    txtConsumeMin.Text = 0
                    txtConsumeMoney.Text = 0
                    returnCash = Val(Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text))
                    txtBalance.Text = returnCash
                    mrc.Fields(7) = txtBalance.Text
                    mrc.Update
                    Call judge
                Else           '判断上机时间是否超过最短时间
                        txtConsumeMin.Text = intTime                                 '在窗体上显示上网时间
                    If intTime <= Val(Object2.Fields(3)) Then                       '没有超过最短时间按最短时间收费
                        txtConsumeMoney.Text = basicPay
                        returnCash = Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text)
                        txtBalance.Text = returnCash
                        mrc.Fields(7) = txtBalance.Text
                        mrc.Update
                        Call judge
                    Else
                        '超过最短时间,判断消耗的时间能否正好是要求单位时间的倍数,判断是不是有超出不满足要求时间的部分,这部分仍然按照要求时间收费
                        If Val(intTime) Mod 30 = 0 Then                               '消耗时间正好等于要求的单位时间
                            txtConsumeMoney.Text = Val(intTime) \ 30 * basicPay \ 2
                            returnCash = Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text)
                            txtBalance.Text = returnCash
                            mrc.Fields(7) = txtBalance.Text
                             mrc.Update
                            Call judge
                        Else
                            txtConsumeMoney.Text = (Val(intTime) \ 30 + 1) * basicPay \ 2
                            returnCash = Val(Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text))
                            txtBalance.Text = returnCash
                            mrc.Fields(7) = txtBalance.Text
                            mrc.Update
                            Call judge
                        End If
                    End If
                End If
            Else               '临时用户的消费计算方式
                basicPay = Val(Trim(Object2.Fields(1)))
                If intTime < Val(Object2.Fields(4)) Then
                    txtConsumeMin.Text = 0
                    txtConsumeMoney.Text = 0
                    returnCash = Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text)
                    txtBalance.Text = returnCash
                    mrc.Fields(7) = txtBalance.Text
                    mrc.Update
                    Call judge
                Else
                    txtConsumeMin.Text = intTime
                    If intTime <= Val(Object2.Fields(3)) Then
                        txtConsumeMoney.Text = basicPay
                        returnCash = Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text)
                        txtBalance.Text = returnCash
                        mrc.Fields(7) = txtBalance.Text
                        mrc.Update
                        Call judge
                    Else
                        If Val(intTime) Mod 30 = 0 Then
                            txtConsumeMoney.Text = Val(intTime) \ 30 * basicPay \ 2
                            returnCash = Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text)
                            txtBalance.Text = returnCash
                            mrc.Fields(7) = txtBalance.Text
                            mrc.Update
                            Call judge
                        Else
                            txtConsumeMoney.Text = (Val(intTime) \ 30 + 1) * basicPay \ 2
                            returnCash = Trim(txtBalance.Text) - Trim(txtConsumeMoney.Text)
                            txtBalance.Text = returnCash
                            mrc.Fields(7) = txtBalance.Text
                            mrc.Update
                            Call judge
                        End If
                    End If
                End If
            End If
        End If
    End If</span>

【总结】

   上机和下机这一部分主要涉及到多个表的操作,逻辑性比较强,主要是把各个方面要考虑完全,这正是“全局观”的思想,最大的感觉就是全心全意为人民服务,从使用者的角度去出发,思考一个不了解软件使用规则的用户,回去怎样点,而我们的目的就是尽快的帮助用户熟悉使用方法,并且让软件在不懂者的手中也不能点出bug。这条路还很长,慢慢努力做好中。。


     如有错误,欢迎大家指出大笑。。



评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mandy_i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值