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

機房收費系統——日、周結賬單

最後一個難點就是報表——日、周結賬單,這兩部分幾乎是相同的,只要把日結賬單做出來了,周結賬單也是so easy的,關鍵看你怎麼做了,接下來看看我做的,僅供參考:

日結:

Option Explicit

Dim WithEvents report As grproLibCtl.GridppReport  '例項化報表
Dim txtsql As String   '例項化報表

Private Sub cmdPrint_Click()
    report.[Print] (True)  '列印,因為報表物件的print方法名與vb內部定義有衝突所以要用中括號
End Sub

Private Sub Command1_Click()
    GRDisplayViewer1.Refresh
    
End Sub

Private Sub Command3_Click()
    report.PrintPreview (True)
End Sub

Private Sub Form_Load()
    Dim noda As String
    noda = Now
    
    Dim grprolibct1 As String
    
    txtsql = "select * from checkday_info where date= '" & Format(Date, "yyyy-mm-dd") & "'"
    Set report = New grproLibCtl.GridppReport   '例項化模板
    
    
    report.LoadFromFile (App.Path & "\daycheck.grf") '載入模板
    
    report.DetailGrid.Recordset.ConnectionString = connectstring()  '連線資料來源
    
    report.DetailGrid.Recordset.QuerySQL = txtsql '通過select查詢建立記錄集,只查詢

    report.ParameterByName("Parameter3").AsString = noda '顯示當前的日期

   report.ParameterByName("Parameter2").AsString = UserName '顯示編號
    
    GRDisplayViewer1.report = report '將資料賦給grd的report
    
    GRDisplayViewer1.Start '在報表中顯示

End Sub

周結:

Private Sub Command3_Click()

Dim lastrecharge As Integer '計算上期充值金額
Dim mrcconsume As ADODB.Recordset
Dim consume As Integer '計算本期消費金額
Dim mrccancel As ADODB.Recordset
Dim cancelcash As Integer '計算本期退卡金額
Dim allcash As Integer '計算本期充值卡餘額
Dim mrcall As ADODB.Recordset
Dim mrcrecharge As ADODB.Recordset '計算本期充值卡金額
Dim Recharge As Integer
Dim mrc As ADODB.Recordset

Dim mrcweek As ADODB.Recordset


    If DTPicker1.Value > DTPicker2.Value Then
        MsgBox "終止時間不能小於起始時間", 0 + 46, "警告"
    Exit Sub
    
    End If
    
    '判斷上期餘額的文字框是否為空
    If Text1.Text = "" Then
        txtsql = "select * from checkday_info where date between '" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'" & "and '" & Format$(DTPicker2.Value, "yyyy-mm-dd") & "'"
    Else
        txtsql = "select * from checkday_info where date between '" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'" & "and '" & Format$(DTPicker2.Value, "yyyy-mm-dd") & "'and remaincash= '" & Trim(Text1.Text) & "'"
        Set mrc = ExecuteSQL(txtsql, msgtext)
        If mrc.EOF And mrc.BOF Then
            MsgBox "沒有記錄"
        End If
        
    End If
    txtsql = "delete from checkweek_info "
    Set mrcweek = ExecuteSQL(txtsql, msgtext)
    
    '計算上期充值卡餘額(充值卡的錢-退卡的錢)
    txtsql = "select  sum(remaincash) from checkday_info where date <'" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'"
    
    Set mrcrecharge = ExecuteSQL(txtsql, msgtext)
    
    If IsNull(mrcrecharge.fields(0)) = True Then
        lastrecharge = "0"
    Else
        lastrecharge = Trim(mrcrecharge.fields(0))
    End If
    
    '計算本期消費金額
     txtsql = "select sum(consumecash) from checkday_info where date between'" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'" & "and'" & Format$(DTPicker2.Value, "yyyy-mm-dd") & "'"
    Set mrcconsume = ExecuteSQL(txtsql, msgtext)
    
    If IsNull(mrcconsume.fields(0)) = True Then
        consume = "0"
    Else
        consume = Trim(mrcconsume.fields(0))
    End If
    
    '計算本期退卡金額
    txtsql = "select sum(cancelcash) from checkday_info where date between'" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'" & "and'" & Format$(DTPicker2.Value, "yyyy-mm-dd") & "'"
    Set mrccancel = ExecuteSQL(txtsql, msgtext)
    
    If IsNull(mrccancel.fields(0)) = True Then
        cancelcash = "0"
    Else
        cancelcash = Trim(mrccancel.fields(0))
    End If
    
    '計算本期充值卡餘額
    txtsql = "select sum(allcash) from checkday_info where  date between'" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'" & "and'" & Format$(DTPicker2.Value, "yyyy-mm-dd") & "'"
    Set mrcall = ExecuteSQL(txtsql, msgtext)
    If IsNull(mrcall.fields(0)) = True Then
        allcash = "0"
    Else
        allcash = Trim(mrcall.fields(0))
    End If
    
    '計算本期充值金額
    txtsql = "select sum(rechargecash) from checkday_info where date between'" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'" & "and'" & Format$(DTPicker2.Value, "yyyy-mm-dd") & "'"
    Set mrcrecharge = ExecuteSQL(txtsql, msgtext)
    
    If IsNull(mrcrecharge.fields(0)) = True Then
        Recharge = "0"
    Else
        Recharge = Trim(mrcrecharge.fields(0))
    End If
    
    '將資料更新到checkweek表中
    txtsql = "select * from checkweek_info"
    Set mrc = ExecuteSQL(txtsql, msgtext)
    
    mrc.AddNew
    mrc.fields(0) = Val(lastrecharge)
    mrc.fields(1) = Val(Recharge)
    mrc.fields(2) = Val(consume)
    mrc.fields(3) = Val(cancelcash)
    mrc.fields(4) = Val(allcash)
    mrc.fields(5) = Date
    mrc.Update
    
    
    
    GRDisplayViewer1.Refresh
    
    report.DetailGrid.Recordset.QuerySQL = "select * from checkweek_info where date between '" & Format$(DTPicker1.Value, "yyyy-mm-dd") & "'" & "and'" & Format$(DTPicker2.Value, "yyyy-mm-dd") & "'"

    '顯示管理員編號
    report.ParameterByName("Parameter3").Value = UserName
    
        '獲取開始和結束時間
    report.ParameterByName("Parameter1").Value = Format$(DTPicker1.Value, "yyyy-mm-dd")
    report.ParameterByName("Parameter2").Value = Format$(DTPicker2.Value, "yyyy-mm-dd")

    
    
    
End Sub

Private Sub Form_Load()
    '連線資料庫
    txtsql = "select * from checkday_info where date= '" & Format(Date, "yyyy-mm-dd") & "'"
    Set report = New grproLibCtl.GridppReport  '例項化模板
    
    report.LoadFromFile (App.Path & "\weekcheck.grf") '載入模板
    report.DetailGrid.Recordset.ConnectionString = connectstring()  '連線資料來源
    report.DetailGrid.Recordset.QuerySQL = txtsql   '通過select查詢建立記錄集
    
    report.ParameterByName("Parameter3").AsString = UserName
    report.ParameterByName("Parameter3").Value = UserName '顯示管理員編號
    
    GRDisplayViewer1.report = report '將資料賦給GRD的report
    GRDisplayViewer1.Start  '在報表中顯示

End Sub