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

機房收費系統之日結賬單

        日結賬單這個版塊的內容稍有點難,根據我自己的理解,實現這個功能主要突破兩個主要的內容:第一為報表,資料庫和vb之間的連線的問題;第二為結賬的問題。這兩個內容實現了,那麼,日結賬單的這個功能也就基本實現了。

         那麼?結賬是對什麼結賬呢?上期餘額,當日充值金額,當日消費金額,當日退還金額,本期金額。

         上期餘額:指昨天的本期金額

          當日充值金額:指今天充值的總帳

          當日消費餘額:指顧客上機消費的總額

          當日退還金額:指顧客退卡的錢數

          本期金額:今天的總賬(購卡金額+充值金額-退卡的錢)

上期餘額的計算:主要是連線兩次checkday_info表,第一次是將昨天的總賬檢索出來,第二次是將第一次檢索出來的總賬賦值,讓我們來看一下實現思路。

    Rem:定義checkday_info(用於彙總)
    Dim txtsqlcheck As String
    Dim msgtextcheck As String
    Dim mrccheck As ADODB.Recordset
    
    Rem:定義checkday_info(用於找出上期金額,即昨天總帳)
    Dim txtsqlcheck1 As String
    Dim msgtextcheck1 As String
    Dim mrccheck1 As ADODB.Recordset



    Rem:找出昨天總賬
    
    yesterday = DateAdd("d", "-1", Date)
    txtsqlcheck1 = "select * from checkday_info where date='" & yesterday & "'"
    Set mrccheck1 = executesql(txtsqlcheck1, msgtextcheck1)
    
    If mrccheck1.EOF = True Then
            yesterdayallcash = 0
    Else
            yesterdayallcash = mrccheck1!allcash
    End If
    
    

    Rem:將資料更新到checkday_info
    txtsqlcheck = "select * from checkday_info"
    Set mrccheck = executesql(txtsqlcheck, msgtextcheck)
    
    mrccheck.AddNew
    mrccheck!remaincash = Val(yesterdayallcash)
    mrccheck!rechargecash = Val(rechargecash)
    mrccheck!consumecash = Val(consumecash)
    mrccheck!cancelcash = Val(cancelcash)
    mrccheck!allcash = Val(allcash)
    mrccheck!Date = Format(Date, "yyyy-mm-dd")
    mrccheck.Update


思路:在檢索昨天的日期的時候,需要用到dateadd函式


當日充值金額的計算:

    Rem:計算充值的錢
    txtsqlrecharge = "select * from recharge_info where date='" & Format(Date, "yyyy-mm-dd") & "'"
    Set mrcrecharge = executesql(txtsqlrecharge, msgtextrecharge)
    
    If mrcrecharge.EOF = True Then
            rechargecash = 0
    Else
            Do While Not mrcrecharge.EOF
                    rechargecash = Val(rechargecash) + Val(mrcrecharge!addmoney)
                    mrcrecharge.MoveNext
            Loop
    End If

計算金額方法的延伸:

以上幾種金額的計算都可按照上述程式碼的思路設計,在這裡在介紹另一種計算金額程式碼的方法,主要是對SQL語言的運用和VB語言的結合:

Rem:計算購卡總額
    txtsqlstudent = "select sum(cash) as cardcash from student_info where date>='" &       DTPicker1.Value & "'" & "and date<='" & DTPicker2.Value & "'"
    Set mrcstudent = executesql(txtsqlstudent, msgtextstudent)
    
    If mrcstudent.EOF = True Then
            buycardcash = 0
    Else
            buycardcash = mrcstudent("cardcash").Value
    End If