机房收费系统(四)-结账

【前言】
在写结账代码之前,我们要明白结账的含义和思路。
含义:是谁来结账?结的是谁的账?这是必须弄明白的。
结账:是管理员来结账,管理员结的是操作员的账。
之前总是听别人说结账是个难点,所以心里有点抵触,并且不想去做,感觉自己不会做,弄不明白。只有做过之后才知道它是不是很难,这是做完之后的感受。所以什么事首先不要去顾虑太多,去做就好了。
【内容】
在结账的过程中,我认为稍微有些难度的就是汇总选项和结账按钮了,思路很重要。下面是我对结账的总结:
购卡(student表)
充值(Recharge表)
退卡(CancelCard表)
临时用户(student表)
汇总(student表、Recharge表、CancelCard表)

在这里插入图片描述
售卡张数:在student_info 表中当天该操作员未结账的记录条数。
退卡张数:cancelcard_info 表中当天该操作员未结账的记录条数。
充值金额:recharge_info 表中该操作员当天未结账的金额总数。
临时收费金额:student表中当天该操作员对临时用户的收费金额。
退卡金额:cancelcard_info 表中操作员当天未结账的金额总数。
总售卡张数:售卡张数-退卡张数
临时收费金额:包括在充值金额中!
应收总金额:充值金额(注册+充值)- 退卡金额

以下是我的结账代码,望指点!
comboUserID点击事件

Private Sub comboUserID_Click()

Dim MsgText As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim mrcReCharge As ADODB.Recordset
Dim mrcCancelCard As ADODB.Recordset
Dim mrcStu As ADODB.Recordset

