⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 report.cls

📁 超经典的打印预览动态库源码 版权: 本资源版权归作者所有 说明: 本资源由源码天空搜集,仅提供学习参考
💻 CLS
📖 第 1 页 / 共 2 页
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Report"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"

Option Explicit
'**************************************************************
'*类模块名称:Report
'*类模块说明:报表类
'*
'*备注:
'*
'*作者:chlf78
'*日期:2002-03-27 15:09:18
'***************************************************************

Private Const ModalName = "Report"


'*开放对象
Public ColHeader            As clsColHeader             '*列头
Public WithEvents Content   As clsContent               '*正文
Attribute Content.VB_VarHelpID = -1

Public Event InitProgress(Value As Integer)             '*初始化的处理进度
Public Event PrintProgress(Value As Integer)            '*打印输出时的处理进度

Public Header               As clsCollection            '*表头
Public Footer               As clsCollection            '*表尾
Public Title                As clsCollection            '*页头
Public Tail                 As clsCollection            '*页尾
Public LeftSection          As clsCollection            '*左部标签集合
Public RightSection         As clsCollection            '*右部标签集合

'*打印机的设置
Private m_PrinterWidth      As Single
Private m_PrinterHeight     As Single
Private m_PrinterOrient     As typeOrient

'*页边距的设置
Private m_LeftMargin        As Single
Private m_RightMargin       As Single
Private m_TopMargin         As Single
Private m_BottomMargin      As Single


'*当前使用的模板文件
Private m_Templatefile      As String


'*正文打印的对齐方式
Private m_Align             As typeAlign


'*是否有数据
Private m_HaveData          As Boolean

Public Property Get Align() As typeAlign
'*得到正文打印的对齐方式
    Align = m_Align
End Property

Public Property Let Align(vData As typeAlign)
'*设置正文打印的对齐方式
    m_Align = vData
End Property


Friend Property Get HaveData() As Boolean
'*是否有数据
    HaveData = m_HaveData
End Property


'**************************************************************
'*名称:SetPrinter
'*功能:设置打印机
'*传入参数:
'*      width       --宽度(如果设为0,则认为读取系统默认宽度)
'*      height      --高度(如果设为0,则认为读取系统默认高度)
'*      orient      --方向
'*返回参数:
'*      是否设置成功
'*作者:chlf78
'*日期:2002-03-19 23:10:00
'***************************************************************
Public Function SetPrinter(width As Single, _
                           height As Single, _
                           orient As typeOrient) _
    As Boolean
                         
    '*如果数值小于0,则为非法
    If width < 0 Or height < 0 Then
        SetPrinter = False
        Exit Function
    End If
    '*设置

        m_PrinterWidth = width
        m_PrinterHeight = height
        m_PrinterOrient = orient

    '*返回成功
    SetPrinter = True
    
End Function

Public Property Get width() As Single
'*得到报表的页宽度
    width = m_PrinterWidth
End Property

Public Property Get height() As Single
'*得到报表的页高度
    height = m_PrinterHeight
End Property

Public Property Get orient() As typeOrient
'*得到报表的打印方向
    orient = m_PrinterOrient
End Property

'**************************************************************
'*名称:SetMargin
'*功能:设置页边距
'*传入参数:
'*      left        --左边距
'*      right       --右边距
'*      top         --上边距
'*      bottom      --下边距
'*返回参数:
'*
'*作者:chlf78
'*日期:2002-03-20 15:37:22
'***************************************************************
Public Function SetMargin(left As Single, _
                          Top As Single, _
                          Right As Single, _
                          Bottom As Single) _
    As Boolean
    
    '*过滤非法值
    If left < 0 Or Top < 0 Or Right < 0 Or Bottom < 0 Then
        SetMargin = False
        Exit Function
    End If
    
    If left + Right >= m_PrinterWidth _
        Or Top + Bottom >= m_PrinterHeight Then
        
        SetMargin = False
        Exit Function
    End If

    '*设置

        m_LeftMargin = left
        m_RightMargin = Right
        m_TopMargin = Top
        m_BottomMargin = Bottom

    SetMargin = True        '*返回成功值
End Function

Public Property Get LeftMargin() As Single
'*得到报表的页高度
    LeftMargin = m_LeftMargin
End Property

Public Property Get RightMargin() As Single
'*得到报表的页高度
    RightMargin = m_RightMargin
End Property

Public Property Get TopMargin() As Single
'*得到报表的页高度
    TopMargin = m_TopMargin
End Property

