1. 程式人生 > >機房收費系統(四)-結賬

機房收費系統(四)-結賬

【前言】
在寫結賬程式碼之前,我們要明白結賬的含義和思路。
含義:是誰來結賬?結的是誰的賬?這是必須弄明白的。
結賬:是管理員來結賬,管理員結的是操作員的賬。
之前總是聽別人說結賬是個難點,所以心裡有點抵觸,並且不想去做,感覺自己不會做,弄不明白。只有做過之後才知道它是不是很難,這是做完之後的感受。所以什麼事首先不要去顧慮太多,去做就好了。
【內容】
在結賬的過程中,我認為稍微有些難度的就是彙總選項和結賬按鈕了,思路很重要。下面是我對結賬的總結:
購卡(student表)
充值(Recharge表)
退卡(CancelCard表)
臨時使用者(student表)
彙總(student表、Recharge表、CancelCard表)


在這裡插入圖片描述
售卡張數:在student_info 表中當天該操作員未結賬的記錄條數。
退卡張數:cancelcard_info 表中當天該操作員未結賬的記錄條數。
充值金額:recharge_info 表中該操作員當天未結賬的金額總數。
臨時收費金額:student表中當天該操作員對臨時使用者的收費金額。
退卡金額:cancelcard_info 表中操作員當天未結賬的金額總數。
總售卡張數:售卡張數-退卡張數
應收總金額:充值金額+註冊金額-退卡金額

以下是我的結賬程式碼,望指點!
SSTab1點選事件:

Private Sub SSTab1_Click(PreviousTab As Integer)

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

相關推薦

機房收費系統-結賬

【前言】 在寫結賬程式碼之前,我們要明白結賬的含義和思路。 含義:是誰來結賬?結的是誰的賬?這是必須弄明白的。 結賬:是管理員來結賬,管理員結的是操作員的賬。 之前總是聽別人說結賬是個難點,所以心裡有點抵觸,並且不想去做,感覺自己不會做,弄不明白。只有做過之後才

機房收費系統---組合查詢

  涉及的窗體有學生基本資訊維護,學生上機記錄查詢,學生上機統計查詢初次見到組合查詢介面,有種似曾相識的感覺。沒錯,我們在學生資訊管理系統裡面見過類似的。也可以說我們已經接觸過組合查詢了。不同的是這次的組合查詢要多一點,相對來講複雜一點。今天我就用學生基本資訊維

機房收費系統項目開發計劃

tro 外部 程序語言 友好 知識 add sql 數據庫 名稱 項目開發計劃 1引言 1.1編寫目的 主要對開發機房收費系統的費用、時間、進度、人員組織、硬件設備的配置、開發環境和執行環境的配置進行說明。為開發的下一步做準備。預期讀者是系統分析員和開發者。

機房收費系統-組合查詢

【前言】 一拖再拖,組合查詢終於做完了,並且弄明白了其中的含義。下面就以操作員的工作記錄窗體為例,來總結一下組合查詢吧! 【內容】 組合查詢: 第一行(可單獨查詢)即為第一個條件,第二行為第二個條件,第三行為第三個條件。利用“組合關係”控制元件將條件連線起來,進行組合查詢。 導圖 這張

機房收費系統-上下機

【前言】 開始做機房時間也不短了,也看了不少大佬的部落格,但是真的是每個人有每個人的思路,所以我也有了自己的思路。剛開始的時候沒有什麼思路,不知道如何下手,只有靜下心來,一點點往下走,才能理清自己的思路。有些地方可能還存在不足,望指點。 【內容】 上機和下機導圖 上機程式碼 Priv

機房收費系統-命名規範

【前言】 命名規範至關重要,做好機房系統的第一步工作。 【內容】 1.主選單命名 一般使用者:GeneralUser 學生檢視餘額:StuInquiryBalanceMenu 學生檢視上機記錄:StuInquiryLineRecordMenu 學生充值記錄查詢:StuInquiryRec

機房收費系統------登入&修改

前言 進行機房也有一段時間了,一直處於走迷宮的狀態不知從何入手。從生活中出發,我們在使用某個系統時,一般情況下最先進入該系統的登入頁面。現在輪到自己敲系統了,當然也是從登入開始啦。 正文 機房收費系統登入窗體的思路,和有原始碼的學生系統的思路是大同

機房收費系統——組合查詢

