1. 程式人生 > >機房收費系統之結賬總結

機房收費系統之結賬總結

【前言】

說到機房結賬,說難不難,說簡單也簡單,只要捋清楚思理接著再寫程式碼就可以了,本次是第一次機房,只是初次接觸結賬的,只要是賬能對的上就可以,這次機房的驗收光結賬我就驗收了三次,還是有個嚴格的師傅好啊,跟我講了很多,正好另一個師傅在做機房重構,一些內容和第一的機房的區別都告訴了。

【機房結賬理解】

要想把結賬做好首先要知道理解它的功能,結賬是給誰結的對吧!我把機房專案當作成一個網咖。

一般使用者:來上網的人

操作員: 網管

管理員: 網咖老闆

管理員那一列就是給網咖老闆用的,之前我們涉及到了級別登陸在資料庫中User_Info表中不難看出,登陸管理員的賬號操作那一下拉選單,之後老闆來看操作員網管一天都辦理了幾張卡,充值了多少,臨時使用者又辦了幾張,最後又退卡還給人家多少錢,最後這就是他一天獲利的錢。

結賬:三進一出, 有這個理解不會讓用你軟體的成為一個糊塗老闆。

應收金額=充值金額+臨時收費金額 -退卡金額

在就是知道SSTab控制元件中購卡、充值、退卡、臨時使用者所對應的表,充值金額是固定使用者平時充值的記錄,而臨時使用者不具備充值這個功能,所以在管理員算今天櫃檯上的收入的時候,就應該算上臨時使用者消費的金額和固定使用者充值的金額,再減掉退卡金額。

結賬部分程式碼

    '計算上期充值卡餘額
    txtSQL = "select sum(cash) from student_Info where UserID='" & Trim(cmbOpUserID.Text) & "' and Ischeck ='" & "未結賬" & "'"
        Set mrcStudent = ExecuteSQL(txtSQL, MsgText)
        If IsNull(mrcStudent.Fields(0)) Then
            sumcash = 0
        Else
            sumcash = mrcStudent.Fields(0)
        End If

    '計算line表當日消費餘額
    txtSQL = "select sum(cash) from Line_Info where offdate='" & Date & "'"
        Set mrcline = ExecuteSQL(txtSQL, MsgText)
        If IsNull(mrcline.Fields(0)) Then
            ConsumeCash = 0
        Else
            ConsumeCash = mrcline.Fields(0)
        End If

    '將相應的記錄存入到日結表
    txtSQL = "select * from CheckDay_Info"
    Set mrcCheckDay = ExecuteSQL(txtSQL, MsgText)
            
    '當天結多次賬的情況,就在原有基礎上更新
    mrcCheckDay.AddNew
        mrcCheckDay!RemainCash = sumcash + mrcCheckDay!RemainCash
        mrcCheckDay!RechargeCash = Val(txtRechargeMoney.Text) + mrcCheckDay!RechargeCash
        mrcCheckDay!ConsumeCash = ConsumeCash + mrcCheckDay!ConsumeCash
        mrcCheckDay!CancelCash = Val(txtBackCardMoney.Text) + mrcCheckDay!CancelCash
        mrcCheckDay!AllCash = (sumcash + Val(txtRechargeMoney.Text) - Val(txtBackCardMoney.Text) - ConsumeCash) + mrcCheckDay!AllCash
        mrcCheckDay!Date = Date
        mrcCheckDay.Update
        mrcCheckDay.Close
        mrcStudent.Close
        mrcline.Close


    txtSQL = "select * from student_Info where UserID='" & cmbOpUserID.Text & "'"
        Set mrcStudent = ExecuteSQL(txtSQL, MsgText)

            Do While Not mrcStudent.EOF
                mrcStudent.Fields(11) = "結賬"
                mrcStudent.MoveNext
            Loop

    txtSQL = "select * from ReCharge_Info where UserID='" & cmbOpUserID.Text & "'"
        Set mrcRecharge = ExecuteSQL(txtSQL, MsgText)

        Do While Not mrcRecharge.EOF
            mrcRecharge.Fields(7) = "結賬"
            mrcRecharge.MoveNext
        Loop

    txtSQL = "select * from CancelCard_Info where UserID='" & cmbOpUserID.Text & "'"
        Set mrcCancelCard = ExecuteSQL(txtSQL, MsgText)

        Do While Not mrcCancelCard.EOF
            mrcCancelCard.Fields(6) = "結賬"
            mrcCancelCard.MoveNext
        Loop

        MsgBox "結賬成功!", vbOKOnly + vbExclamation, "提示"
            txtSalecard.Text = "0"
            txtBackCardMoney.Text = "0"
            txtBackCard.Text = "0"
            txtSalecardSum.Text = "0"
            txtRechargeMoney.Text = "0"
            txtCollectMoney.Text = "0"
            txtTemRecharge.Text = "0"

【結賬查詢】

結賬的時候應該修改相應的資料庫資訊(將結賬的所有賬戶資訊改為“已結賬”),並且在checkWeek_Info和checkDay_Info中新增資料,方便在報表中呼叫,完成之後將窗體的所有資訊清0。

注意:

既然這裡將所有資訊都改為了“已結賬”,那麼這些使用者下次登入的記錄將不再收集,但是確實消費了,所以在下次登入的時候應該將餘額大於0的使用者統一改回“未結賬”

