View RSS Feed

Development Team Blog

Visual Report Writer and The Web (X)

Rate this Entry
In this tenth blog about Visual Report Writer and the Web I want to take you to the next four reports that can be found at the Live Demo website (European Server, USA server) grouped under Wines. If this is the first blog you read I encourage you to read the nine other blogs (1: The Solution, 2: Invoices Report, 3: The Cleanup, 4: The CustomerList, 5: The Orderlist, 6: The Credit and Balances Overview), 7: Inventory Stock Levels), 8: Sick Leave) and 9: FileList (RDS)). Meanwhile we have been able to release the Alpha II version of Visual Report Writer 3.0 and the 2.1+ Library only setup. The latter one is needed to make the web reporting using the 17.1 DataFlex Web Framework easy and look like at the demo website.

The Reports
There are four in this part of the demo and this blog to be discussed. All reports were created to show special features such as the use of vertical lines (border) and dynamic and static images in a report. The wines listing by year and by type reports - can be viewed under Wines (JPEG) - are converted reports from the Wines example that is part of the Visual DataFlex product since 1995. The other two reports wines grouped by vintner and list of vintners with logo are more simple reports. The shipped wines example does not come with the images shown in this live example and to avoid potential copyright problems we bought the images for use in this example only (hence the watermark).

Integration
Four reports... so four report views? No, the reports are shown in two views and selectable via either a radiogroup or a drop-down control. Both views do not have selection criteria for the end-user so what is special on the integration? It is the fact that the output of the reports is not a PDF, not HTML but the pages are individual JPEG or GIF images grouped together via the same javascript control used to display the HTML based reports (Sick Leave and FileList).

The report selection is different too but it is not very complex.

Wines (JPEG)
This report view uses a radiogroup with two radio object for the report selection.
Code:
Object oChoicesContainer is a cWebCardContainer
    Set pbShowCaption to True
    Set pbShowBorder to True
    
    Object oReportChoiceGroup is a cWebCard
        Set psCaption to "Wines Report By"
        Set piColumnCount to 2

        Object oByTypeRadio is a cWebRadio
            Set psCaption to "By Type"
            Set psRadioValue to "T"
            Set piColumnSpan to 1
            Set piColumnIndex to 0
            Set pbServerOnSelect to True
            
            Procedure OnSelect
                Send ShowReport of oViewer
            End_Procedure
        End_Object
        
        Object oByYearRadio is a cWebRadio
            Set psCaption to "By Year"
            Set piColumnIndex to 1
            Set piColumnSpan to 1
            Set psRadioValue to "Y"
            Set pbServerOnSelect to True
            
            Procedure OnSelect
                Send ShowReport of oViewer
            End_Procedure
        End_Object
    End_Object
End_Object
The report output generation can be started via the "Run Report" tool-bar button or by clicking the other radio in the radiogroup. In both cases a message ShowReport is send to the viewer control.

The viewer control has a property set that tells it to request image download links. The viewer control can also (as seen before) request for a HTML stream (string). In this report view the message GenerateDownloadLinks is send to the report object. The message should return an array of strings holding download paths to the image files. For each of the report pages ONE image file is generated.

To generate a page as image a variable of the VRWImageExportOptions type needs to be created and the members have to be set. One of the members is the image type (TIFF, JPEG, GIF). Only TIFF output supports multi-page which means that the member bMultiPage must be set to false for this report. Instead the iPage member needs to be set to the page number that needs to be exported to the image file. Where the first two members can be set statically the page member will be set in a loop. Finally the code needs to construct a page name for each file and the code below uses the RandomHexUUID function (present in the 17.1 web framework and discussed in Create a New Universally Unique IDentifier (UUID) blog I wrote in 2011). The file will be created (like the PDF) in the Cache folder, sub-folder of the Reports folder.
Code:
Function GenerateDownloadLinks Returns String[]
    String sReportChoice sReportId sCacheFolder sHEXUUID sBaseName
    String[] sFileNames
    VRWImageExportOptions ImageExportOptions
    Integer iPages iPage iElement
    
    WebGet psValue of oByTypeRadio to sReportChoice
    Case Begin
        Case (sReportChoice = 'T')
            Set psReportName to "WineInventoryByType.vrw"
            Case Break
        Case (sReportChoice = 'Y')
            Set psReportName to "WineInventoryByYear.vrw"
            Case Break
    Case End

    Get OpenReport to sReportId
    If (sReportId <> "") Begin
        Get ReportPageCount to iPages
        Move (ResizeArray (sFileNames, iPages)) to sFileNames
        
        Get ReportsCacheFolder to sCacheFolder
        Get RandomHexUUID to sHEXUUID
        Move (sCacheFolder + sHEXUUID) to sBaseName
        
        Move C_VRWJPEG to ImageExportOptions.iImageType
        Move False to ImageExportOptions.bMultiPage
        
        For iPage from 1 to iPages
            Move iPage to ImageExportOptions.iPage
            Set pImageExportOptions to ImageExportOptions
            Move (Sformat ("%1-Page%2.jpg", sBaseName, iPage)) to sFileNames[iElement]
            Send ExportReport C_VRWImage sFileNames[iElement]
            Get DownloadURL of ghoWebResourceManager sFileNames[iElement] to sFileNames[iElement]
            Increment iElement
        Loop
        
        Send CloseReport sReportId
    End

    Function_Return sFileNames