Public Property Get BottomMargin() As Single
'*得到报表的页高度
    BottomMargin = m_BottomMargin
End Property

'**************************************************************
'*名称:CalPage
'*功能:计算页
'*传入参数:
'*
'*作者:chlf78
'*日期:2002-04-05 14:25:56
'***************************************************************
Public Sub CalPage()

Dim pageheight          As Single       '*可用页高
Dim firstPageHeight     As Single       '*第一页的可用页高(减去表头)
Dim lastPageHeight      As Single       '*最后一页的可用页高(减去表尾)

Dim pagewidth           As Single       '*可用页宽

    If Not m_HaveData Then
        Exit Sub
    End If
    
    pagewidth = m_PrinterWidth - (m_LeftMargin + m_RightMargin) _
                - LeftSection.GetWidth - RightSection.GetWidth
    
    '*列头分页
    ColHeader.Merge pagewidth
    
    '*计算正文可用的高度
    pageheight = m_PrinterHeight _
                - (m_TopMargin + m_BottomMargin) _
                - ColHeader.GetHeight _
                - Title.GetHeight - Tail.GetHeight

    firstPageHeight = pageheight - Header.GetHeight
    lastPageHeight = pageheight - Footer.GetHeight

    '*正文分页
    Content.Merge pagewidth, pageheight, firstPageHeight, lastPageHeight
    
End Sub

Public Property Get pages() As Integer
'*得到总页数
    pages = Content.GetPages
End Property

Public Property Get cutpages() As Integer
    cutpages = ColHeader.cutpages
End Property


'**************************************************************
'*名称:AttachFlexGrid
'*功能:绑定到FlexGrid
'*传入参数:
'*
'*返回参数:
'*
'*作者:chlf78
'*日期:2002-04-09 19:59:40
'***************************************************************
Public Function AttachFlexGrid(flexgrid As Object) As Boolean

    AttachFlexGrid = funAttachFlexGrid(Me, flexgrid)
    m_HaveData = AttachFlexGrid
    
End Function


'**************************************************************
'*名称:AttachListView
'*功能:绑定到listview
'*传入参数:
'*
'*返回参数:
'*
'*作者:chlf78
'*日期:2002-04-09 19:59:40
'***************************************************************
Public Function AttachListView(listview As Object) As Boolean

    AttachListView = funAttachListView(Me, listview)
    m_HaveData = AttachListView
    
End Function

'**************************************************************
'*名称:Preview
'*功能:预览
'*传入参数:
'*
'*作者:chlf78
'*日期:2002-04-05 19:38:22
'***************************************************************
Public Sub Preview()

    If Not m_HaveData Then
        MsgBox "没有数据,无法预览!", vbInformation + vbOKOnly
        Exit Sub
    End If
    
Dim fPreview        As New frmPreview

    Set fPreview.rpt = Me
    
    fPreview.Show
    
    Set fPreview = Nothing
    
End Sub


'**************************************************************
'*名称:Export2Jpg
'*功能:输出到jpg文件
'*传入参数:
'*      filepath        --文件夹位置
'*      pageFrom        --页起始
'*      cutPageFrom     --分页起始
'*      pageTo          --页终止
'*      cutPageTo       --分页终止
'*      sRate           --缩放比例
'*      isBmp           --输出BMP还是JPG
'*      preFix          --输出文件名的前缀
'*返回参数:
'*
'*作者:chlf78
'*日期:2002-04-10 11:21:12
'***************************************************************
Public Function Export2Jpg(filepath As String, _
                           pic As Object, _
                           pageFrom As Integer, cutPageFrom As Integer, _
                           pageTo As Integer, cutPageTo As Integer, _
                           sRate As Single, _
                           Optional isBmp As Boolean = False, _
                           Optional preFix As String = "") _
    As Boolean
    '*如果没有数据,不输出
    If Not m_HaveData Then
        Export2Jpg = False
        Exit Function
    End If
    '*拦截错误数据
    If pageFrom > pageTo Or pageFrom < 1 Or _
        pageTo > Me.pages Or sRate > 5 _
        Or sRate < 0.1 Then
        Export2Jpg = False
        Exit Function
    End If

    Export2Jpg = funExport2Jpg(Me, filepath, pic, pageFrom, cutPageFrom, _
                               pageTo, cutPageTo, sRate, isBmp, preFix)

End Function


'**************************************************************
'*名称:Export2Prn
'*功能:
'*传入参数:
'*
'*返回参数:
'*
'*作者:chlf78

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -