機房收費係統之結賬與報表
機房收費係統在幾天前終於告一個段落了,這篇是關於最後階段結賬與報表的總結。
結賬,首先清楚該窗體的作用是:管理員對每個操作員工作情況的查看。其中包括售卡數量,充值金額以及退還金額。
知道全局後,操作上就會簡單不少了。我們需要做的就是將遍曆學生信息表、充值信息表和退卡信息表後的該操作員和結賬狀態為“未結賬”的所有金額總計。然後在單擊結賬後,將匯總後的信息寫入結賬表,將前麵三個表中的結賬狀態標記為“已結賬”。
結賬流程:
Part One:將所有操作員ID和Name提取出來,以供選擇。(下麵以選擇姓名為例)
<strong><span > '將數據庫中操作員的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 > '充值選項
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 >'將所有信息修改為“已結賬”
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 >'連接結賬表,將新的信息寫入表中
'向結賬表中添加數據
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 > '不管是否結賬,都將該操作員的信息寫入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做報表(一)https://blog.csdn.net/wlccomeon/article/details/8269917
用VB做報表(二)https://blog.csdn.net/wlccomeon/article/details/8296679
很詳細的講解,一個報表,也可以輕鬆搞定。
最後,說說做這個部分的感受。還是感覺全局認識很重要,如果心中沒有譜,肯定不知道如何下手。與其浪費時間坐在那瞎想,瞎敲,還不如花些時間把流程弄明白。這樣會起到一個事半功倍的效果。
最後更新:2017-04-03 07:57:16