Dim RechargeCash As Variant      '用于存储,充值的 所有金额
Dim CancelCash As Variant        '用于存储,退钱的 所有金额
Dim TmpCash As Variant           '临时用户金额

    '购卡(student表)
    If SSTab1.Caption = "购卡" Then
        StuSQL = "select * from student_Info where UserID='" & comboUserID.Text & "' and status='未结账'"
        Set mrcStu = ExecuteSQL(StuSQL, MsgText)
        MSFlexGrid1.Rows = mrcStu.RecordCount + 1
    
        With MSFlexGrid1
            .Rows = 1
            .CellAlignment = 4  '居中
            .TextMatrix(0, 0) = "学号"
            .TextMatrix(0, 1) = "卡号"
            .TextMatrix(0, 2) = "日期"
            .TextMatrix(0, 3) = "时间"
            .TextMatrix(0, 4) = "使用状态"
            .TextMatrix(0, 5) = "结账情况"
            
        While mrcStu.EOF = False
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrcStu.Fields(1))
            .TextMatrix(.Rows - 1, 1) = Trim(mrcStu.Fields(0))
            .TextMatrix(.Rows - 1, 2) = Trim(mrcStu.Fields(12))
            .TextMatrix(.Rows - 1, 3) = Trim(mrcStu.Fields(13))
            .TextMatrix(.Rows - 1, 4) = Trim(mrcStu.Fields(10))
            .TextMatrix(.Rows - 1, 5) = Trim(mrcStu.Fields(11))
            mrcStu.MoveNext
        Wend
        End With
    End If
 
    '充值(ReCharge表)
    If SSTab1.Caption = "充值" Then
        ReChargeSQL = "select * from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
        RechargeCash = 0
        With MSFlexGrid2
            .Rows = 1
            .CellAlignment = 5
            .TextMatrix(0, 0) = "卡号"
            .TextMatrix(0, 1) = "学号"
            .TextMatrix(0, 2) = "充值金额"
            .TextMatrix(0, 3) = "日期"
            .TextMatrix(0, 4) = "时间"
            
        Do While Not mrcReCharge.EOF
            .Rows = .Rows + 1
            .TextMatrix(.Rows - 1, 0) = mrcReCharge.Fields(2)
            .TextMatrix(.Rows - 1, 1) = mrcReCharge.Fields(1)
            .TextMatrix(.Rows - 1, 2) = mrcReCharge.Fields(3)
            .TextMatrix(.Rows - 1, 3) = mrcReCharge.Fields(4)
            .TextMatrix(.Rows - 1, 4) = mrcReCharge.Fields(5)
            mrcReCharge.MoveNext
        Loop
        End With
    End If
    
    
    '退卡(CancelCard表)
    If SSTab1.Caption = "退卡" Then
        CancelCardSQL = "select * from CancelCard_Info where status='未结账'and UserID='" & comboUserID.Text & "'"
        Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
        CancelCash = 0
        With MSFlexGrid3
            .Rows = 1
            .CellAlignment = 4      '居中
            .TextMatrix(0, 0) = "学号"  'studentid
            .TextMatrix(0, 1) = "卡号"  'cardid
            .TextMatrix(0, 2) = "日期"  'cash
            .TextMatrix(0, 3) = "时间"  'date
            .TextMatrix(0, 4) = "退卡金额"
            .TextMatrix(0, 5) = "结账情况"
        
        While Not mrcCancelCard.EOF
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrcCancelCard.Fields(0))  'studentno
            .TextMatrix(.Rows - 1, 1) = Trim(mrcCancelCard.Fields(1))   'cardno
            .TextMatrix(.Rows - 1, 2) = Trim(mrcCancelCard.Fields(3))   'date
            .TextMatrix(.Rows - 1, 3) = Trim(mrcCancelCard.Fields(4))   'time
            .TextMatrix(.Rows - 1, 4) = Trim(mrcCancelCard.Fields(2))   'cancelcash
            .TextMatrix(.Rows - 1, 5) = Trim(mrcCancelCard.Fields(6))   'cancelcash
            CancelCash = CancelCash + mrcCancelCard.Fields(2)
            mrcCancelCard.MoveNext
        Wend
        End With
    End If
    
    '临时用户(student表)
    If SSTab1.Caption = "退卡" Then
        StuSQL = "select * from student_Info where status='使用' and UserID='" & comboUserID.Text & "'and type='临时用户'and Ischeck='未结账'"
        Set mrcStu = ExecuteSQL(StuSQL, MsgText)
        TmpCash = 0
        With MSFlexGrid4
            .Rows = 1
            .CellAlignment = 4
            .TextMatrix(0, 0) = "学号"
            .TextMatrix(0, 1) = "卡号"
            .TextMatrix(0, 2) = "日期"
            .TextMatrix(0, 3) = "时间"
            .TextMatrix(0, 4) = "结账情况"
        
        While mrcStu.EOF = False
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrcStu.Fields(1))
            .TextMatrix(.Rows - 1, 1) = Trim(mrcStu.Fields(0))
            .TextMatrix(.Rows - 1, 2) = Trim(mrcStu.Fields(12))
            .TextMatrix(.Rows - 1, 3) = Trim(mrcStu.Fields(13))
            .TextMatrix(.Rows - 1, 4) = Trim(mrcStu.Fields(11))
            TmpCash = mrcStu.Fields(7)
            mrcStu.MoveNext
        Wend
        End With
    End If
    
    If MSFlexGrid4.Rows = 1 Then
        RechargeCash = "0"
    Else
        ReChargeSQL = "select * from ReCharge_Info where status='未结账' and UserID='" & comboUserID.Text & "'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
        Do While Not mrcReCharge.EOF
            RechargeCash = RechargeCash + mrcReCharge.Fields(3)
            mrcReCharge.MoveNext
        Loop
    End If
    
    '汇总(student表)
    If SSTab1.Caption = "汇总" Then
    
        '计算售卡张数
        StuSQL = "select * from student_info where UserID = '" & Trim(comboUserID.Text) & "'and ischeck = '" & "未结账" & "'"
        Set mrcStu = ExecuteSQL(StuSQL, MsgText)
        txtSCard.Text = mrcStu.RecordCount
   
        '计算退卡张数
        CancelCardSQL = "select * from CancelCard_info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
        Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
        txtBCard.Text = mrcCancelCard.RecordCount
        
        '总售卡数=售卡张数-退卡张数
        txtAllSCard = txtSCard - txtBCard
        
        '计算充值金额(不区分固定还是临时用户)
        ReChargeSQL = "select sum(addmoney) from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
        If IsNull(mrcReCharge.Fields(0)) Then   '无记录
            txtChargeMoney.Text = "0"
        Else
            txtChargeMoney.Text = mrcReCharge.Fields(3)
        End If

        '计算退卡金额
        CancelCardSQL = "select sum(CancelCash) from CancelCard_Info where UserID = '" & Trim(comboUserID.Text) & "'and status = '" & "未结账" & "'"
        Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
        If IsNull(mrcCancelCard.Fields(0)) Then '无记录
            txtBMoney.Text = "0"
        Else
            txtBMoney.Text = mrcCancelCard.Fields(2)
        End If

        '计算临时收费金额
        ReChargeSQL = "select sum(addmoney) from ReCharge_Info where UserID = '" & Trim(comboUserID.Text) & "'and status = '未使用'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
        If IsNull(mrcReCharge.Fields(0)) Then   '无记录
            txtTemporaryMoney.Text = "0"
        Else
            txtTemporaryMoney.Text = mrcReCharge.Fields(3)
        End If

        '计算应收金额
        txtAllCollectMoney.Text = Val(txtChargeMoney.Text) - Val(txtBMoney.Text)
        mrcStu.Close         '关闭释放空间
        mrcReCharge.Close
        mrcCancelCard.Close
    End If
    
    '退出
    If SSTab1.Caption = "退出" Then
        Unload Me
    End If