對於敲完機房收費系統的我們對於組合查詢應該都不在陌生了吧。想想當時我在敲之前聽別人說它比較麻煩的時候,我足足停了兩天才開始對這部分下手。一下手就感覺我之前在學生資訊管理系統裡面見過啊(根據姓名、班級、

機房收費系統—再看組合查詢

寫在前面: 組合查詢顧名思義是多條件查詢,關鍵就是確定在一定的條件下需要查詢與這個條件想對應的內容,確定好查詢內容之後,每一次查詢都是在上一個條件基礎上加一個條件的查詢。 下面就看一下機房中複合查詢

機房收費系統——學生基本資訊維護

概述 學生基本資訊維護裡面所用到的知識點有查詢類,更準確的說是組合查詢。該知識點堪稱機房收費系統三大難點之一。那麼它的難到底難在哪裡?下面我們來逐一進行分析。 流程圖 通過上面兩張圖可以清晰的看到,查詢難在哪裡: 首先、我們需要進行判斷查詢是

機房收費系統——退卡操作

在敲機房的時候,感覺退卡挺簡單的,很快的完成了。但是驗收的時候,它卻出問題了——該卡正在上機,可以退卡,但是卻沒有對下機進行處理。現在重新來實現這個功能,其實仍然也是很簡單的。 一、整理思路    

機房收費系統——登入介面

概述 機房收費系統其實和學生資訊管理系統差不多,難度麼有增加多少。關鍵在於需要我們在敲程式碼之前把思路搞清楚,程式碼並不是什麼大事。這裡我就採用了畫流程圖的形式,把要實現的功能都畫出來,然後進行程式碼的編輯。下面就來分享我的思路和部分程式碼。 流程圖

機房收費系統1-註冊控制元件

根據師哥給的機房收費系統使用說明:在cmd命令中輸入“regsvr +路徑+控制元件名稱,相信大家在操作的時候都有如下試水。 看看犯的錯誤都覺得可笑,把”+“都給人家輸上了。圖中的錯誤提示框是最後一

機房收費系統之下機退卡

今天我又回顧了一下 機房管理系統,看見了我熟悉的花費了我三天才敲好的窗體(當然想了兩天),然後今天我就來總結一下下機退卡吧!  第一句話是讓子窗體在父窗體中的圖片框裡顯示! 其他的然後就是定義函式名

機房收費重構-SqlHelper

      最近由於學校專業課考試,導致上一篇的一些部落格沒有及時補上,讓讀者久等了,下面來說說關於DAL中一個模板吧-SqlHelper。      在敲機房收費中,有好多都是重複的訪問資料庫這些操作,這樣我們可以將這些步驟抽象出來,命名為SqlHelper。在任何時候想

機房收費系統VB.NET個人版總結

blog gb2 watermark ast 做到 解決 content 結果 avi 重構版個人機房收費系統大概從暑假開學開始進行。花了不到一個半月的時間才完畢。以下對我在重構過程中的一寫理解。 1、系統設計一個非常重要的目的就是重用。而要做

機房收費系統命名篇

主介面選單編輯器命名如下 PS:(用menu作字尾) 一般使用者   GeneralUser 學生檢視餘額 InquiryBalance學生檢視上機記錄 InquiryLineRecord學生充值記錄查詢  InquiryRechargeRec

機房收費系統準備篇

開始機房前,我預計先學習觀看一下11期師哥師姐打包給12期師哥師姐的機房系統,於是我安裝後點擊開始,出現錯誤: 執行錯誤’91’:未設定物件變數或with block變數 這個是因為沒有連線到資料庫,所以我需要配置ODBC,配置過程如下: 在這裡我們看到了,

【 專欄 】- 機房收費系統VB版+C#

機房收費系統(VB版+C#) VB與資料庫的互動,VB各種控制元件的調整,SQL語句的熟練使用,以及後期系統的除錯優化,以小見大,都能給我們很好的啟發! 後期的C#重構的機房收費系統,對於三層的理解,資料庫的設計,設計模式的使用

自己搭建自動化巡檢系統 處理鄰居列表

telnet遠程登錄 cisco python 通過之前的三次實驗,我們已經可以初步的使用python通過telnet來操作cisco設備,接下來開始新一期的實驗實驗目的:網絡巡檢,之後將信息存儲在數據庫中本次實驗需要再次拓展新的拓撲,,且實驗環境改為ubuntu,後續的拓展將改為在linux環境