Module cHtmlreport.pkg

     1//****************************************************************************//
     2//                                                                            //
     3// $File name  : cHtmlReport.PKG                                              //
     4// $File title : cHtmlReport class  (private class)                           //
     5// $Author     : John Tuohy                                                   //
     6//                                                                            //
     7// Confidential Trade Secret.                                                 //
     8// Copyright 1999 Data Access Corporation, Miami FL, USA                      //
     9// All Rights reserved                                                        //
    10// DataFlex is a registered trademark of Data Access Corporation.             //
    11//                                                                            //
    12//                                                                            //
    13// $Rev History                                                               //
    14//   8/12/98 jjt - created                                                    //
    15//                                                                            //
    16//****************************************************************************//
    17
    18
    19//
    20//  Report_DS
    21//    BasicReport
    22//       cHTMLReport     - generic html output report
    23//
    24
    25Use cBasicReport.pkg
    26Use HtmlEncode.pkg // loads global htmlEncode function
    27Use HtmlFormat_mixin.pkg     // HTML helper mixin and functions
    28Use HtmlWrite_mixin.pkg
    29
    30{ ClassLibrary=WebApp ClassType=Abstract }
    31{ HelpTopic=cHtmlReport }
    32Class cHtmlReport is a cBasicReport
    33
    34    Procedure Construct_Object
    35        Forward send construct_object
    36
    37        Object oRptTotal is an Array
    38        End_Object
    39
    40        Set Status_Panel_State to False
    41        Set Page_Feed   to -2   // No FormFeed
    42        Set Page_End    to 0
    43
    44        { Visibility=Private }
    45        Property integer phOutputDevice     0
    46
    47        { DesignTime=False }
    48        Property integer piConstrainFile    0
    49        { DesignTime=False }
    50        Property rowId   priConstrainRowId
    51        { Obsolete=True }
    52        { DesignTime=False }
    53        Property integer piConstrainRecord  0
    54
    55    End_Procedure
    56
    57    { Visibility=Private }
    58    Procedure Constrain
    59        integer iFile iRec
    60        RowId riId
    61        Forward Send Constrain
    62        Get piConstrainFile    to iFile
    63        Get priConstrainRowId  to riId
    64        Get piConstrainRecord  to iRec
    65        // we check for both rowId and for obsolete record id
    66        If (iFile>0 AND ( Not(IsNullRowId(riId)) or (iRec>0) ) ) ;
    67            CONSTRAIN (Main_File(Self)) RELATES TO iFile
    68    End_Procedure
    69
    70    { Visibility=Private }
    71    Procedure Find_Init
    72        integer iFile iRec
    73        handle  hSrvr hPrntSrvr
    74        RowId   riId
    75        Boolean bNoFindConstrain bDoConstrain bHasRowId bFound
    76        Get Server to hSrvr
    77        If (pbChildReport(self)) Begin
    78            If hSrvr Begin
    79                Delegate Get Server to hPrntSrvr // server of outer report
    80                If (hPrntSrvr=hSrvr) ;   // not allowed!
    81                    Error DFERR_PROGRAM C_$ChildAndParentHaveSameServer
    82                Get Main_File of hPrntSrvr to iFile
    83            end
    84            Else ;
    85                Delegate Get Main_file to iFile
    86            Move true to bNoFindConstrain
    87        end
    88        else begin
    89            Get piConstrainFile   to iFile
    90            Get priConstrainRowId to riId
    91            Move (not(isNullRowId(riId))) to bHasRowId
    92
    93            Get piConstrainRecord to iRec
    94            // compatibility check
    95            If ( iRec and not(IsRecnumTable(self,iFile)) ) begin
    96                error DFErr_Program "Cannot use piConstrainedRecord with this table"
    97                Move 0 to iRec
    98            end
    99        end
   100
   101        If (iFile>0) Begin
   102            if hSrvr Begin
   103                Move (bNoFindConstrain or bHasRowId or iRec>0) to bDoConstrain
   104                Set constrain_file of hSrvr to (If(bDoConstrain, iFile, 0))
   105                If bHasRowId begin
   106                    Send FindByRowId of hSrvr iFile riId
   107                end
   108                else if (iRec>0) begin
   109                    send Find_by_recnum of hSrvr iFile iRec // compatibility with old stuff
   110                end
   111                // note: you may not find anything..that's ok
   112            End
   113            else Begin
   114                If bHasRowId begin
   115                    Move (FindByRowId(iFile,riId)) to bFound
   116                end
   117                else if (iRec>0) begin
   118                   Set_Field_Value iFile 0 to iRec   // compatibility w/ recnum
   119                   vFind iFile 0 eq
   120                end
   121            end
   122        end
   123        Forward Send Find_Init
   124    End_Procedure
   125
   126    { NoDoc=True }
   127    Function DoRunReport Returns Integer
   128        Integer iStat hDD iOldConstrainFile iConstrainFile
   129
   130        If not (pbChildReport(self)) ;
   131            Send ClearAllSubTotals // clear all accumulators
   132        Else ;
   133            Set phOutputDevice to (phOutputDevice(parent(self)))
   134
   135        Get Server to hDD
   136        If hDD begin
   137            get Constrain_file of hDD to iOldConstrainFile
   138            Forward Get DoRunReport to iStat
   139            // after running report, restore previous relates to constraint
   140            Get constrain_file of hDD to iConstrainFile
   141            If (iOldConstrainFile<>iConstrainFile) begin
   142                Set Constrain_file of hDD to iOldConstrainFile
   143                Send Rebuild_Constraints of hDD
   144            end
   145        end
   146        else Forward Get DoRunReport to iStat
   147        function_Return iStat
   148    End_Function
   149
   150
   151    // helper html tag functions
   152    Import_Class_Protocol HtmlFormat_Mixin
   153    Import_Class_Protocol HtmlWrite_Mixin
   154
   155    Procedure AddSubTotal Integer iCounter Number nData
   156        Number nValue
   157        Integer iObj
   158        Move (oRptTotal(phMainReport(self))) to iObj
   159        Get Number_Value of iObj Item iCounter To nValue
   160        Add nData To nValue
   161        Set Array_Value of iObj Item iCounter To nValue
   162    End_Procedure
   163
   164    Procedure ClearSubTotal Integer iCounter
   165        Set Array_Value of (oRptTotal(phMainReport(self))) Item iCounter To 0
   166    End_Procedure
   167
   168    Procedure ClearAllSubTotals
   169        Send Delete_Data to (oRptTotal(phMainReport(self)))
   170    End_Procedure
   171
   172    Function SumSubTotal Integer iTotal Returns Number
   173        Number nRetVal
   174        Get Number_Value of (oRptTotal(phMainReport(self))) Item iTotal To nRetVal
   175        Function_Return nRetVal
   176    End_Function
   177
   178    //Return sub-total and clear accumulator
   179    Function SubTotal Integer iTotal Returns Number
   180        Number nRetVal
   181        Get SumSubTotal  iTotal to nRetVal
   182        Send ClearSubTotal iTotal
   183        Function_Return nRetVal
   184    End_Function
   185
   186
   187    { Visibility=Private }
   188    Procedure Close_Output_Device
   189       integer hObj
   190       Get phOutputDevice to hObj
   191       If hObj ;
   192          Send Close_Output_Device to hObj
   193       else ;
   194          Forward Send Close_Output_Device
   195    End_Procedure
   196
   197    { Visibility=Private }
   198    Procedure Initialize_Output_Device
   199       integer hObj
   200       Get phOutputDevice to hObj
   201       If hObj ;
   202          Send Initialize_Output_Device to hObj
   203       Else ;
   204          Forward Send Initialize_Output_Device
   205    End_procedure
   206
   207    { Visibility=Private }
   208    Procedure Output String WrStr
   209       integer hObj
   210       Get phOutputDevice to hObj
   211       If hObj Send Output to hObj WrStr
   212       else Writeln WrStr
   213    End_Procedure
   214
   215    // augment to always returns OK. User must decide when to
   216    // break pages with page_end_state
   217    { Visibility=Private }
   218    Function Page_End_Check Integer Lines Returns Integer
   219    End_Function
   220
   221
   222    //  Procedure: Handle_Footer (Internal)
   223    //
   224    { Visibility=Private }
   225    Procedure Handle_Footer Integer LastTime // Do Filler and footer
   226      Integer i PE
   227      If (pbChildReport(self)) ;
   228         Send Handle_Footer to (phMainReport(self)) LastTime
   229      Else Begin
   230         Set No_PageCheck_State to True
   231         Send OnPageTotal
   232         If LastTime eq 0 Send OnPageFooter
   233         else             Send OnReportFooter
   234         Send OnPageBottom
   235         Set No_PageCheck_State to False
   236      End
   237    End_Procedure
   238
   239    Procedure WriteHtml String WrStr
   240        If Not (No_PageCheck_State(self)) Send Page_Check 0
   241        Send Output WrStr
   242    End_Procedure
   243
   244
   245    Procedure WriteLn String WrStr
   246       Send WriteHtmlBreak WrStr
   247    End_Procedure
   248
   249End_Class
   250