机房结账

感受

机房项目总共有三个大难点,其中比较重要的分别是上下机和结账,而组合查询因为没有涉及到金钱,所以暂居两者之后。之前我曾分享了自己对于上机,下机的想法,所以这次我就来写写结账窗体的那二三事。
1.预载用户列

Private Sub Form_Load()
    Dim txtSQL As String
    Dim Msgtext As String
    Dim mrc As ADODB.Recordset
    
    txtSQL = "select * from User_Info where Level = '操作员'"
    Set mrc = ExecuteSQL(txtSQL, Msgtext)
    Do While Not mrc.EOF
        ComboUserID.AddItem mrc!UserID
        mrc.MoveNext
    Loop
    If Trim(ComboUserID.Text) = "" Then
        MsgBox "没有用户,请先添加用户!", vbOKOnly + vbExclamation, "提示"
        FrmADUser.Show
    End If
End sub

2.选择加载
在这里插入图片描述
根据选择的用户,自动加载相关的信息

    Dim txtSQL As String
    Dim Msgtext As String

	txtSQL = "select * from xx表 where UserID(以数据表为准) = '" & Trim(ComboUserID) & "'" & "and Ischeck = '未结账'"    '连接至数据库
	Set mrc = ExecuteSQL(txtSQL, Msgtext)
	
	With MSFlexGrid1                                '加载模板
        .ColWidth(2) = 1800
        .Rows = 1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "日期"
        .TextMatrix(0, 3) = "时间"
    End With
    
    Do While Not mrc.EOF
        With MSFlexGrid1                        '将回执信息显示在窗体上
            .ColWidth(2) = 1800
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrc!studentNo)
            .TextMatrix(.Rows - 1, 1) = Trim(mrc!cardno)
            .TextMatrix(.Rows - 1, 2) = Trim(mrc!Date)
            .TextMatrix(.Rows - 1, 3) = Trim(mrc!Time)
            mrc.MoveNext
        End With
    Loop

3.金钱计算(!!!)
在这里插入图片描述
售卡张数 = 学生表中该操作员旗下未结账的记录
退卡张数 = 退卡表中该操作员旗下未结账的记录
充值金额 = 充值表中该操作员旗下未结账的记录的充值金额之和
退卡金额 = 退卡表中该操作员旗下未结账的记录的退款金额之和
总售卡数 = 学生表中该操作员旗下未结账的记录 + 退卡表中该操作员旗下未结账的记录
应收金额 = 充值金额 - 退卡金额
需要注意的是:充值金额不仅仅包含了充值时的记录,购卡时的金额也是充值表的一部分忽略这一点就会出现对不清账的情况
计算的方法基本是共同的

txtSQL = "select * from student_Info where UserID = '" & Trim(ComboUserID.Text) & "'" & "and Ischeck = '未结账'"    '售卡统计
    Set mrc = ExecuteSQL(txtSQL, Msgtext)
    
    i = 0
    Do While Not mrc.EOF
        i = i + 1
        mrc.MoveNext
    Loop
    TxtSellCard.Text = i

4.数据更新(闭环)(!!!)
在将金额计算正确之后,需要将相关的数据更新到各个表中,结账一共涉及到了四个表的更新,分别是学生表,充值表,退卡表,以及日结账单

	txtSQL = "select * from Recharge_Info where userID = '" & Trim(ComboUserID.Text) & "'" & "and status = '未结账'"
    Set mrc1 = ExecuteSQL(txtSQL, Msgtext)
    
    Do While Not mrc1.EOF
        mrc1.Fields(7) = "结账"
        mrc1.Update
        mrc1.MoveNext
    Loop
txtSQL = "select * from CheckDay_Info where date ='" & Date & "'"
    Set mrc = ExecuteSQL(txtSQL, Msgtext)
    txtSQL = "select sum (allcash) from CheckDay_Info where date = '" & Date - 1 & "'"                 '计算昨天的总收入
    Set mrc1 = ExecuteSQL(txtSQL, Msgtext)
    txtSQL = "select sum(consume) from Line_Info where offdate = '" & Date & "'"                     '计算今天的消费金额
    Set mrc2 = ExecuteSQL(txtSQL, Msgtext)
    
    If IsNull(mrc2.Fields(0)) Then                                                                      '无信息则为0
        xfjy = 0
    Else
        xfjy = mrc2.Fields(0)                                                                             '赋值
    End If
    
    
    If IsNull(mrc1.Fields(0)) Then                                                                   '无信息则为0
        sqye = 0
    Else
        sqye = mrc1.Fields(0)                                                                        '赋值
    End If
              
    b = g - e
    
    If Not mrc.EOF And Not mrc.BOF Then                                                     '判断是否已有记录
        mrc.Fields(0) = sqye
        mrc.Fields(1) = g + mrc.Fields(1)
        mrc.Fields(2) = xfjy
        mrc.Fields(3) = e + mrc.Fields(3)
        mrc.Fields(4) = b + mrc.Fields(4)
        mrc.Update
    Else																										‘无则加新’
        mrc.AddNew
        mrc.Fields(0) = sqye
        mrc.Fields(1) = g
        mrc.Fields(2) = xfje
        mrc.Fields(3) = e
        mrc.Fields(4) = b
        mrc.Fields(5) = Date
        mrc.Update
    End If
    MsgBox "结账成功!", vbOKOnly + vbExclamation, "提示"

至此,我们的机房结账就可以宣告竣工了。

总结

机房结账本身并没有特别难的地方,只是需要我们严谨的去对待金钱计算逻辑及整个机房系统的信息闭环更新。而谨慎和细心正是我们作为一个软件从业者必须具备的一个品质。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值