VB机房收费系统09——日结账单和周结账单

前端之家收集整理的这篇文章主要介绍了VB机房收费系统09——日结账单和周结账单前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前言

这是我整个机房项目中最后一个难点,这两个账单我卡了3天,敲完了后,我把收获分享在这里,希望对大家有所帮助。


正文

这窗体不是敲出来,是调用显示出来的!

这里我们就用到了报表,报表下个生成器然后自己画也可以,直接选择给的机房素材也可以。
以我亲身经历来说,画报表没有调试报表代码难,调试报表代码没有找到报表控件难!


画报表

画报表参考博客:http://blog.csdn.net/zhoukun1008/article/details/38518297


调试报表代码

报表代码有点类似机房中用到的“导出EXECEL”代码,是万能的。

日结账单全代码
Option Explicit
  '定义报表对象
   Dim Report As grproLibCtl.GridppReport
  
 Private Sub Form_Load()
      Dim Strsql As String
      Dim strMsg As String
       
     '创建报表对象
      Strsql = "select * from CheckDay_Info where date= '" & Date & "'  "
        
      '实例化报表
      Set Report = New grproLibCtl.GridppReport
       
      '载入报表模板文件
      Report.LoadFromFile (App.Path & "\daycheck.grf")
       
      '数据源连接
      Report.DetailGrid.Recordset.ConnectionString = connectstring
       
      '通过SELECT查询创建记录集
      Report.DetailGrid.Recordset.Querysql = Strsql
           
      '显示报表中的内容
      GRDisplayViewer1.Report = Report
      GRDisplayViewer1.Start
       
 End Sub

Private Sub cmddaylist_Click()
'日结账单刷新
     
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset
    
    txtsql = "select * from checkday_Info "
    Set mrc = Executesql(txtsql,msgtext)
         
    '刷新
    Report.DetailGrid.Recordset.Querysql = "select * from CheckDay_Info where date= '" & Date & "'  "
    GRDisplayViewer1.Refresh
End Sub

Private Sub cmdprintpreview_Click()
'打印预览
      Report.PrintPreview (True)
 End Sub
 
 Private Sub cmdprint_Click()
 '打印,因为报表对象的print方法名与vb的内部定义方法有冲突所以要用中括号
 
     Report.[Print] (True)
End Sub



周结账单全部代码

Dim WithEvents Report As grproLibCtl.GridppReport



