Module ReportPreviewCR.rv

     1//*************************************************************************
     2//*                                                                       *
     3//*  Confidential Trade Secret.                                           *
     4//*  Copyright (c) 2011-2012 Mertech Data Systems Inc, Miami Florida      *
     5//*  All rights reserved.                                                 *
     6//*  DataFlex is a registered trademark of Data Access Corporation.       *
     7//*                                                                       *
     8//*************************************************************************
     9Use CheckForFlex2Crystal.dg
    10Use dfrptvw.pkg
    11Use Windows.pkg
    12Use DfLine.Pkg
    13Use File_dlg.Pkg
    14Use cFlex2Crystal.pkg
    15Use Flexml.pkg
    16
    17Activate_View Activate_oReportPreviewCR for oReportPreviewCR
    18Object oReportPreviewCR is a ReportView
    19
    20    // Handle to ActiveX previewer
    21    Property Handle phoActiveXReportViewer 0
    22    
    23    Set Border_Style to Border_Thick
    24    Set Label to "Flex2Crystal Reports Previewer"
    25    Set Location to 6 6
    26    Set Size to 244 389
    27    Set piMinSize to 244 389
    28    Set Maximize_Icon to True
    29
    30    Procedure Entering_Scope Returns Integer
    31        Integer iRetval
    32        Forward Send Entering_Scope to iRetval
    33        Set View_Mode       to ViewMode_Zoom
    34    End_Procedure
    35
    36    Object oCrystalActivexReportViewer is a cFlex2CrystalActiveXReportViewer
    37        Set Size to 190 375
    38        Set Location to 8 8
    39        Set peAnchors to anAll
    40
    41        Procedure OnCreate
    42            Forward Send OnCreate
    43            Set ComDisplayToolbar           to True
    44            Set ComDisplayTabs              to False
    45            Set ComDisplayGroupTree         to False
    46            Set ComEnableGroupTree          to False
    47            Set ComEnablePrintButton        to True
    48            Set ComEnableCloseButton        to False
    49            Set ComEnableRefreshButton      to False
    50            Set ComEnableExportButton       to True
    51            Set ComEnableSearchExpertButton to True
    52            Set ComEnableHelpButton         to False
    53            Set ComEnableZoomControl        to True
    54            Set ComEnableProgressControl    to True
    55            Set ComEnableSearchControl      to True
    56            Set ComEnableNavigationControls to True
    57            Set ComEnableDrillDown          to False
    58            Set ComEnableAnimationCtrl      to True
    59            Set ComEnableSelectExpertButton to False
    60            Set ComLaunchHTTPHyperlinksInNewBrowser to True
    61        End_Procedure // OnCreate
    62
    63    End_Object    // oCrystalActivexReportViewer1
    64
    65    Object oOkButton is a Button
    66        Set Label to "Run Report"
    67        Set Size to 14 51
    68        Set Location to 226 281
    69        Set peAnchors to anBottomRight
    70        Set Default_State to True
    71
    72        Procedure OnClick
    73            Boolean bReportOK bCrystalOK
    74            String sReportName
    75        
    76            Get CheckCrystalEnvironment of oCheckForFlex2Crystal to bCrystalOK
    77            If (bCrystalOK) Begin
    78                Set psReportName of oCrystalReport to "..\Data\Flex2Crystal.rpt"
    79                Send RunReport of oCrystalReport
    80            End
    81            Else Begin
    82                Send DisplayDialog of oCheckForFlex2Crystal
    83            End
    84        End_Procedure  // OnClick
    85
    86    End_Object    // oOkButton
    87
    88    Object oCancelButton is a Button
    89        Set Label to "Cancel"
    90        Set Location to 226 334
    91        Set peAnchors to anBottomRight
    92
    93        Procedure OnClick
    94            Send Request_Cancel
    95        End_Procedure // OnClick
    96
    97    End_Object    // oCancelButton
    98
    99    Object oCrystalReport is a cFlex2Crystal
   100        Set psReportName to ""
   101        Property Handle phoRoot
   102
   103        // procedure is called when report is sent to previewer
   104        Procedure OnDisplayReport Handle hoReport
   105            Forward Send OnDisplayReport hoReport
   106        
   107            // This assigns the preview object so we can use our custom previewer
   108            Send AssignPreviewObject of hoReport oReportPreviewCR
   109        
   110        End_Procedure // OnDisplayReport
   111        
   112        Procedure OnInitializeReport Handle hoReport
   113            Handle hoF2C
   114            Handle hoXML hoRoot hoData hoRec
   115            Boolean bOK
   116            Integer iLen i
   117            Variant [][4] vData
   118            String sLocation DirSep
   119
   120            Move (Sysconf(SYSCONF_DIR_SEPARATOR)) to DirSep
   121            Get Create u_cXMLDOMDocument to hoXML
   122               
   123            Get psDataPath of (phoWorkspace(ghoApplication)) to sLocation
   124            Set psDocumentName of hoXML to (sLocation-DirSep-"Flex2Crystal.xml")
   125            Set pbValidateOnParse of hoXML to True
   126                 
   127            Get LoadXMLDocument of hoXML to bOK
   128            Get DocumentElement of hoXML to hoRoot
   129            Set phoRoot to hoRoot
   130
   131            Get CreateCDO of hoReport "Flex2Crystal.ttx" to hoF2C
   132            If (hoF2C) Begin
   133                Get FindNodeList of hoRoot "CDOData/Rec" to hoData
   134                Get NodeListLength of hoData to iLen
   135                For i from 0 to (iLen-1)
   136                    Get CollectionNode of hoData i to hoRec
   137                    Get ChildNodeValue of hoRec "StringVal" to vData[i][0]
   138                    Get ChildNodeValue of hoRec "IntVal" to vData[i][1]
   139                    Get ChildNodeValue of hoRec "BoolVal" to vData[i][2]
   140                    Get ChildNodeValue of hoRec "Description" to vData[i][3]
   141                Loop
   142                Send AppendCDOData of hoReport hoF2C vData
   143                Send Destroy of hoData
   144            End
   145            
   146            Send AssignADODataSources of hoReport
   147            
   148            Send Destroy of hoRoot
   149            Send Destroy of hoXML
   150        End_Procedure
   151        
   152        Procedure LoadRowData Handle hoDataTable String sTable
   153            Handle hoRoot hoData hoRec hoRows hoRow
   154            Variant[5] vData
   155            Variant vRows vRow
   156            Integer iLen i
   157
   158            Get ComRows of hoDataTable to vRows
   159            Get Create U_cComF2CDataRowCollection to hoRows
   160            Set pvComObject of hoRows to vRows
   161            Get Create U_cComF2cDataRow to hoRow
   162            
   163            Get phoRoot to hoRoot
   164
   165            Get FindNodeList of hoRoot "ADOData/Rec" to hoData
   166            Get NodeListLength of hoData to iLen
   167            For i from 0 to (iLen-1)
   168                Get CollectionNode of hoData i to hoRec
   169                Get ChildNodeValue of hoRec "StringVal" to vData[0]
   170                Get ChildNodeValue of hoRec "IntVal" to vData[1]
   171                Get ChildNodeValue of hoRec "BoolVal" to vData[2]
   172                Get ChildNodeValue of hoRec "Description" to vData[3]
   173                Get ChildNodeValue of hoRec "DoubleCol" to vData[4]
   174                
   175                Move (Cast(vData[1], Integer)) to vData[1]
   176                Move (Cast(vData[2], Boolean)) to vData[2]
   177                Move (Cast(vData[4], Float)) to vData[4]
   178
   179                Get ComNewRow of hoDataTable to vRow
   180                Set pvComObject of hoRow to vRow
   181                Set ComItemArray of hoRow to vData
   182                Send ComAdd of hoRows vRow
   183            Loop
   184            
   185            Send Destroy of hoData
   186            Send Destroy of hoRow
   187            Send Destroy of hoRows
   188        End_Procedure
   189        
   190    End_Object    // oCrystalReport
   191        
   192    // set property to activeX preview object
   193    Set phoActiveXReportViewer to oCrystalActiveXReportViewer
   194
   195    // Message received by CrystalReport to display the report.
   196    Procedure DisplayReport Handle hoReport
   197        Handle hoViewer
   198        Variant vViewer
   199        Get phoActiveXReportViewer to hoViewer
   200        If (hoViewer) Begin
   201            Get  pvComObject     of hoReport to vViewer
   202            Set  ComReportSource of hoViewer to vViewer
   203            Send ComViewReport   of hoViewer
   204            Send ComZoom         of hoViewer 100
   205        End
   206    End_Procedure // DisplayReport
   207    
   208End_Object