End Sub

结账按钮:

Private Sub cmdAmount_Click()

Dim MsgText As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim checkWeekSQL As String
Dim CheckDaySQL As String
Dim LineSQL As String
Dim mrcStu As ADODB.Recordset          '代表学生表(student_info)
Dim mrcReCharge As ADODB.Recordset     '代表充值表(recharge_info)
Dim mrcCancelCard As ADODB.Recordset   '代表退卡表(cancelcard_info)
Dim mrcCheckDay As ADODB.Recordset     '代表日结账单(checkday_info)
Dim mrcLine As ADODB.Recordset         '代表line表(Line_info)

Dim remaincash As String               '上期金额
Dim RechargeCash As String             '充值金额
Dim consumecash As String              '消费金额
Dim CancelCash As String               '退卡金额
Dim allcash As String                  '汇总金额
    
    '判断是否已选择操作员
    If comboUserID.Text = "" Then
        MsgBox "请选择操作员后再结账!", 48, "警告"
        Exit Sub
    End If

    '更新学生表
    StuSQL = "select * from student_info where UserID = '" & Trim(comboUserID.Text) & "'and ischeck = '" & "未结账" & "'"
    Set mrcStu = ExecuteSQL(StuSQL, MsgText)
    Do While Not mrcStu.EOF
        mrcStu!ischeck = "结账"
        mrcStu.Update
        mrcStu.MoveNext
    Loop
    mrcStu.Close

    '更新充值表
    ReChargeSQL = "select * from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
    Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
    Do While Not mrcReCharge.EOF
        mrcReCharge!Status = "结账"
        mrcReCharge.Update
        mrcReCharge.MoveNext
    Loop
        mrcReCharge.Close
    
    '更新退卡表
    CancelCardSQL = "select * from CancelCard_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
    Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
    Do While Not mrcCancelCard.EOF
        mrcCancelCard!Status = "结账"
        mrcCancelCard.Update
        mrcCancelCard.MoveNext
    Loop
        mrcCancelCard.Close

    '更新日结账单表
    '计算上期充值卡余额(remaincash)
    CheckDaySQL = "select max(date) from CheckDay_Info"   'max(date)就是最近的一天
    Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
    If mrcCheckDay.BOF Then
        Exit Sub
        MaxDate = mrcCheckDay.Fields(5)
        CheckDaySQL = "select * from CheckDay_Info where date ='" & MaxDate & "'"
        Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
        If IsNull(mrcCheckDay.Fields(0)) Then
            remaincash = "0"
            Exit Sub
        Else
            remaincash = mrcCheckDay.Fields(0)
        End If
    End If
    
    '更新当天充值金额
    '充值金额是今天的值班的任意个操作员充值的金额,并且是已经结完账的
    '如果今天充值了一些金额,但是没有结账,则在计算日结账单时,不计入
    ReChargeSQL = "select sum(addmoney) from ReCharge_info where status = '结账' and date  = '" & Date & "'" '代表今天
    Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
    If IsNull(mrcReCharge.Fields(0)) Then
        RechargeCash = "0"
    Else
        RechargeCash = mrcReCharge.Fields(0)
    End If

    '计算当日消费金额
    LineSQL = "select sum(consume) from Line_Info where offdate='" & Date & "'"
    Set mrcLine = ExecuteSQL(LineSQL, MsgText)
    If IsNull(mrcLine.Fields(0)) Then
        consumecash = "0"
    Else
        consumecash = mrcLine.Fields(0)
    End If

   '更新计算当天的退卡金额(cancelcash)
   CancelCardSQL = "select sum(cancelcash) from CancelCard_Info where date='" & Date & "'and status = '结账'"
   Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
   If IsNull(mrcCancelCard.Fields(0)) Then
       CancelCash = "0"
   Else
       CancelCash = mrcCancelCard.Fields(0)
   End If

    '更新CheckDay表
    CheckDaySQL = "select * from CheckDay_info "
    Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
    
    '判断当天是否已经结过帐
    CheckDaySQL = "select * from CheckDay_info where date='" & Date & "'"
    Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
    If mrcCheckDay.EOF = False Then
        mrcCheckDay!remaincash = Val(remaincash)
        mrcCheckDay!RechargeCash = Val(RechargeCash)
        mrcCheckDay!consumecash = Val(consumecash)
        mrcCheckDay!CancelCash = Val(CancelCash)
        mrcCheckDay!allcash = Val(remaincash) + Val(RechargeCash) - Val(CancelCash) - Val(consumecash)
        mrcCheckDay!Date = Date
        mrcCheckDay.Update
        mrcCheckDay.Close
    Else
        mrcCheckDay.AddNew
        mrcCheckDay!remaincash = Val(remaincash)
        mrcCheckDay!RechargeCash = Val(RechargeCash)
        mrcCheckDay!consumecash = Val(consumecash)
        mrcCheckDay!CancelCash = Val(CancelCash)
        mrcCheckDay!allcash = Val(remaincash) + Val(RechargeCash) - Val(CancelCash)
        mrcCheckDay!Date = Date
        mrcCheckDay.Update
        mrcCheckDay.Close
    End If
    
    '更新周结账单
    checkWeekSQL = "delete checkWeek_info"
    Set mrccheckWeek = ExecuteSQL(checkWeekSQL, MsgText)
    
    checkWeekSQL = "insert into checkWeek_info select * from CheckDay_info"
    Set mrccheckWeek = ExecuteSQL(checkWeekSQL, MsgText)
    
    '清空文本框显示的信息
    txtSCard.Text = "0"
    txtBCard.Text = "0"
    txtChargeMoney.Text = "0"
    txtTemporaryMoney.Text = "0"
    txtBMoney.Text = "0"
    txtAllSCard.Text = "0"
    txtAllCollectMoney.Text = "0"
    MsgBox "结账成功!", 64, "温馨提示"
   
End Sub
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值