Private Sub cmdweeklist_Click()
'账单刷新
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset
    Dim mrc1 As ADODB.Recordset
    Dim mrc2 As ADODB.Recordset
    Dim mrc3 As ADODB.Recordset
    Dim mrc4 As ADODB.Recordset
    Dim mrc5 As ADODB.Recordset
    Dim RemainCash As Integer
    Dim RechargeCash As Integer
    Dim ConsumeCash As Integer
    Dim CancelCash As Integer
    Dim AllCash As Integer
    
    If DTPicker1.Value > DTPicker2.Value Then
        MsgBox "终止日期不能小于起始日期",48,"提示"
        Exit Sub
    Else
    
        If DTPicker1.Value And DTPicker2.Value > Date Then
            MsgBox "小主,日子还没到呢","提示"
            DTPicker1.Value = Date
            DTPicker2.Value = Date
            Exit Sub
        Else
        
            txtsql = "select * from checkday_info where date between '" & DTPicker1.Value & "' and '" & DTPicker2.Value & "'"
            Set mrc = Executesql(txtsql,msgtext)
            
            If mrc.EOF Then
                MsgBox "该时间段没有数据!","提示"
                
                Exit Sub
            Else
                
                '删除check week表中的记
                
                txtsql = "delete from checkweek_Info"
                
                Set mrc1 = Executesql(txtsql,msgtext)
                
                '计算上次充值卡金额
                
                    mrc.MoveLast
                    RemainCash = mrc.Fields(0)
                
                '计算总充值金额mrc2
                    
    
                    txtsql = "select sum(rechargecash) from checkday_info where date between '" & DTPicker1.Value & " ' and '" & DTPicker2.Value & "'"
                    Set mrc2 = Executesql(txtsql,msgtext)
                    
                    If IsNull(mrc2.Fields(0)) = True Then
                        RechargeCash = 0
                    Else
                        RechargeCash = Trim(mrc2.Fields(0))
                    End If
                    
            
                
                '计算总消费金额
                
                    txtsql = "select sum(consumecash) from checkday_info where date between '" & DTPicker1.Value & "' and '" & DTPicker2.Value & "'"
                    Set mrc3 = Executesql(txtsql,msgtext)
                    
                        If IsNull(mrc3.Fields(0)) = True Then
                            ConsumeCash = 0
                        Else
                            ConsumeCash = Trim(mrc3.Fields(0))
                        End If
                            
                '计算总退卡金额
                
                    txtsql = "select sum(cancelcash) from checkday_info where date between '" & DTPicker1.Value & "' and '" & DTPicker1.Value & "'"
                    Set mrc4 = Executesql(txtsql,msgtext)
                    
                        If IsNull(mrc4.Fields(0)) = True Then
                            CancelCash = 0
                        Else
                            CancelCash = Trim(mrc4.Fields(0))
                        End If
                        
                '计算本期充值卡金额
                
                    mrc.MoveLast
                    AllCash = mrc.Fields(4)
                    
                '添加到check week表中
                
                    txtsql = "select * from checkweek_info"
                    Set mrc1 = Executesql(txtsql,msgtext)
                    mrc1.AddNew
                        mrc1.Fields(0) = RemainCash
                        mrc1.Fields(1) = RechargeCash
                        mrc1.Fields(2) = ConsumeCash
                        mrc1.Fields(3) = CancelCash
                        mrc1.Fields(4) = AllCash
                        mrc1.Fields(5) = Date
                        
                    mrc1.Update
                    
                '显示报表中的内容
                    
                    Report.DetailGrid.Recordset.Querysql = txtsql
                    GRDisplayViewer1.Refresh
                    
                '给报表的日期赋值
    
                    Report.ParameterByName("BeginDate").Value = Format$(DTPicker1.Value,"yyyy-mm-dd")
                    Report.ParameterByName("EndDate").Value = Format$(DTPicker2.Value,"yyyy-mm-dd")
                    Report.ParameterByName("XX").Value = UserName
                    
            End If
        End If
    End If
End Sub

Private Sub cmdprint_Click()
    Report.[Print] (True)
    
End Sub

Private Sub cmdprintpreview_Click()
    Report.PrintPreview (True)
    
End Sub

Private Sub Form_Load()
    txtsql = "select * from checkweek_info"
    
    
    '创建报表对象
    
    Set Report = New grproLibCtl.GridppReport
    
    '放入做好的报表文件
    
    Report.LoadFromFile (App.Path & "\weekcheck.grf")
    
    '连接数据源
    
    Report.DetailGrid.Recordset.ConnectionString = "FileDSN=charge.dsn;UID=sa;PWD=123456"
    Report.DetailGrid.Recordset.Querysql = txtsql
    
    
    '显示报表的内容
    GRDisplayViewer1.Report = Report
    GRDisplayViewer1.Start
    
    '给报表的日期赋值
    
    Report.ParameterByName("BeginDate").Value = Format$(DTPicker1.Value,"yyyy-mm-dd")
    Report.ParameterByName("EndDate").Value = Format$(DTPicker2.Value,"yyyy-mm-dd")
    Report.ParameterByName("XX").Value = UserName
End Sub

VB报表控件

数据库原理一样,我们需要把报表程序与VB程序连接在一起。
这就是Displayviewer控件

我们翻阅很多的博客中都写到它是下载报表软件后,引用,部件选择两个红框后出来的

但这两个红框在我这里根本就不显示
就是因为这个原因,我查了很多报表博客,请了很多小伙伴帮忙都没弄出来,一弄就是3天......



问题的解决:在晓鸿大神的帮助下,找到了原因。大家还记得配置机房时需要注册的3个控件吗?

就是这3个小伙伴!我的电脑忘记什么原因,这3个注册的控件失效了。重新注册一遍之后,报表控件显示,账单出现。

报表dll,不会忘了......
原文链接:https://www.f2er.com/vb/256203.html

猜你在找的VB相关文章