机房收费系统在几天前终于告一个段落了,这篇是关于最后阶段结账与报表的总结。
结账,首先清楚该窗体的作用是:管理员对每个操作员工作情况的查看。其中包括售卡数量,充值金额以及退还金额。
知道全局后,操作上就会简单不少了。我们需要做的就是将遍历学生信息表、充值信息表和退卡信息表后的该操作员和结账状态为“未结账”的所有金额总计。然后在单击结账后,将汇总后的信息写入结账表,将前面三个表中的结账状态标记为“已结账”。
结账流程:
Part One:将所有操作员ID和Name提取出来,以供选择。(下面以选择姓名为例)
<strong><span style="font-family:KaiTi_GB2312;font-size:18px;"> '将数据库中操作员的UserName提供出来 strTxtSQL = "select UserID from tb_User where userlevel='操作员'" Set mrc = ExecuteSQL(strTxtSQL, strMsgText) '点击操作员姓名,相应地出现其ID strTxtSQL = "select * from tb_User where username='" & comboOperatorName.Text & "'" Set mrc = ExecuteSQL(strTxtSQL, strMsgText) comboOperatorID.Text = mrc.Fields(0)</span></strong>
Part Two:从ID或Name中任意选择一个,便将该操作员的工作记录显示在SSTAB控件中,全部是“未结账”状态下的工作记录。(下面以充值选项为例)
<strong><span style="font-family:KaiTi_GB2312;font-size:18px;"> '充值选项 RechargeFlexGrid.Visible = True '从充值表中查看是否有该操作员的充值工作记录 strTxtSQL = "select * from tb_Recharge where checkState = '未结账' and UserID= '" & Trim(comboOperatorID.Text) & "'" Set mrc = ExecuteSQL(strTxtSQL, strMsgText) If mrc.EOF = True Then '该操作员没有充值工作记录 With RechargeFlexGrid .Rows = 1 .TextMatrix(0, 0) = "卡号" .TextMatrix(0, 1) = "学号" .TextMatrix(0, 2) = "日期" .TextMatrix(0, 3) = "时间" .TextMatrix(0, 4) = "充值金额" End With Else With RechargeFlexGrid '该操作员充值工作记录显示 .Rows = 1 .TextMatrix(0, 0) = "卡号" .TextMatrix(0, 1) = "学号" .TextMatrix(0, 2) = "日期" .TextMatrix(0, 3) = "时间" .TextMatrix(0, 4) = "充值金额" .ColWidth(0) = 800 .ColWidth(1) = 800 .ColWidth(2) = 2000 .ColWidth(3) = 2000 .ColWidth(4) = 2000 Do While Not mrc.EOF .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = mrc.Fields(2) .TextMatrix(.Rows - 1, 1) = mrc.Fields(1) .TextMatrix(.Rows - 1, 2) = mrc.Fields(4) .TextMatrix(.Rows - 1, 3) = mrc.Fields(5) .TextMatrix(.Rows - 1, 4) = mrc.Fields(3) .ColWidth(0) = 800 .ColWidth(1) = 800 .ColWidth(2) = 2000 .ColWidth(3) = 2000 .ColWidth(4) = 2000 '该操作员通过学生充值所获得的金额 Rechargemoney = Rechargemoney + Trim(mrc.Fields(3)) mrc.MoveNext Loop '该操作员的售卡金额 txtRechargeSum.Text = Trim(Rechargemoney) mrc.Close End With '该操作员的注册、充值和退卡后的总金额 txtSum.Text = Val(Trim(txtSum.Text)) + Val(Trim(txtRechargeSum.Text)) - Val(Trim(txtReturnCardSum.Text)) End If</span></strong>
Part Three:确认结账。将所有表中结账状态改变。(以充值表为例)
<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">'将所有信息修改为“已结账” strTxtSQL = "select * from tb_recharge where userid ='" & Trim(comboOperatorID.Text) & "'" & " and checkstate = '" & "未结账" & "'" Set mrc = ExecuteSQL(strTxtSQL, strMsgText) Do While mrc.EOF = False mrc.Fields(7) = "已结账" mrc.Update mrc.MoveNext Loop mrc.Close</span></strong>
并将数据写入到结账表中。
<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">'连接结账表,将新的信息写入表中 '向结账表中添加数据 strTxtSQL = "select * from tb_checkout where userid='" & Trim(comboOperatorID.Text) & "'" Set mrc = ExecuteSQL(strTxtSQL, strMsgText) '如果没有新的记录则提示 If Trim(txtSaleCardCount.Text) = "0" And Trim(txtRechargeSum.Text) = "0" And _ Trim(txtReturnCardCount.Text) = "0" And Trim(txtReturnCardSum.Text) = "0" And _ Trim(txtSaleCardSum.Text) = "0" And Trim(txtSum.Text) = "0" Then MsgBox "数据未更新,结账操作无效!", vbOKOnly + vbExclamation, "结账提示" End If '如果有新的工作记录 strTxtSQL = "select * from tb_checkout where userid='" & Trim(comboOperatorID.Text) & "'" Set mrc = ExecuteSQL(strTxtSQL, strMsgText) If mrc.EOF = True Then lastbalance = " 0" Else lastbalance = mrc.Fields(1) End If '向结账表中添加数据 mrc.AddNew mrc.Fields(0) = frmLogin.txtUserName.Text mrc.Fields(1) = lastbalance mrc.Fields(2) = txtRechargeSum.Text mrc.Fields(3) = txtCasualSum.Text mrc.Fields(4) = txtReturnCardSum.Text mrc.Fields(5) = txtSum.Text mrc.Fields(6) = Date mrc.Fields(7) = "已结账" mrc.Update mrc.Close MsgBox "已成功结账!", vbOKOnly + vbExclamation, "结账提示"</span></strong>
Part Four:解决问题。如果按照上面的流程去做,那么在结账表中只会出现该管理员点击“结账”后的记录。如果该管理员某天休息,没有及时结账,那么这一天的数据变会丢失。那么账单中肯定会少钱了,这系统做的就不合格了。所以,在此之前,我将所有信息都先存在了另一个新表中,不管是该管理员结账了还是没结账,数据都写进去。
<strong><span style="font-family:KaiTi_GB2312;font-size:18px;"> '不管是否结账,都将该操作员的信息写入DayCheck中 '向表DayCheck中添加数据 strTxtSQL = "select * from tb_daycheck where date ='" & Trim(Label10.Caption) & "'" Set mrc = ExecuteSQL(strTxtSQL, strMsgText) If mrc.EOF = True Then Trim(lastbalance) = 0 mrc.AddNew mrc.Fields(0) = lastbalance mrc.Fields(1) = txtRechargeSum.Text mrc.Fields(2) = txtCasualSum.Text mrc.Fields(3) = txtReturnCardSum.Text mrc.Fields(4) = txtSum.Text mrc.Fields(5) = Date mrc.Update mrc.Close Else mrc.MoveLast lastbalance = Trim(mrc.Fields(4)) mrc.MoveNext mrc.AddNew mrc.Fields(0) = lastbalance mrc.Fields(1) = txtRechargeSum.Text mrc.Fields(2) = txtCasualSum.Text mrc.Fields(3) = txtReturnCardSum.Text mrc.Fields(4) = txtSum.Text mrc.Fields(5) = Date mrc.Update mrc.Close End If</span></strong>
Part Five:制作报表,以便查询账单。
报表,一个以前没有接触的东西。刚开始,可能无从下手,不过我们可以站在巨人的肩膀上,如果你的报表还没有做,推荐一个师哥的博客:
用VB做报表(一)http://blog.csdn.net/wlccomeon/article/details/8269917
用VB做报表(二)http://blog.csdn.net/wlccomeon/article/details/8296679
很详细的讲解,一个报表,也可以轻松搞定。
最后,说说做这个部分的感受。还是感觉全局认识很重要,如果心中没有谱,肯定不知道如何下手。与其浪费时间坐在那瞎想,瞎敲,还不如花些时间把流程弄明白。这样会起到一个事半功倍的效果。