【机房收费系统】——结账

       结账,结的都是哪些账,给谁结账,结账需要涉及到哪些表?这些都是开始设计代码之前首先要想的。

       看到这个界面,你会怎么想?你也许会想,这是给谁结账,怎么查的是操作员啊?不该给一般用户结账吗?一个操作员每天给一般用户进行注册,充值,退卡等,这些工作是由操作员完成的,管理员要做的就是将操作员的工作进行汇总,然后结账,所以我认为是给操作员结账,结的当然是每天没结的账了。

               【机房收费系统】——结账_第1张图片

首先我们来看需要哪些表来查询相关信息。

user_info表:查询相关操作员,在这里注意,管理员也可以是操作员,优化的时候要想到这点,在以下的代码中我没有体现,大家自己想想,很简单。

student_info表:查询购卡数及购卡信息

recharge_info表:查询充值记录,充值金额

cancelcard_info表:查询退卡记录,退卡数,退卡金额

checkday_info表:将以上查到的信息更新到日结账表

checkweek_info表:将以上查到的信息更新到周结账表


明白了这些,我们就来看看具体怎么实现。

一、首先,查询操作员及他的真实姓名,Tab表里显示的都是该操作员进行过的工作,要一致。

       先将已经添加的操作员用户名加载到combouserid框中,

Private Sub Form_Load()
    '从user中查询操作员用户名
    txtSQL = "select * from user_info where level='操作员'"
    Set umrc = ExecuteSQL(txtSQL, MsgText)
   
    While (umrc.EOF = False)
        comboUserId.AddItem umrc.Fields(0) '加载用户名
        umrc.MoveNext  '移动到下一条记录
    Wend
    
    '从user中查询操作员真实名
    txtSQL = "select * from user_info where level='操作员'"
    Set mrcc = ExecuteSQL(txtSQL, MsgText)
    
    While (mrcc.EOF = False)
        comboUserName.AddItem mrcc.Fields(3) '加载真名
        mrcc.MoveNext '移动到下一条记录
    Wend
    
End Sub
然后,单击用户名,即出现相应的真名。

Private Sub comboUserId_Click()
    '单击combouserid,查询用户名,真实名
    '从user表中查
    txtSQL = "select username from user_info where userid='" & Trim(comboUserId.Text) & "'"
    Set mrcc = ExecuteSQL(txtSQL, MsgText)
    '赋值,真名显示在combousername
    comboUserName.Text = mrcc.Fields(0)
    '关闭数据集对象
    mrcc.Close
End Sub
二、在选中要结账的操作员后查询出相应的信息,这里以充值为例:

'查询充值表语句
    txtSQL = "select * from recharge_info where userid= '" & Trim(comboUserId.Text) & "'and status='未结账'and date='" & Format(Date, "yyyy-mm-dd") & "'"
    '执行查询语句
    Set remrc = ExecuteSQL(txtSQL, MsgText)
    '将查到的信息显示到mycharge(1)控件中
    '如果没有记录,则显示名称就可以
    If (remrc.EOF Or remrc.BOF) Then
        With myCharge(1)
            .Rows = 1 '第一行
            .CellAlignment = 4
            .TextMatrix(0, 0) = "学号"
            .TextMatrix(0, 1) = "卡号"
            .TextMatrix(0, 2) = "充值金额"
            .TextMatrix(0, 3) = "日期"
            .TextMatrix(0, 4) = "时间"
        End With
        Exit Sub
    Else
    '否则显示全部查询到的信息
        With myCharge(1)
            .Rows = 1
            .CellAlignment = 4
            .TextMatrix(0, 0) = "学号"
            .TextMatrix(0, 1) = "卡号"
            .TextMatrix(0, 2) = "充值金额"
            .TextMatrix(0, 3) = "日期"
            .TextMatrix(0, 4) = "时间"
            Do While Not remrc.EOF '若有记录,加进去
                .Rows = .Rows + 1  '防止空行的出现
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(remrc.Fields(1))
                .TextMatrix(.Rows - 1, 1) = Trim(remrc.Fields(2))
                .TextMatrix(.Rows - 1, 2) = Trim(remrc.Fields(3))
                .TextMatrix(.Rows - 1, 3) = Trim(remrc.Fields(4))
                .TextMatrix(.Rows - 1, 4) = Trim(remrc.Fields(5))
                .ColWidth(3) = 1600
                remrc.MoveNext  '移动到下一条记录
            Loop
            remrc.Close  '关闭数据集对象
        End With
    End If
    
其他几个,购卡、退卡、临时用户与充值雷同,在这里就不再多写了。

三、汇总,结账

       汇总,汇总,无非就是把查到的所有记录加和,显示在文本框中,主要是计算,结账的时候我是结的当天的账,一天一结账,这样就不会出现结账重复的情况。