仔細研究下這三個表中的status列和Ischeck列對應下面的程式碼思考下為什麼這麼寫,程式碼的重點在查詢表語句中。

【如下圖和程式碼】

【程式碼展示】

   '購卡
    If SSTab1.Tab = 0 Then
        With MSHFlexGrid1
            .CellAlignment = 4
            .Rows = 1
            .TextMatrix(0, 0) = "學號"
            .TextMatrix(0, 1) = "卡號"
            .TextMatrix(0, 2) = "日期"
            .TextMatrix(0, 3) = "時間"
        End With
    End If
    
        '選擇student表中使用者名稱為combo且未結賬的資料
        txtSQL = "select * from student_Info where UserID='" & cmbOpUserID.Text & "' and Ischeck='未結賬 ' and type='固定使用者 '"
        Set mrcStudent = ExecuteSQL(txtSQL, MsgText)
        SaleCard = mrcStudent.RecordCount
        
        With MSHFlexGrid1
        Do While Not mrcStudent.EOF
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = mrcStudent.Fields(1)
            .TextMatrix(.Rows - 1, 1) = mrcStudent.Fields(0)
            .TextMatrix(.Rows - 1, 2) = mrcStudent.Fields(12)
            .TextMatrix(.Rows - 1, 3) = mrcStudent.Fields(13)
            mrcStudent.MoveNext
        Loop
        End With
    
    
    
    '充值
    If SSTab1.Tab = 1 Then
        With MSHFlexGrid2
            .CellAlignment = 4
            .Rows = 1
            .TextMatrix(0, 0) = "學號"
            .TextMatrix(0, 1) = "卡號"
            .TextMatrix(0, 2) = "充值金額"
            .TextMatrix(0, 3) = "日期"
            .TextMatrix(0, 4) = "時間"
        End With
    End If
    
        '選擇recharge表中使用者名稱為combo、未結賬的資料
        txtSQL = "select * from Recharge_Info where UserID='" & cmbOpUserID.Text & "' and status='未結賬 '"
        Set mrcRecharge = ExecuteSQL(txtSQL, MsgText)
        RechargeMoney = 0
        
        With MSHFlexGrid2
        Do While Not mrcRecharge.EOF
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = mrcRecharge.Fields(1)
            .TextMatrix(.Rows - 1, 1) = mrcRecharge.Fields(2)
            .TextMatrix(.Rows - 1, 2) = mrcRecharge.Fields(3)
            .TextMatrix(.Rows - 1, 3) = mrcRecharge.Fields(4)
            .TextMatrix(.Rows - 1, 4) = mrcRecharge.Fields(5)
        RechargeMoney = RechargeMoney + mrcRecharge.Fields(3)
        mrcRecharge.MoveNext
        Loop
        End With
    
        
    '退卡
    If SSTab1.Tab = 2 Then
  
        With MSHFlexGrid3
            .CellAlignment = 4
            .Rows = 1
            .TextMatrix(0, 0) = "學號"
            .TextMatrix(0, 1) = "卡號"
            .TextMatrix(0, 2) = "退卡金額"
            .TextMatrix(0, 3) = "日期"
            .TextMatrix(0, 4) = "時間"
        End With
    End If
    
    '選擇cancelcard表中使用者名稱為combo、未結賬的資料
    txtSQL = "select * from CancelCard_Info where UserId='" & cmbOpUserID.Text & "'and status='未結賬 '"
    
    Set mrcCancelCard = ExecuteSQL(txtSQL, MsgText)
        BackCardMoney = 0
        BackCard = mrcCancelCard.RecordCount
    
    With MSHFlexGrid3
    Do While Not mrcCancelCard.EOF
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = mrcCancelCard.Fields(0)
        .TextMatrix(.Rows - 1, 1) = mrcCancelCard.Fields(1)
        .TextMatrix(.Rows - 1, 2) = mrcCancelCard.Fields(2)
        .TextMatrix(.Rows - 1, 3) = mrcCancelCard.Fields(3)
        .TextMatrix(.Rows - 1, 4) = mrcCancelCard.Fields(4)
        BackCardMoney = BackCardMoney + mrcCancelCard.Fields(2)
        mrcCancelCard.MoveNext
    Loop
    End With
    
  
    '臨時使用者
    If SSTab1.Tab = 3 Then
        With MSHFlexGrid4
            .CellAlignment = 4
            .Rows = 1
            .TextMatrix(0, 0) = "學號"
            .TextMatrix(0, 1) = "卡號"
            .TextMatrix(0, 2) = "日期"
            .TextMatrix(0, 3) = "時間"
        End With
    End If
    '選擇學生表中使用者名稱為combo,型別為臨時使用者,且未結賬的使用者
    txtSQL = "select * from student_Info where UserID='" & cmbOpUserID.Text & "' and type='臨時使用者 ' and Ischeck='未結賬 '"
    Set mrcStudent = ExecuteSQL(txtSQL, MsgText)
    
    With MSHFlexGrid4
    Do While Not mrcStudent.EOF
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = mrcStudent.Fields(1)
        .TextMatrix(.Rows - 1, 1) = mrcStudent.Fields(0)
        .TextMatrix(.Rows - 1, 2) = mrcStudent.Fields(12)
        .TextMatrix(.Rows - 1, 3) = mrcStudent.Fields(13)
    
        mrcStudent.MoveNext
    Loop
    End With