机房收费系统-结账

前言:

     敲着敲着,就到了最后的结账。一段时间与代码的碰撞,发现早已褪去了起初的畏惧和怀疑,反而越来越自信和自如了。这就是所谓的增加了代码的亲切感吧!突然发现生活开始越来越离不开代码,有时候就连做梦都是这个功能怎么实现,怎样让代码变得有准又精。好了,接下来给大家说说这最后的功能,结账吧!


内容:

     一、注意点:

     所谓结账,就是将该操作员或管理员将他所操作的购卡、充值、退卡以及临时用户的消费结账,将应得的钱结出来,形成收入,方便接下来的运行。其中比较重要的是汇总。我是这样计算的:

    1、售卡张数就是学生(student)表中UserID为登录名,未结账且在使用状态的卡的张数。

    2、退卡张数退卡表(cancelCard)中userID为登录名,未结账状态的卡的张数。

    3、总售卡数 = 售卡张数 - 退卡张数

    4、退卡金额为条件为2的退卡金额的总和。

    5、充值金额为充值表中UserID为登录名,未结账的充值金额的总和。

    6、应收金额 = 充值金额 - 退卡金额

          PS:这里需要注意的是注册时的充值金额在注册时就要更新到充值表中,切记不能忘记注册时的充值金额,不                    然会数据混乱。

    7、临时用户退卡就等于结账。

    最后当点击结账按钮时,我们要把student表、cancelcard表以及recharge表的ischeck属性改为“结账“!

    二、给大家展示一下部分代码吧,大家可以借鉴一下:

Private Sub SSTab1_Click(PreviousTab As Integer)
Dim i As Integer, j As Integer, t As Integer
If SSTab1.Tab = 0 Then                              '当点击购卡时

  With MSFlexGrid1
        .CellAlignment = 4
        .Rows = 1
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "日期"
        .TextMatrix(0, 3) = "时间"
  
  '选择student表中用户名为combo、未结账且为使用状态的数据
  txtsql = "select * from student_Info where UserID='" & Trim(ComboUserID.Text) & "'and Ischeck='" & "未结账" & "'and status='" & "使用" & "'"
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  
  Do While Not mrc.EOF
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1) & "")
        .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(0) & "")
        .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(12) & "")
        .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(13) & "")
        mrc.MoveNext
  Loop
  End With
End If



If SSTab1.Tab = 1 Then                                         '当点击充值时

  With MSFlexGrid2
        .CellAlignment = 4
        .Rows = 1
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "充值金额"
        .TextMatrix(0, 3) = "日期"
        .TextMatrix(0, 4) = "时间"
  
   '选择charge表中用户名为combo、未结账的数据
  txtsql = "select * from Recharge_Info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  
  Do While Not mrc.EOF
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1) & "")
        .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(2) & "")
        .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(3) & "")
        .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(4) & "")
        .TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(5) & "")
        mrc.MoveNext
  Loop
  End With
End If


If SSTab1.Tab = 2 Then                                              '当点击退卡时

  With MSFlexGrid3
        .CellAlignment = 4
        .Rows = 1
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "退卡金额"
        .TextMatrix(0, 3) = "日期"
        .TextMatrix(0, 4) = "时间"
  
   '选择cancelcard表中用户名为combo、未结账的数据
  txtsql = "select * from CancelCard_Info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  
  Do While Not mrc.EOF
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(0) & "")
        .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(1) & "")
        .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(2) & "")
        .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(3) & "")
        .TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(4) & "")
        mrc.MoveNext
  Loop
  End With
End If


If SSTab1.Tab = 3 Then                                          '当点击临时用户时

  With MSFlexGrid4
        .CellAlignment = 4
        .Rows = 1
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "日期"
        .TextMatrix(0, 3) = "时间"
  
  '选择学生表中用户名为comboid,类型为临时用户,且未结账的用户
  txtsql = "select * from student_Info where UserID='" & Trim(ComboUserID.Text) & "'and type='" & "临时用户" & "'and Ischeck='" & "未结账" & "'"
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  
  Do While Not mrc.EOF
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1) & "")
        .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(0) & "")
        .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(12) & "")
        .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(13) & "")
        mrc.MoveNext
  Loop
  End With
End If


If SSTab1.Tab = 5 Then                                             '当点击退出时
  Unload Me
End If


If SSTab1.Tab = 4 Then
  txtsql = "select * from student_Info where UserID='" & Trim(ComboUserID.Text) & "'and Ischeck='" & "未结账" & "'and status='" & "使用" & "'"       '计算售出卡的数量
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  txtSaleCard.Text = Val(mrc.RecordCount)                 '售卡数量
  
  txtsql = "select * from CancelCard_Info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"   '计算退卡数量
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  txtRtnNum.Text = Val(mrc.RecordCount)                   '退卡数量
  
  txtSaleCardNumber.Text = Val(txtSaleCard.Text) - Val(txtRtnNum.Text)           '售卡总数=售卡数量-退卡数量
  
  
  txtsql = "select * from CancelCard_Info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"   '退卡金额等于该操作员操作的所有用户退卡金额的总和
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  For i = 1 To mrc.RecordCount
    txtRtnSum.Text = Val(txtRtnSum.Text) + Val(mrc.Fields(2))
    mrc.MoveNext
  Next i

  txtsql = "select * from Recharge_Info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"       '充值时的金额
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  t = 0
  For i = 1 To mrc.RecordCount
    t = t + Val(mrc.Fields(3))
    mrc.MoveNext
  Next i
  txtRechargeSum = Val(t)                  '得出退卡金额
  
  
  txtsql = "select * from student_Info where UserID='" & Trim(ComboUserID.Text) & "'and type='" & "临时用户" & "'and Ischeck='" & "未结账" & "'and status='" & "使用" & "'"         '临时收费金额等于注册时的金额加上充值时的金额
  Set mrc = ExecuteSQL(txtsql, Msgtext)                         '注册时的金额
  i = 0: t = 0
  If Not mrc.EOF Then
    For i = 1 To mrc.RecordCount
      j = j + Val(mrc.Fields(7))
      mrc.MoveNext
    Next i
  End If
  txtsql = "select * from Recharge_Info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"
  Set mrc = ExecuteSQL(txtsql, Msgtext)
  i = 0: t = 0
  If Not mrc.EOF Then
    For i = 1 To mrc.RecordCount
      t = t + Val(mrc.Fields(3))
      mrc.MoveNext
    Next i
  End If
  txtTemporarySum = Val(j) + Val(t)                  '将两项相加得出退卡金额
  
  txtSum.Text = Val(txtRechargeSum.Text) + Val(txtTemporarySum.Text) - Val(txtRtnSum.Text)         '应收金额等于充值金额+临时收费金额-退卡金额
  
End If
End Sub

总结:

     最后到了结账,也就意味着机房收费系统到了尾声。当然,最重要的就是颗粒归仓。很多同学都说要形成自己的代码库,这点我非常的赞同,相信通过几年的积累,代码库一定会形成,而且会又精又准。


评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值