Module ReportPreviewCR.rv

     1Use DfRptVw.pkg
     2Use Crystal\CheckForCrystal.dg
     3Use dfrptvw.pkg
     4Use Windows.pkg
     5Use DfLine.Pkg
     6Use cCrystalActiveXReportViewer.pkg
     7Use File_dlg.Pkg
     8Use cCrystal.pkg
     9
    10DEFERRED_VIEW Activate_oReportPreviewCR FOR ;
    11;
    12Object oReportPreviewCR is a ReportView
    13
    14    // Handle to ActiveX previewer
    15    Property Handle phoActiveXReportViewer 0
    16    
    17    Set Border_Style to Border_Thick
    18    Set Label to "Crystal Reports Previewer"
    19    Set Location to 6 6
    20    Set Size to 244 389
    21    Set piMinSize to 244 389
    22
    23    Object oReportForm is a Form
    24        Set Label to "Crystal Report:"
    25        Set Size to 13 320
    26        Set Location to 10 61
    27        Set peAnchors to anTopLeftRight
    28        Set Label_Col_Offset to 2
    29        Set Label_Justification_Mode to jMode_Right
    30        Set Prompt_Button_Mode to pb_PromptOn
    31
    32        // Send when the prompt key is pressed, start selection list
    33        Procedure Prompt
    34            Integer iSelected iNumPaths
    35            String  sSelectedFile
    36            String  sDataDir
    37        
    38            Get psDataPath of (phoWorkspace(ghoApplication)) to sDataDir
    39            Get CountOfPaths of (phoWorkspace(ghoApplication)) sDataDir to iNumPaths
    40            If (iNumPaths > 1) Get PathAtIndex of (phoWorkspace(ghoApplication)) sDataDir 1 to sDataDir
    41            Set Initial_Folder of oNewDialog to sDataDir
    42        
    43            // Start the save as dialog
    44            Get Show_Dialog of oNewDialog to iSelected
    45            If iSelected Begin
    46                Get File_Name of oNewDialog to sSelectedFile
    47                Set Value to sSelectedFile
    48            End
    49        
    50        End_Procedure  // Prompt
    51
    52    End_Object    // oReportForm
    53
    54    Object oLineControl1 is a LineControl
    55        Set Size to 2 376
    56        Set Location to 28 8
    57        Set peAnchors to anTopLeftRight
    58    End_Object    // oLineControl1
    59
    60    Object oCrystalActivexReportViewer1 is a cCrystalActiveXReportViewer
    61        Set Size to 185 375
    62        Set Location to 34 8
    63        Set peAnchors to anAll
    64
    65        Procedure OnCreate
    66            Forward Send OnCreate
    67            Set ComDisplayToolbar           to True
    68            Set ComDisplayTabs              to False
    69            Set ComDisplayGroupTree         to False
    70            Set ComEnableGroupTree          to False
    71            Set ComEnablePrintButton        to True
    72            Set ComEnableCloseButton        to False
    73            Set ComEnableRefreshButton      to False
    74            Set ComEnableExportButton       to True
    75            Set ComEnableSearchExpertButton to True
    76            Set ComEnableHelpButton         to False
    77            Set ComEnableZoomControl        to True
    78            Set ComEnableProgressControl    to True
    79            Set ComEnableSearchControl      to True
    80            Set ComEnableNavigationControls to True
    81            Set ComEnableDrillDown          to False
    82            Set ComEnableAnimationCtrl      to True
    83            Set ComEnableSelectExpertButton to False
    84            Set ComLaunchHTTPHyperlinksInNewBrowser to True
    85        End_Procedure // OnCreate
    86
    87    End_Object    // oCrystalActivexReportViewer1
    88
    89    Object oNewDialog is a OpenDialog
    90        Set Dialog_Caption to "Customer report export to disk, give file name"
    91        Set Filter_String to "Crystal Report (*.rpt)|*.rpt|All Files|*.*"
    92        Set HideReadOnly_State to True
    93    End_Object    // oNewDialog
    94
    95    Object oOkButton is a Button
    96        Set Label to "Run Report"
    97        Set Size to 14 51
    98        Set Location to 226 281
    99        Set peAnchors to anBottomRight
   100        Set Default_State to True
   101
   102        Procedure OnClick
   103            Boolean bReportOK bCrystalOK
   104            String sReportName
   105        
   106            Get Value of oReportForm to sReportName
   107        
   108            // Check if the report name was specified and report actually exists
   109            Get ValidateReportName sReportName to bReportOK
   110            If (bReportOK) Begin
   111                Get CheckCrystalEnvironment of oCheckForCrystal to bCrystalOK
   112                If (bCrystalOK) Begin
   113                    Set psReportName of oCrystalReport1 to sReportName
   114                    Send RunReport of oCrystalReport1
   115                End
   116                Else Begin
   117                    Send DisplayDialog of oCheckForCrystal
   118                End
   119            End
   120            Else Begin
   121                Send activate of oReportForm
   122            End
   123        
   124        End_Procedure  // OnClick
   125
   126    End_Object    // oOkButton
   127
   128    Object oCancelButton is a Button
   129        Set Label to "Cancel"
   130        Set Location to 226 334
   131        Set peAnchors to anBottomRight
   132
   133        Procedure OnClick
   134            Send Request_Cancel
   135        End_Procedure // OnClick
   136
   137    End_Object    // oCancelButton
   138
   139    Object oCrystalReport1 is a cCrystal
   140        Set psReportName to ""
   141
   142        // procedure is called when report is sent to previewer
   143        Procedure OnDisplayReport Handle hoReport
   144            Forward Send OnDisplayReport hoReport
   145        
   146            // This assigns the preview object so we can use our custom previewer
   147            Send AssignPreviewObject of hoReport oReportPreviewCR
   148        
   149        End_Procedure // OnDisplayReport
   150        
   151    End_Object    // oCrystalReport1
   152        
   153    // set property to activeX preview object
   154    Set phoActiveXReportViewer to oCrystalActiveXReportViewer1
   155    
   156    // Message received by CrystalReport to display the report.
   157    Procedure DisplayReport Handle hoReport
   158        Handle hoViewer
   159        Variant vViewer
   160        Get phoActiveXReportViewer to hoViewer
   161        If (hoViewer) Begin
   162            Get  pvComObject     of hoReport to vViewer
   163            Set  ComReportSource of hoViewer to vViewer
   164            Send ComViewReport   of hoViewer
   165            Send ComZoom         of hoViewer 100
   166        End
   167    End_Procedure // DisplayReport
   168    
   169    Function ReportExists String sRPTName Returns Boolean
   170        Boolean bReportExists
   171    
   172        // Check if the report actually exists
   173        File_Exist sRPTName bReportExists
   174    
   175        Function_Return bReportExists
   176    End_Function
   177    
   178    Function ValidateReportName String sReportName Returns Boolean
   179        Boolean bReportNameOK
   180    
   181        Move False to bReportNameOK
   182    
   183        If (sReportName="") Begin
   184            Send Info_Box "Select or specify a report." "Report Information"
   185        End
   186        Else Begin
   187            Get ReportExists sReportName to bReportNameOK
   188            If (not(bReportNameOK)) Begin
   189                Send Info_Box ("The report file " + sReportName + " does not exist. Select or specify another one.") "Report Information"
   190            End
   191        End
   192    
   193        Function_Return bReportNameOK
   194    End_Function
   195    
   196CD_End_Object    // oReportPreviewCR
   197