End_Function
For each of the generated files a download link will be generated only available for the current session. The viewer will show the image in a page controlled way.

The path to the static image in the two report is passed to the report via a parameter. The image is stored in the same folder as the report. When this demo site gets updated to use Visual Report Writer 3.0 the following code can be removed as 3.0 supports embedded images.
Code:
Procedure OnInitializeReport
    String sReportLocation
    Integer iParameter
    
    Get psReportLocation to sReportLocation
    Get ParameterIdByName C_USEMAINVRWREPORTID 'ImagePath' to iParameter
    Set psParameterValue C_USEMAINVRWREPORTID iParameter to sReportLocation
End_Procedure
Wines (GIF)
The second report view in this example generates the output as individual GIF files. The report selection is done from a drop-down control. Where the report selection from a radio was code in a case structure in GenerateDownloadLinks the drop-down let me specifiy the report name as the data element of each combo-item.
Code:
Object oReportSelectorCombo is a cWebCombo
    Set psLabel to "Select Report"
    Set piColumnSpan to 8
    Set psEmptyItemDescription to "Select a Report"
    
    Procedure OnFill
        Send AddComboItem "Wine Bottles Grouped by Vintner.vrw" "Wine Bottles Grouped By Vintner"
        Send AddComboItem "List of Vintners With Logo.vrw" "List of Vintners With Logo"
    End_Procedure
End_Object
Where the many of the other report-views use a button in a tool-bar to start the report output this report-view uses a standard cWebButton object. The location is directly next the drop-down control. The message send by the button is the same as from the tool-bar button (ShowReport).

In the GenerateDownLoadLinks the report to be opened is retrieved from the drop-down control via the psValue property.
Code:
WebGet psValue of oReportSelectorCombo to sReportChoice
Set psReportName to sReportChoice
The GIF output reports print a logo file per vintner. The logos are present in a folder vintners inside the AppHtml folder. For each vintner two files are created, a larger and smaller one. The larger is used in the cWebView for the vintner table and the small one for the report. The folder where these images are stored in is passed via a parameter to the report. The code to set the parameter is as follows.
Code:
Procedure OnInitializeReport
    Handle hoWorkspace
    String sAppHtmlPaths sAppHtmlPath sFolder
    Integer iPaths iPath iParameter
    Boolean bIsFolder
    
    Get phoWorkspace of ghoApplication to hoWorkspace
    Get psAppHtmlPath of hoWorkspace to sAppHtmlPaths
    Get CountOfPaths of hoWorkspace sAppHtmlPaths to iPaths
    For iPath from 1 to iPaths
        Get PathAtIndex of hoWorkspace sAppHtmlPaths iPath to sAppHtmlPath
        If (Right (sAppHtmlPath, 1) <> SysConf (SYSCONF_DIR_SEPARATOR)) Begin
            Move (sAppHtmlPath - SysConf (SYSCONF_DIR_SEPARATOR)) to sAppHtmlPath
        End
        Move (sAppHtmlPath - "Vintners\") to sFolder
        Move (VRW_WinAPI_PathIsDirectory (AddressOf (sFolder))) to bIsFolder
        If (bIsFolder) Begin                
            Get ParameterIdByName C_USEMAINVRWREPORTID 'ImagePath' to iParameter
            Set psParameterValue C_USEMAINVRWREPORTID iParameter to sFolder
            Move iPaths to iPath
        End
    Loop
End_Procedure
This concludes the 10th blog about Visual Report Writer and the web. I hope I have been able to learn you a couple of more features available in Visual Report Writer and in the Visual DataFlex Web Framework.

Comments