'汇总,结账
    Dim N As Integer  '定义卡数
    Dim TmpRate As Single  '定义金额
    Dim cancelCash As Single  '定义退卡金额


    '查学生表中的临时用户,计算临时用户收费
    txtSQL = "select * from student_info where userid='" & Trim(comboUserId.Text) & "'and type='临时用户'and date='" & Format(Date, "yyyy-mm-dd") & "'"
    Set mrc = ExecuteSQL(txtSQL, MsgText)
    TmpRate = 0
    '计算临时用户收费
    While (mrc.EOF = False)
        TmpRate = TmpRate + mrc.Fields(7)
        mrc.Fields(11) = Trim("结账") '更新数据库
        mrc.MoveNext '移动到下一条记录
    Wend
    txtRegister = TmpRate  '将临时收费赋值给txtregister
    mrc.Close  '关闭数据库对象

    '查用户名,获取总卡数
    txtSQL = "select * from student_info where userid='" & Trim(comboUserId.Text) & "'and date='" & Format(Date, "yyyy-mm-dd") & "'"
    Set mrc = ExecuteSQL(txtSQL, MsgText)
    N = 0
    TmpRate = 0
    '循环计算总卡数
    While (mrc.EOF = False)
        N = N + 1
        mrc.Fields(11) = Trim("结账") '更新数据库结账
        mrc.MoveNext '移动到下一条记录
    Wend
    txtnum = N  '购卡数
    mrc.Close  '关闭数据集对象

    '查退卡表,获取退卡数和退卡金额
    txtSQL = "select * from cancelcard_info where userid='" & Trim(comboUserId.Text) & "'and date='" & Format(Date, "yyyy-mm-dd") & "'"
    Set mrccan = ExecuteSQL(txtSQL, MsgText)
    N = 0
    cancelCash = 0
    '计算退卡金额
    While (mrccan.EOF = False)
        N = N + 1
        cancelCash = cancelCash + mrccan.Fields(2)
        mrccan.Fields(6) = Trim("结账") '更新数据库
        mrccan.MoveNext
    Wend
    txtbackcard = N
    txtbackmoney = cancelCash '将退卡金额赋值给txtbackmoney
    mrccan.Close '关闭数据集对象


    '查充值表,获取充值金额
    txtSQL = "select * from recharge_info where userid='" & Trim(comboUserId.Text) & "'and date='" & Format(Date, "yyyy-mm-dd") & "'"
    Set remrc = ExecuteSQL(txtSQL, MsgText)
    TmpRate = 0
    '计算充值金额
    While (remrc.EOF = False)
        TmpRate = TmpRate + remrc.Fields(3)
        remrc.Fields(7) = Trim("结账") '更新数据库
        remrc.MoveNext '移动到下一条记录
    Wend
    txtrecharge = TmpRate  '将充值金额赋值给txtrecharge
    
    '计算购卡数
    txtBuycard.Text = Val(txtnum) + Val(txtbackcard)
    '计算应收金额
    txtcash.Text = Val(txtrecharge) + Val(txtRegister) - Val(txtbackmoney)
    '关闭数据集对象
    remrc.Close
       最后把结账信息更新到日结账表和周结账表中。

'填写日结账表的内容
    
    '本期余额
    txtSQL = "select * from student_info where userid='" & Trim(comboUserId.Text) & "'and date='" & Format(Date, "yyyy-mm-dd") & "'and type='固定用户'"
'    txtSQL = "select * from student_info where datediff(dd,offtime,getdate())=1"
    Set mrc = ExecuteSQL(txtSQL, MsgText)
    Do While Not mrc.EOF
        allcash = allcash + mrc.Fields(7)  '本期余额
        mrc.MoveNext
    Loop
    '当日消费余额
    txtSQL = "select * from line_info where offdate='" & Format(Date, "yyyy-mm-dd") & "'"
    Set lmrc = ExecuteSQL(txtSQL, MsgText)
    Do While Not lmrc.EOF
        consumecash = consumecash + lmrc.Fields(11)
        lmrc.MoveNext
    Loop
    '当日充值金额
    txtSQL = "select * from recharge_info where userid='" & Trim(comboUserId.Text) & "'and date='" & Format(Date, "yyyy-mm-dd") & "'"
    Set remrc = ExecuteSQL(txtSQL, MsgText)
    Do While remrc.EOF = False
        Rechargemoney = Rechargemoney + remrc.Fields(3)
        remrc.MoveNext
    Loop
    '当日退还金额
    txtSQL = "select * from cancelcard_info where userid='" & Trim(comboUserId.Text) & "'and date='" & Format(Date, "yyyy-mm-dd") & "'"
    Set mrccan = ExecuteSQL(txtSQL, MsgText)
    Do While mrccan.EOF = False
        cancelCash = cancelCash + mrccan.Fields(2)
        mrccan.MoveNext
    Loop
    remaincash = allcash - Rechargemoney + consumecash + cancelCash
    
    '关闭数据集对象
    mrc.Close
    lmrc.Close
    remrc.Close
    mrccan.Close
    
    '查询日结账表
    txtSQL = "select * from checkday_info "
    Set dmrc = ExecuteSQL(txtSQL, MsgText)
    '更新日结账表内容
    With dmrc
        .AddNew
        .Fields(0) = remaincash
        .Fields(1) = Rechargemoney
        .Fields(2) = consumecash
        .Fields(3) = cancelCash
        .Fields(4) = allcash
        .Fields(5) = Format(Date, "yyyy-mm-dd")
        .Update
        MsgBox "结账成功!"  '提示结账成功
        
    End With
    
    '更新周结账单
    txtSQL = "select * from checkweek_info"
    Set wmrc = ExecuteSQL(txtSQL, MsgText)
    '更新到周结表中
        With wmrc
            .AddNew
            .Fields(0) = dmrc.Fields(0)
            .Fields(1) = dmrc.Fields(1)
            .Fields(2) = dmrc.Fields(2)
            .Fields(3) = dmrc.Fields(3)
            .Fields(4) = dmrc.Fields(4)
            .Fields(5) = dmrc.Fields(5)
            .Update '更新数据集对象
            wmrc.MoveNext  '移动到下一条记录
        End With
        wmrc.Close  '关闭数据集对象
       这就是整个结账的过程。

       结账这部分花了很长时间弄好的,但是我相信时间是检验真理的标准,也是磨练我们意志的最硬的基石。奉劝大家一句,刚看到结账不要急着做,要先搞清思路,搞清算账的过程,根据自己想的试着去做,相信只要思路正确很快就可以做出来的,这也是我做结账的感受,如果以上有不合理的,欢迎大家来指正!






你可能感兴趣的:(【机房收费系统】——结账)