Module cSigCJReportControl.pkg

     1//==============================================================================
     2// Project      : SigCj - VDF Classes for Codejock
     3// File         : cSigCJReportControl.pkg
     4// Description  : VDF Class for Codejock control
     5//
     6// Revision     : $Rev: 691 $
     7//                $Date: 2011-04-19 03:50:13 -0400 (Tue, 19 Apr 2011) $
     8//                $Author: martin $ Martin Pincott
     9//
    10// Requirements : Visual DataFlex 12.1+
    11//                Codejock SuitePro - Version 12.0.0+
    12//
    13// Copyright    : (c) 2008 VDF SIG UK
    14//                Visual DataFlex Special Interest Group UK.
    15//                http://www.vdfsig.co.uk/
    16//                dev@vdfsig.co.uk
    17//
    18//                This file is part of SigCj.
    19//
    20//                SigCj is free software: you can redistribute it and/or modify
    21//                it under the terms of the GNU Lesser General Public License
    22//                as published by the Free Software Foundation, either version
    23//                2.1 of the License, or (at your option) any later version.
    24//
    25//                SigCj is distributed in the hope that it will be useful, but
    26//                WITHOUT ANY WARRANTY; without even the implied warranty of
    27//                MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    28//                GNU Lesser General Public License for more details.
    29//
    30//                If you have the complete SigCj workspace then a copy of the
    31//                GNU Lesser General Public License is in the Docs folder. If
    32//                not, see <http://www.gnu.org/licenses/>.
    33//
    34//==============================================================================
    35// Contributions
    36// =============
    37//
    38// When       Who           What
    39// ========== ============= =====================================================
    40// 2009-06-25 Chris Spencer Reported Bug when using DD defined check boxes.
    41//
    42//==============================================================================
    43
    44Use SigCjW_ReportControl.pkg
    45Use cSigCJMethods_Mixin.pkg
    46Use cSigCJGlobalSettings.pkg
    47Use cSigCJPropEx_Mixin.pkg
    48Use cSigCJReportControlContextMenu.pkg
    49Use cSigCJFieldChooser.pkg
    50Use gFormatNumbers.pkg
    51Use CSV_Export.dg
    52Use StdFont.pkg
    53
    54Register_Function pbRefreshRequired Returns Boolean
    55
    56Class SigCJReportIdleHandler is a cIdleHandler
    57
    58    Procedure OnIdle
    59        If (pbRefreshRequired(Self)) Begin
    60            Delegate Send Refresh_Report
    61            Set pbRefreshRequired to False 
    62        End
    63    End_Procedure
    64    
    65 End_Class 
    66
    67Class SigCJReportColumn is a cSigCjComReportColumn
    68    Import_Class_Protocol cSigCJMethods_Mixin
    69
    70    Procedure Construct_Object
    71        Forward Send Construct_Object
    72
    73        { Visibility=Private }
    74        { MethodType=Property }
    75        Property String Private.psImage
    76        { Visibility=Private }
    77        { MethodType=Property }
    78        Property Integer Private.piImage
    79    End_Procedure
    80
    81
    82    { MethodType=Property }
    83    { Category="CodeJock" }
    84    Procedure Set psImage String sImage
    85        Integer iImageId
    86        Variant vImage
    87
    88        Get AddImage    of ghoSigCjGlobalSetting sImage 0 OLExtpImageNormal to iImageId
    89        Set Private.piImage to iImageId
    90
    91        If (IsComObjectCreated(Self)) Set ComIcon to iImageId
    92    End_Procedure
    93
    94    { MethodType=Property }
    95    { Category="CodeJock" }
    96    Function psImage Returns String
    97        Function_Return (Private.psImage(Self))
    98    End_Function
    99
   100End_Class
   101
   102
   103Class SigCJReportRecordItem is a cSigCjComReportRecordItem
   104    Import_Class_Protocol cSigCJMethods_Mixin
   105
   106    Procedure Construct_Object
   107        Forward Send Construct_Object
   108
   109        { Visibility=Private }
   110        { MethodType=Property }
   111        Property String Private.psImage
   112        { Visibility=Private }
   113        { MethodType=Property }
   114        Property Integer Private.piImage
   115    End_Procedure
   116
   117
   118    { MethodType=Property }
   119    { Category="CodeJock" }
   120    Procedure Set psImage String sImage
   121        Integer iImageId
   122        Variant vImage
   123
   124        Get AddImage    of ghoSigCjGlobalSetting sImage 0 OLExtpImageNormal to iImageId
   125        Set Private.piImage to iImageId
   126
   127        If (IsComObjectCreated(Self)) Set ComIcon to iImageId
   128    End_Procedure
   129
   130    { MethodType=Property }
   131    { Category="CodeJock" }
   132    Function psImage Returns String
   133        Function_Return (Private.psImage(Self))
   134    End_Function
   135
   136End_Class
   137
   138
   139//Add the the next line to your main program in order to use Mertech SQL drivers instead of DataAccess drivers.
   140//Define SigCj_Use_Mertech_Drivers
   141
   142#IFDEF SigCj_Use_Mertech_Drivers
   143    Use MerTech.inc
   144    Use cSQLResultSet.pkg
   145    Move SQLFLEX To _SQLBACKEND    // Default = Move ORAFLEX To _SQLBACKEND
   146#ELSE
   147    Use sql.pkg
   148#ENDIF
   149
   150//=============================================================================
   151//Enums
   152//=====
   153
   154Enum_List // HitTest
   155    Define eRC_HitTest_None
   156    Define eRC_HitTest_Unknown
   157    Define eRC_HitTest_GroupBox
   158    Define eRC_HitTest_Header
   159    Define eRC_HitTest_ReportArea
   160End_Enum_List
   161
   162Enum_List // Data Source
   163    Define eRC_db_Table
   164    Define eRC_db_SQL
   165    Define eRC_db_Text
   166End_Enum_List
   167
   168Enum_List // Find record Method for standard dataflex tables 
   169    Define eRC_Find_Normal 
   170    Define eRC_Find_RequestRead 
   171    Define eRC_Find_Constrained 
   172End_Enum_List
   173
   174Enum_List // Styles
   175    Define eRC_Standard
   176    Define eRC_CheckBox
   177    Define eRC_Preview
   178End_Enum_List
   179
   180Enum_List
   181    Define eRC_BestFit_None
   182    Define eRC_BestFit_Visible
   183    Define eRC_BestFit_All
   184End_Enum_List
   185
   186//-----------------------------------------------------------------------------
   187
   188Enum_List  // Data Type
   189    Define eRC_String           // This first so string is default if data type not specified
   190    Define eRC_Currency
   191    Define eRC_Date
   192    Define eRC_DateTime
   193    Define eRC_DTString         // Datatime held as a String
   194    Define eRC_Integer
   195    Define eRC_Real
   196    Define eRC_Decimal          // It will work out the number decimal places, upto 8
   197    Define eRC_Text             // Text fields have automatic word wrap
   198    Define eRC_Time
   199    Define eRC_Dev1             // For Development formats 
   200    Define eRC_Dev2
   201    Define eRC_Dev3
   202    Define eRC_Last_DataType    // MUST BE Lst in Enum_List
   203End_Enum_List
   204
   205Define eRC_Num_DataTypes for (eRC_Last_DataType - 1) // Now many types defined (0 based)
   206
   207//-----------------------------------------------------------------------------
   208
   209Struct tdRC_Column_Format
   210    Boolean bBold
   211    Boolean bColorColumn
   212    Integer eAlignment
   213    Integer eBestFit
   214    Integer iForeColor
   215    Integer iBackColor
   216    Integer iForeColor_Neg
   217    Integer iBackColor_Neg
   218    String  sFormat         //the format of the caption - see Codejock help
   219    String  sDateFormat     //the format of the source Date/Time data (e.g. DD-MM-YYYY hh:mm:ss)
   220End_Struct
   221
   222#Replace tdRC_Column_Formats  tdRC_Column_Format[eRC_Last_DataType] //Let the compile do the work
   223
   224//-----------------------------------------------------------------------------
   225
   226Struct tdRC_Column_Def
   227    String  sLabel     // - Column header label
   228    Integer iSize      // - Column size
   229    Integer eDataType  // - Column data type
   230    Integer eStyle     // - Column style - Currency / checkbox etc
   231    String  sTC_Name   // - Table / Column name (file.field)
   232    String  sEval      // - Eval value for database function or datafield displayed
   233End_Struct
   234
   235//-----------------------------------------------------------------------------
   236
   237Struct tdRC_Ordering
   238    Integer iColumn         // - Column Number (zero based)
   239    Boolean bDescending     // - True = Descending, False = Ascending
   240End_Struct
   241
   242//-----------------------------------------------------------------------------
   243
   244
   245{ OverrideProperty=Label_Col_Offset          DesignTime=False }
   246{ OverrideProperty=Label_Justification_Mode  DesignTime=False }
   247{ OverrideProperty=Label_Row_Offset          DesignTime=False }
   248{ OverrideProperty=piMinSize                 DesignTime=False }
   249{ OverrideProperty=Border_Style              DesignTime=False }
   250{ OverrideProperty=Visible_State             DesignTime=False }
   251{ OverrideProperty=Attach_Parent_State       DesignTime=False }
   252{ OverrideProperty=Block_Mouse_State         DesignTime=False }
   253{ OverrideProperty=Client_Area_State         DesignTime=False }
   254{ OverrideProperty=Delegation_Mode           DesignTime=False }
   255{ OverrideProperty=Focus_Mode                DesignTime=False }
   256{ OverrideProperty=pbBindValue               DesignTime=False }
   257{ OverrideProperty=peAutoCreate              DesignTime=False }
   258{ OverrideProperty=peNeighborhood            DesignTime=False }
   259{ OverrideProperty=Popup_State               DesignTime=False }
   260{ OverrideProperty=Ring_State                DesignTime=False }
   261{ OverrideProperty=Scope_State               DesignTime=False }
   262{ OverrideProperty=Search_Case               DesignTime=False }
   263{ OverrideProperty=Skip_State                DesignTime=False }
   264{ OverrideProperty=Help_Id                   DesignTime=False }
   265{ OverrideProperty=Help_Keyword              DesignTime=False }
   266{ OverrideProperty=psHtmlHelpTopic           DesignTime=False }
   267{ OverrideProperty=Status_Help               DesignTime=False }
   268{ OverrideProperty=Use_Parent_Status_Help    DesignTime=False }
   269{ OverrideProperty=psLicenseKey              DesignTime=False }
   270{ OverrideProperty=psProgID                  DesignTime=False }
   271{ OverrideProperty=Color                     InitialValue=clActiveCaption }
   272{ OverrideProperty=psPX_Class InitialValue="SigCjReportControl" }
   273
   274{ DesignerClass=cDTGrid }
   275Class cSigCJReportControl is a cSigCjComReportControl
   276    Import_Class_Protocol cSigCJMethods_Mixin
   277    Import_Class_Protocol cSigCJPropEx_Mixin
   278
   279//    Set Color to clActiveCaption // Used only by the Studio
   280
   281    Procedure Construct_Object
   282        Handle hoFieldChooserPanel
   283        
   284        Forward Send Construct_Object
   285
   286        { DesignTime=False }
   287        Property Handle phoReportRecords             (Create(Self, U_cSigCjComReportRecords))
   288
   289        { DesignTime=False }
   290        Property Handle phoReportRecord              (Create(Self, U_cSigCjComReportRecord))
   291
   292        { DesignTime=False }
   293        Property Handle phoReportRecordItem          (Create(Self, U_SigCJReportRecordItem))
   294
   295        { DesignTime=False }
   296        Property Handle phoReportRecordItemMetrics   (Create(Self, U_cSigCjComReportRecordItemMetrics))
   297
   298        { DesignTime=False }
   299        Property Handle phoReportColumns             (Create(Self, U_cSigCjComReportColumns))
   300
   301        { DesignTime=False }
   302        Property Handle phoReportColumn              (Create(Self, U_SigCJReportColumn))
   303
   304        { DesignTime=False }
   305        Property Handle phoReportColumnOrder         (Create(Self, U_cSigCjComReportColumnOrder))
   306
   307        { DesignTime=False }
   308        Property Handle phoReportRows                (Create(Self, U_cSigCjComReportRows))
   309
   310        { DesignTime=False }
   311        Property Handle phoReportRow                 (Create(Self, U_cSigCjComReportRow))
   312
   313        { DesignTime=False }
   314        Property Handle phoReportGroupRow            (Create(Self, U_cSigCjComReportGroupRow))
   315
   316        { DesignTime=False }
   317        Property Handle phoReportSelectedRows        (Create(Self, U_cSigCjComReportSelectedRows))
   318
   319        { DesignTime=False }
   320        Property Handle phoReportPaintManager        (Create(Self, U_cSigCjComReportPaintManager))
   321
   322        { DesignTime=False }
   323        Property Handle phoReportPrintOptions        (Create(Self, U_cSigCjComReportPrintOptions))
   324
   325        { DesignTime=False }
   326        Property Handle phoPrintPageHeaderFooter     (Create(Self, U_cSigCjComPrintPageHeaderFooter))
   327
   328        { DesignTime=False }
   329        Property Handle phoHitTestInfo               (Create(Self, U_cSigCjComReportHitTestInfo))
   330
   331        { DesignTime=False }
   332        Property tdRC_Column_Formats ptColumn_Formats
   333
   334        { Category="CodeJock" InitialValue="" }
   335        Property String  psWatermarkBitmap 
   336        
   337        { Category="CodeJock" InitialValue=2082 } // 2 + 32 + 2048 = 2082
   338        Property Integer piWatermarkAlignment (OLExtpReportWatermarkCenter + OLExtpReportWatermarkvCenter + OLExtpReportWatermarkPreserveRatio)
   339
   340        { Category="CodeJock" InitialValue=35 }
   341        Property Integer piWatermarkWeight 35 
   342        
   343        { Category="CodeJock" InitialValue=True }
   344        Property Boolean pbWatermarkFromFile True 
   345        
   346        { Category="CodeJock" InitialValue=False }
   347        Property Boolean pbPrintLandscape False
   348        
   349        // Font Support 
   350        { DesignTime=False }
   351        Property Handle phoFont               (Create(Self, U_cComStdFont))
   352        
   353        { Category="CodeJock" InitialValue="" }
   354        Property String  psGridFontName
   355        
   356        { Category="CodeJock" InitialValue=0 }
   357        Property Number  pnGridFontSize 
   358
   359        { Category="CodeJock" InitialValue="" }
   360        Property String  psPreviewFontName
   361        
   362        { Category="CodeJock" InitialValue=0 }
   363        Property Number  pnPreviewFontSize 
   364        
   365        { DesignTime=False }
   366        Property Integer Private_piFreezeColumnsCount 0
   367        
   368        { Category="CodeJock" InitialValue=False }
   369        Property Boolean pbFreezeColumns False
   370
   371        { DesignTime=False }
   372        Property Integer Private_piColumn_Count 0
   373
   374        { DesignTime=False }
   375        Property Integer Private_piCurrentColumnIndex 0
   376
   377        { DesignTime=False }
   378        Property Integer Private_piRow_Count 0
   379
   380        { DesignTime=False }
   381        Property Integer Private_piFiltered_Row_Count 0
   382
   383        { DesignTime=False }
   384        Property Integer Private_piSelected_Row_Count 0
   385
   386        { DesignTime=False }
   387        Property Boolean Private_pbPreviewMode True
   388        
   389        { Category="CodeJock" InitialValue="" }
   390        Property Handle phoContextMenu_Header        (Create(Self, U_cSigCJReportControlContextMenu_Header))
   391
   392        { Category="CodeJock" InitialValue="" }
   393        Property Handle phoContextMenu_GroupBox      (Create(Self, U_cSigCJReportControlContextMenu_GroupBox))
   394
   395        { Category="CodeJock" InitialValue="" }
   396        Property Handle phoContextMenu_ReportArea    (Create(Self, U_cSigCJReportControlContextMenu_ReportArea))
   397        
   398        { DesignTime=False }
   399        { EnumList="eRC_HitTest_None, eRC_HitTest_Unknown, eRC_HitTest_GroupBox, eRC_HitTest_Header, eRC_HitTest_ReportArea"}
   400        Property Integer peHitTest
   401        
   402        { Category="CodeJock" InitialValue=False }
   403        Property Boolean pbActive_Track False
   404
   405        { Category="CodeJock" InitialValue=False }
   406        Property Boolean pbAuto_Columns False
   407
   408        { Category="CodeJock" InitialValue=True }
   409        Property Boolean pbAuto_Fill True
   410
   411        { Category="CodeJock-Text Files Only" InitialValue=True }
   412        Property Boolean pbAuto_Row_Ref True
   413
   414        { Category="CodeJock" }
   415        Property String  psProcess_Type
   416
   417        { DesignTime=False }
   418        Property Integer piCh_No 0
   419
   420        { DesignTime=False }
   421        Property tdRC_Column_Def[] ptColumn_Defs
   422
   423        { DesignTime=False }
   424        Property String[] psData_Items
   425
   426        { Category="CodeJock" InitialValue=eRC_db_Table }
   427        { EnumList="eRC_db_Table, eRC_db_SQL, eRC_db_Text"}
   428        Property Integer peDb_Type eRC_db_Table
   429
   430        { DesignTime=False }
   431        Property Handle phoDD 0
   432
   433        { Category="CodeJock" InitialValue=True }
   434        Property Boolean pbShowGroupBox True
   435
   436        { Category="CodeJock" InitialValue=False }
   437        Property Boolean pbDescending False
   438
   439        { Category="CodeJock" InitialValue=False }
   440        Property Boolean pbCollapseGroups False
   441
   442        { Category="CodeJock" InitialValue= True}
   443        Property Boolean pbColumn_Resort True
   444
   445        { DesignTime=False }
   446        Property Boolean pbEOF False
   447
   448        { Category="CodeJock" }
   449        Property Handle phoFieldChooser 0
   450
   451        { DesignTime=False }
   452        { Obsolete=True }
   453        Property Handle Private_phoFieldChooserList 0 
   454
   455        { DesignTime=False}
   456        Property Boolean pbDefaultLayout False 
   457
   458        { Category="CodeJock" InitialValue= 0}
   459        Property Integer piMax_Rows 0
   460
   461        { Category="CodeJock" InitialValue= False}
   462        Property Boolean pbRow_Item False
   463
   464        { Category="CodeJock" InitialValue= False}
   465        Property Boolean pbRow_Colors False
   466
   467        { Category="CodeJock" InitialValue= False}
   468        Property Boolean pbItem_Colors False
   469
   470        { DesignTime=False }
   471        Property Integer piRow_ForeColor 0
   472
   473        { DesignTime=False }
   474        Property Integer piRow_BackColor 0
   475
   476        { DesignTime=False }
   477        Property Integer piItem_ForeColor 0
   478
   479        { DesignTime=False }
   480        Property Integer piItem_BackColor 0
   481
   482        { DesignTime=False }
   483        Property String  psExport_File ""
   484
   485        { Category="CodeJock" InitialValue=0 }
   486        Property Integer piRef_Column    0
   487
   488        { DesignTime=False }
   489        Property String  psCurrent_Tag "" 
   490
   491        { Category="CodeJock-Data Tables Only" InitialValue=False }
   492        Property Boolean pbRowID_Mode False
   493
   494        { Category="CodeJock" InitialValue=False }
   495        Property Boolean pbShow_Recnum False
   496        
   497        { Category="CodeJock" InitialValue=True }
   498        Property Boolean pbWordWrap True
   499        
   500        { Category="CodeJock" InitialValue=eRC_Find_Normal }
   501        { EnumList="eRC_Find_Normal, eRC_Find_RequestRead, eRC_Find_Constrained"}
   502        Property Integer peDataflex_Table_Find_Method 
   503        
   504        { Category="CodeJock-SQL" InitialValue=False }
   505        Property Boolean pbSQL_Case False
   506
   507        { Category="CodeJock-SQL" InitialValue="" }
   508        Property String  psSQL_From ""
   509
   510        { Category="CodeJock-SQL" InitialValue="" }
   511        Property String  psSQL_OrderBy ""
   512
   513        { Category="CodeJock-SQL" InitialValue="" }
   514        Property String  psSQL_Select ""
   515
   516        { DesignTime=False }
   517        Property String  psSQL_Select_Statment ""
   518
   519        { Category="CodeJock-SQL" InitialValue="" }
   520        Property String  psSQL_Where ""
   521
   522        { Category="CodeJock" InitialValue=0 }
   523        Property Integer piTable_Index 0
   524
   525        { Category="CodeJock" InitialValue=0 }
   526        Property Integer piLoad_Monitor 0
   527
   528        { DesignTime=False }
   529        Property TimeSpan ptsTimeSpan_Load
   530
   531        { DesignTime=False }
   532        Property TimeSpan ptsTimeSpan_SQL
   533
   534        { DesignTime=False }
   535        Property Boolean pbRefreshRequired False 
   536
   537        #IFDEF SigCj_Use_Mertech_Drivers
   538        #ELSE
   539            Object oSQL_Report_Handler is a cSQLHandleManager
   540            End_Object
   541        #ENDIF
   542
   543        Object oSigCJReportIdleHandler is a SigCJReportIdleHandler
   544            Set pbEnabled to True 
   545        End_Object
   546
   547        Send Initialise_PropEx_Mixin        
   548        Set psPX_Class to "SigCjReportControl"
   549    End_Procedure
   550
   551    Procedure End_Construct_Object
   552        Forward Send End_Construct_Object
   553        
   554        Send Initialise_Column_Formats
   555    End_Procedure
   556
   557    //~~~~~~~~~~~~~~~~~~~~~~~~~~
   558
   559    Function CreateFieldChooserPanel Returns Handle
   560        Handle hoFieldChooserPanel
   561
   562        Get Create U_cSigCjGridFieldChooserPanel to hoFieldChooserPanel
   563        Set phoGridObject of hoFieldChooserPanel to Self
   564        
   565        Function_Return hoFieldChooserPanel
   566    End_Function
   567
   568    Procedure AttachFieldChooser Handle hoFieldChooser Boolean bAttach
   569        Variant vFieldChooser
   570        
   571        If (IsComObjectCreated(Self) and hoFieldChooser <> 0) Begin
   572            If bAttach Begin
   573                Get pvComObject of hoFieldChooser to vFieldChooser
   574            End
   575            Else Begin
   576                Move (NullComObject()) to vFieldChooser
   577            End
   578            Set ComFieldChooser to vFieldChooser
   579        End
   580    End_Procedure  // AttachFieldChooser
   581
   582    //~~~~~~~~~~~~~~~~~~~~~~~~~~
   583
   584    Procedure Reset_Data_Properties
   585        Set pbAuto_Columns        to False
   586        Set pbAuto_Row_Ref        to True
   587        Set phoDD                 to 0
   588        Set pbDescending          to False
   589        Set ptsTimeSpan_Load      to ""
   590        Set ptsTimeSpan_SQL       to ""
   591        Set piMax_Rows            to 0
   592        Set piRef_Column          to 0
   593        Set pbRowID_Mode          to False
   594        Set pbShow_Recnum         to False
   595        Set pbSQL_Case            to False
   596        Set psSQL_From            to ""
   597        Set psSQL_OrderBy         to ""
   598        Set psSQL_Select          to ""
   599        Set psSQL_Select_Statment to ""
   600        Set psSQL_Where           to ""
   601        Set piTable_Index         to 0
   602
   603        Set Private_piRow_Count             to 0
   604        Set Private_piFiltered_Row_Count    to 0
   605        Set Private_piSelected_Row_Count    to 0
   606    End_Procedure
   607
   608    //-------------------------------------------------------------------------
   609    // Support for Obsolete Code 
   610    
   611    { Category="CodeJock" InitialValue=True }
   612    { Obsolete=True } 
   613    Procedure Set pbNormal_Find_Method Boolean bOk
   614        If (bOk) Set peDataflex_Table_Find_Method to eRC_Find_Normal
   615        Else Set peDataflex_Table_Find_Method to eRC_Find_Constrained
   616    End_Procedure
   617    // Use Set peDataflex_Table_Find_Method to eRC_Find_Normal
   618    // Options eRC_Find_Normal eRC_Find_RequestRead eRC_Find_Constrained 
   619    
   620
   621    //-------------------------------------------------------------------------
   622
   623    {Category="CodeJock" MethodType=Method}
   624    Procedure SetWatermark
   625        Boolean bWatermarkFromFile bRetval
   626        Integer iWatermarkWeight iWatermarkAlignment iImageId
   627        String  sWatermarkBitmap sBitmapPath   
   628
   629        Get psWatermarkBitmap    to sWatermarkBitmap   
   630        Get piWatermarkWeight    to iWatermarkWeight  
   631        Get piWatermarkAlignment to iWatermarkAlignment
   632        Get pbWatermarkFromFile  to bWatermarkFromFile
   633        
   634        Set ComWatermarkAlignment to iWatermarkAlignment
   635
   636        If (sWatermarkBitmap <> "") Begin
   637            If (bWatermarkFromFile) Begin          
   638                Get psBitmapPath of (phoWorkspace(ghoApplication))        to sBitmapPath 
   639                Move (Append(sBitmapPath,String("\" + sWatermarkBitmap))) to sBitmapPath
   640                Get ComSetWatermarkBitmapFromFile sBitmapPath iWatermarkWeight to bRetval
   641            End 
   642            Else Begin
   643                Get AddImage of ghoSigCjGlobalSetting sWatermarkBitmap 0 OLExtpImageNormal to iImageId
   644                Get ComSetWatermarkBitmap iImageId iWatermarkWeight to bRetval
   645//                If (IsComObjectCreated(Self)) Set ComIcon to iImageId
   646            End
   647        End     
   648    End_Procedure
   649    
   650    {Category="CodeJock" MethodType=Property InitialValue=0 }
   651    Procedure Set piFreezeColumnsCount Integer iCount
   652        Set SigCJProperty Set_Private_piFreezeColumnsCount Set_ComFreezeColumnsCount to iCount 
   653    End_Procedure
   654
   655    Function piFreezeColumnsCount Returns Integer
   656        Function_Return (SigCJProperty(Self, Get_Private_piFreezeColumnsCount, Get_ComFreezeColumnsCount))
   657    End_Function
   658    
   659    { MethodType=Property }
   660    Function piColumn_Count Returns Integer
   661        Function_Return (Private_piColumn_Count(Self))
   662    End_Function
   663
   664    { MethodType=Property Category="CodeJock" PropertyType=Color InitialValue=clWindow }
   665    Procedure Set piBackColor Integer iColor
   666        Set SigCJProperty Set_Private_piBackColor Set_ComBackColor to iColor
   667    End_Procedure
   668    
   669    Function piBackColor Returns Integer
   670        Function_Return (SigCJProperty(Self, Get_Private_piBackColor, Get_ComBackColor ))
   671    End_Function
   672
   673    { MethodType=Property }
   674    Function piRow_Count Returns Integer
   675        Function_Return (Private_piRow_Count(Self))
   676    End_Function
   677    
   678    { MethodType=Property }
   679    Function piFiltered_Row_Count Returns Integer
   680        Function_Return (Private_piFiltered_Row_Count(Self))
   681    End_Function
   682    
   683    { MethodType=Property }
   684    Function piSelected_Row_Count Returns Integer
   685        Function_Return (Private_piSelected_Row_Count(Self))
   686    End_Function
   687
   688    { MethodType=Property }
   689    Function pbPreviewMode Returns Boolean
   690        Function_Return (Private_pbPreviewMode(Self))
   691    End_Function  
   692    
   693    { MethodType=Property DesignTime=False }
   694    Procedure Set pbPreviewMode Boolean bValue
   695        If (IsComObjectCreated(Self)) Begin
   696            Set ComPreviewMode to bValue 
   697            Set Private_pbPreviewMode to bValue 
   698        End    
   699    End_Procedure    
   700    
   701    //-------------------------------------------------------------------------
   702
   703    Procedure FieldChooser
   704        Send Popup to (phoFieldChooser(Self)) 
   705    End_Procedure
   706    
   707    Procedure DefaultLayout
   708        Set pbDefaultLayout to True
   709        Send Rebuild_Report
   710        Set pbDefaultLayout to False
   711    End_Procedure
   712        
   713    //-------------------------------------------------------------------------
   714
   715    Procedure Initialise_Column_Formats
   716        Integer iLoop
   717        tdRC_Column_Formats tColumn_Formats
   718
   719        Get ptColumn_Formats to tColumn_Formats
   720
   721        For iLoop from 0 to eRC_Num_DataTypes
   722            Move False               to tColumn_Formats[iLoop].bBold
   723            Move False               to tColumn_Formats[iLoop].bColorColumn
   724            Move eRC_BestFit_None to tColumn_Formats[iLoop].eBestFit
   725            Move clWindow            to tColumn_Formats[iLoop].iBackColor
   726            Move clWindowText        to tColumn_Formats[iLoop].iForeColor
   727            Move clWindow            to tColumn_Formats[iLoop].iBackColor_Neg
   728            Move clRed               to tColumn_Formats[iLoop].iForeColor_Neg
   729            Move ""                  to tColumn_Formats[iLoop].sFormat
   730            Move ""                  to tColumn_Formats[iLoop].sDateFormat
   731
   732            Move OLExtpAlignmentLeft to tColumn_Formats[iLoop].eAlignment
   733            If ((iLoop = eRC_Currency) or (iLoop = eRC_Integer) or (iLoop = eRC_Real)) Begin
   734                Move OLExtpAlignmentRight to tColumn_Formats[iLoop].eAlignment
   735            End
   736            If (iLoop = eRC_Decimal) Begin
   737                Move OLExtpAlignmentRight to tColumn_Formats[iLoop].eAlignment
   738                Move "%.8s" to tColumn_Formats[iLoop].sFormat
   739            End
   740            If (iLoop = eRC_Text) Begin
   741                Move OLExtpAlignmentWordBreak to tColumn_Formats[iLoop].eAlignment
   742                Move eRC_BestFit_None to tColumn_Formats[iLoop].eBestFit
   743            End
   744            If (iLoop = eRC_date) Begin
   745                Move eRC_BestFit_All to tColumn_Formats[iLoop].eBestFit
   746            End
   747        Loop
   748
   749        Set ptColumn_Formats to tColumn_Formats
   750
   751        Send OnSetColumnFormats
   752    End_Procedure
   753
   754    Procedure OnSetColumnFormats
   755        //Event Hook
   756        //
   757        //tdRC_Column_Formats tColumn_Formats
   758        //
   759        //Get ptColumn_Formats to tColumn_Formats
   760        //
   761        //Move True   to tColumn_Formats[eRC_Dev1].bBold
   762        //Move clBlue to tColumn_Formats[eRC_Dev1].iForeColor
   763        //Move "%.2s" to tColumn_Formats[eRC_Dev1].sFormat
   764        //
   765        //Set ptColumn_Formats to tColumn_Formats
   766        //
   767    End_Procedure
   768
   769    //-------------------------------------------------------------------------
   770    // Context Menu OnAdd_ Hook options
   771    //-------------------------------------------------------------------------
   772    Procedure OnAdd_ContextMenu_GroupBox Handle hoContextMenu
   773    End_Procedure
   774
   775    Procedure OnAdd_ContextMenu_Header Handle hoContextMenu
   776    End_Procedure
   777
   778    Procedure OnAdd_ContextMenu_ReportArea Handle hoContextMenu
   779    End_Procedure
   780
   781    Procedure OnCreate
   782        Handle  hoReportPaintManager hoReportPrintOptions hoFieldChooserPanel hoFont 
   783        Handle  hoContextMenu_GroupBox hoContextMenu_Header hoContextMenu_ReportArea
   784        Variant vImageList vFont
   785        String  sFontName
   786        Number  nFontSize 
   787
   788        Forward Send OnCreate
   789
   790        Set ComAutoColumnSizing   to False
   791        Get phoReportPaintManager to hoReportPaintManager
   792        Get phoReportPrintOptions to hoReportPrintOptions
   793
   794        //Attach the report control paint manager and Print options to the DataFlex objects.
   795        //(Only one of each object, so leave attached)
   796        Set pvComObject of hoReportPaintManager to (ComPaintManager(Self))
   797        Set pvComObject of hoReportPrintOptions to (ComPrintOptions(Self))
   798
   799        //Setup Paint Manager
   800        Set ComBorderStyle       to OLExtpBorderThemedFrame
   801        Set ComFixedRowHeight    of hoReportPaintManager to False    //Allow multi row items
   802        Set ComVerticalGridStyle of hoReportPaintManager to OLExtpGridNoLines
   803        #IF (SigCj_Codejock_Version < 150001) 
   804            Set ComColumnStyle       of hoReportPaintManager to OLExtpColumnOffice2007
   805        #ELSE    
   806            Set ComColumnStyle       of hoReportPaintManager to OLExtpColumnResource
   807        #ENDIF 
   808
   809        // Setup Print Options 
   810        If (pbPrintLandscape(Self)) Set ComLandscape of hoReportPrintOptions to True
   811
   812        // Setup Fonts
   813        Get psGridFontName to sFontName
   814        Get pnGridFontSize to nFontSize 
   815        If ((sFontName <> "") or (nFontSize > 0)) Begin
   816            Set ComFixedRowHeight of hoReportPaintManager to False
   817            Get phoFont to hoFont
   818            Get ComTextFont of hoReportPaintManager to vFont
   819            Set pvComObject of hoFont to vFont
   820            If (sFontName <> "") Set ComName of hoFont to sFontName
   821            If (nFontSize > 0)   Set ComSize of hoFont to nFontSize
   822        End
   823        Get psPreviewFontName to sFontName
   824        Get pnPreviewFontSize to nFontSize 
   825        If ((sFontName <> "") or (nFontSize > 0)) Begin
   826            Set ComFixedRowHeight of hoReportPaintManager to False
   827            Get phoFont to hoFont
   828            Get ComPreviewTextFont of hoReportPaintManager to vFont
   829            Set pvComObject of hoFont to vFont
   830            If (sFontName <> "") Set ComName of hoFont to sFontName
   831            If (nFontSize > 0)   Set ComSize of hoFont to nFontSize
   832        End
   833
   834
   835        // Setup Icons
   836        Get ComIcons of ghoSigCjGlobalSetting to vImageList
   837        Set ComIcons to vImageList
   838
   839        // Show Group Box
   840        Set ComShowGroupBox      to (pbShowGroupBox(Self))
   841        
   842        Send SetWatermark
   843        
   844        Get CreateFieldChooserPanel to hoFieldChooserPanel
   845        Set phoFieldChooser to hoFieldChooserPanel
   846
   847        // Add Context Menu option hooks 
   848        Get phoContextMenu_GroupBox   to hoContextMenu_GroupBox
   849        Get phoContextMenu_Header     to hoContextMenu_Header
   850        Get phoContextMenu_ReportArea to hoContextMenu_ReportArea
   851        If (Object_Id(hoContextMenu_GroupBox))   Send OnAdd_ContextMenu_GroupBox   hoContextMenu_GroupBox
   852        If (Object_Id(hoContextMenu_Header))     Send OnAdd_ContextMenu_Header     hoContextMenu_Header
   853        If (Object_Id(hoContextMenu_ReportArea)) Send OnAdd_ContextMenu_ReportArea hoContextMenu_ReportArea
   854        
   855        //If auto fill then do so
   856        If (pbAuto_Fill(Self)) Begin
   857            Send Rebuild_Report
   858        End
   859        
   860        Send Standard_PrintFooter
   861    End_Procedure
   862
   863    
   864    //=========================================================================
   865    // Count Hooks
   866    Procedure Report_Row_Count
   867        Integer iRowCount
   868        Handle  hoRecords 
   869        Variant  vRecords 
   870
   871        Get phoReportRecords         to hoRecords
   872        Get ComRecords               to  vRecords
   873        Set pvComObject of hoRecords to  vRecords
   874        Get ComCount    of hoRecords to  iRowCount
   875        Set Private_piRow_Count to iRowCount
   876
   877        Send OnReport_Row_Count iRowCount
   878    End_Procedure
   879
   880    Procedure OnReport_Row_Count Integer iRow_Count 
   881        // Hook
   882    End_Procedure
   883
   884    Procedure Filtered_Row_Count
   885        Integer iGroupCount iFiltered_Count iRow
   886        Boolean bGroupRow
   887        Handle  hoReportRows hoRow
   888        Variant  vReportRows  vRow
   889
   890        Get phoReportRows               to hoReportRows
   891        Get phoReportRow                 to hoRow
   892        Get ComRows                     to  vReportRows
   893        Set pvComObject of hoReportRows to  vReportRows
   894        Get ComCount    of hoReportRows to  iFiltered_Count
   895
   896        Decrement iFiltered_Count
   897        For iRow from 0 to iFiltered_Count
   898            Get ComRow of hoReportRows iRow to vRow
   899            Set pvComObject of hoRow to vRow
   900            Get ComGroupRow of hoRow to bGroupRow
   901            If (bGroupRow) Increment iGroupCount
   902        Loop
   903        Set Private_piFiltered_Row_Count to (iFiltered_Count - iGroupCount +1)
   904
   905        Send OnFiltered_Row_Count (iFiltered_Count - iGroupCount +1)
   906    End_Procedure
   907
   908    Procedure OnFiltered_Row_Count Integer iFiltered_Count
   909        // Hook
   910    End_Procedure
   911
   912    Procedure Selected_Row_Count
   913        Integer iSelectedCount
   914        Handle  hoSelectedRows
   915        Variant vSelectedRows
   916
   917        Get phoReportSelectedRows         to hoSelectedRows
   918        Get ComSelectedRows               to  vSelectedRows
   919        Set pvComObject of hoSelectedRows to  vSelectedRows
   920        Get ComCount    of hoSelectedRows to  iSelectedCount
   921        Set Private_piSelected_Row_Count to iSelectedCount
   922
   923        Send OnSelected_Row_Count iSelectedCount
   924    End_Procedure
   925
   926    Procedure OnSelected_Row_Count Integer iSelectedCount
   927        // Hook
   928    End_Procedure
   929
   930    Procedure OnComSelectionChanged
   931        Send Selected_Row_Count
   932    End_Procedure
   933
   934    //=========================================================================
   935    //General
   936
   937    Procedure Rebuild_Report
   938        Boolean bColumn_Resort
   939        
   940        Get pbColumn_Resort to bColumn_Resort
   941        // On Rebuilding the Report we must reset the Column sort order
   942        Set pbColumn_Resort to True
   943         
   944        Send DoReset_Report_Control //delete any data and column definitions
   945        Send DoDefine_Columns       //define the columns
   946        Send DoLoad_Data            //load the data
   947        Send ComPopulate            //display it
   948
   949        //Send DoBest_Fit
   950
   951        Set ComTopRowIndex to 0     //Insure we're at the top
   952
   953        Send Report_Row_Count
   954        Send Resync_to_Focus_Row
   955
   956        If (pbDefaultLayout(Self) = False) Send PX_Load
   957        Set ComAutoColumnSizing    to False
   958        Set ComShowGroupBox        to (pbShowGroupBox(Self))
   959        Set ComShowItemsInGroups   to False 
   960        Send Remove_Sorted_Columns
   961        Set pbColumn_Resort to bColumn_Resort 
   962    End_Procedure
   963
   964    // Refresh_Report when idle 
   965    Procedure Deferred_Refresh_Report
   966        Set pbRefreshRequired to True
   967    End_Procedure
   968    
   969    // User hook sent at the start of the Refresh_Report method
   970    Procedure OnRefresh_Report
   971    End_Procedure
   972
   973    Procedure Refresh_Report
   974        Send OnRefresh_Report
   975        If (piColumn_Count(Self) = 0) Begin
   976            // No Count then not column data created, so build the report
   977            Send DoReset_Report_Control //delete any data and column definitions
   978            Send DoDefine_Columns       //define the columns
   979        End
   980        Else Begin
   981            Send DoRefresh_Report_Control
   982            If (peDb_Type(Self) = eRC_db_SQL) Send Build_SQL_Statement
   983        End
   984        Send DoLoad_Data            //load the data
   985        Send ComPopulate            //display it
   986
   987        //Send DoBest_Fit
   988
   989        Set ComTopRowIndex to 0     //Insure we're at the top
   990        Send Report_Row_Count
   991        Send Resync_to_Focus_Row
   992    End_Procedure
   993
   994    Procedure Resync_to_Focus_Row
   995        Variant vRow
   996
   997        Get ComFocusedRow to vRow
   998        If (not(IsNullComObject(vRow))) Send OnComFocusChanging vRow Nothing Nothing Nothing
   999        Send Filtered_Row_Count
  1000        Send Selected_Row_Count
  1001    End_Procedure
  1002
  1003    Procedure Filter_Rows String sValue
  1004        Set ComFilterText to sValue
  1005        Send ComPopulate
  1006        Send Resync_to_Focus_Row
  1007    End_Procedure
  1008
  1009    //-------------------------------------------------------------------------
  1010
  1011    Procedure DoReset_Report_Control
  1012        Handle hoColumns
  1013        Variant vColumns
  1014        tdRC_Column_Def[] tColumn_Defs
  1015
  1016        Get phoReportColumns     to hoColumns
  1017
  1018        Send DoDelete_Report_Data
  1019
  1020        //delete report control column objects
  1021        Get ComColumns to vColumns
  1022        Set pvComObject of hoColumns to vColumns
  1023        Send ComDeleteAll of hoColumns
  1024
  1025        //Clear the columns defs
  1026        Set ptColumn_Defs to tColumn_Defs
  1027        Set Private_piColumn_Count to 0 
  1028    End_Procedure
  1029
  1030    Procedure DoRefresh_Report_Control
  1031        Send DoDelete_Report_Data
  1032    End_Procedure
  1033
  1034    Procedure DoDelete_Report_Data
  1035        Handle  hoRecords
  1036        Variant  vRecords
  1037
  1038        Get phoReportRecords     to hoRecords
  1039
  1040        //delete any data
  1041        Get ComRecords to vRecords
  1042        Set pvComObject of hoRecords to vRecords
  1043        Send ComDeleteAll of hoRecords
  1044    End_Procedure
  1045
  1046    //-------------------------------------------------------------------------
  1047
  1048    Procedure DoDefine_Columns
  1049        If (pbAuto_Columns(Self)) Begin
  1050           Send Define_From_DD      //Use DD to create columns
  1051        End
  1052        Else Begin
  1053            Send OnDefine_Columns   //Get user to specify column info
  1054        End
  1055
  1056        Send Create_Columns         //Ceate RC columns based on defined column info
  1057    End_Procedure
  1058
  1059    Procedure OnDefine_Columns
  1060        // Event Hook
  1061        //
  1062        // Call Add_Column for each column
  1063    End_Procedure
  1064
  1065    //-------------------------------------------------------------------------
  1066
  1067    Procedure Define_From_DD
  1068        Boolean bShow_Recnum bShow
  1069        Handle hoDD
  1070        Integer iTable iColumns iLoop iTable_Type eType iSize  iNo_DP iVal_Type
  1071        String sLabel sTable sColumn sTrue sFalse sEval
  1072
  1073        Get pbShow_Recnum to bShow_Recnum
  1074        Get phoDD to hoDD
  1075        If (hoDD <> 0) Begin
  1076            Move (Main_File(hoDD)) to iTable
  1077            Get_Attribute DF_FILE_LOGICAL_NAME     of iTable to sTable
  1078            Get_Attribute DF_FILE_NUMBER_FIELDS of iTable to iColumns
  1079
  1080            For iLoop from 0 to iColumns
  1081                Get_Attribute DF_FIELD_NAME      of iTable iLoop to sColumn
  1082                Move True to bShow
  1083
  1084                If (not(bShow_Recnum) and Uppercase(Trim(sColumn)) = "RECNUM") Move False to bShow
  1085
  1086                //Can add logic in here to control display of overlap / inverse fields etc.
  1087
  1088                If (bShow) Begin
  1089                    Get_Attribute DF_FIELD_LENGTH    of iTable iLoop to iSize
  1090                    Get_Attribute DF_FIELD_TYPE      of iTable iLoop to iTable_Type
  1091
  1092                    Move -1 to eType    //stop un-handled types
  1093                    If (iTable_Type = DF_ASCII    ) Move eRC_String   to eType
  1094                    If (iTable_Type = DF_DATE     ) Move eRC_Date     to eType
  1095                    If (iTable_Type = DF_DATETIME ) Move eRC_DateTime to eType
  1096                    If (iTable_Type = DF_OVERLAP  ) Move eRC_String   to eType
  1097                    If (iTable_Type = DF_TEXT     ) Move eRC_Text     to eType
  1098
  1099                    If (iTable_Type = DF_BCD) Begin
  1100                        Get_Attribute DF_FIELD_PRECISION of iTable iLoop to iNo_DP
  1101                        If (iNo_DP > 0) Move eRC_Real    to eType
  1102                        Else            Move eRC_Integer to eType
  1103                    End
  1104
  1105                    //Override eType eRC_String if size > 50
  1106                    If ((pbWordWrap(Self) = True) and (eType = eRC_String) and (iSize > 50)) Begin
  1107                         Move eRC_Text to eType  //Force word wrap
  1108                         Move 50 to iSize
  1109                    End
  1110
  1111                    If (iSize < 8) Move 8 to iSize  //8 characters seems to be a good minimum size
  1112
  1113                    Move (Field_Label_Short(hoDD,iLoop)) to sLabel
  1114                    If (Trim(sLabel) = "") Move sColumn to sLabel
  1115
  1116                    Move (Field_Validation_Type(hoDD,iLoop)) to iVal_Type
  1117                    If (iVal_Type = FA_VALIDATION_TYPE_CHECKBOX) Begin
  1118                        Move (Field_Checkbox_Value(hoDD,iLoop,True )) to sTrue
  1119                        Move (Field_Checkbox_Value(hoDD,iLoop,False)) to sFalse
  1120
  1121//Bug                        Move ("If(" - sTable - "." - sColumn - " = " - sTrue - ",'" - sTrue - "','" - sFalse - "')") to sEval
  1122                        Move ("If(" - sTable - "." - sColumn - " = '" - sTrue - "', 1, 0)") to sEval
  1123                        Send Add_Report_Column sLabel (iSize * 8) eType eRC_CheckBox (sTable - "." - sColumn) sEval
  1124                    End
  1125                    Else Send Add_Report_Column sLabel (iSize * 8) eType eRC_Standard (sTable - "." - sColumn) ""
  1126                    //(iSize * 8) 8 pixels per char seems to give a good column width
  1127                End
  1128            Loop
  1129        End
  1130    End_Procedure
  1131
  1132    //-------------------------------------------------------------------------
  1133    //CAUTION :- Overloaded Function
  1134
  1135    //For Text & CSV files
  1136//    Procedure Add_Report_Column Overloaded String sLabel Integer iSize Integer eDataType Short eStyle
  1137//        tdRC_Column_Def[] tColumn_Defs
  1138//        Integer iCount
  1139//
  1140//        Get ptColumn_Defs to tColumn_Defs
  1141//        Move (SizeOfArray(tColumn_Defs)) to iCount
  1142//
  1143//        Move sLabel     to tColumn_Defs[iCount].sLabel
  1144//        Move iSize      to tColumn_Defs[iCount].iSize
  1145//        Move eDataType  to tColumn_Defs[iCount].eDataType
  1146//        Move eStyle     to tColumn_Defs[iCount].eStyle
  1147//
  1148//        Set ptColumn_Defs to tColumn_Defs
  1149//        Set Private_piColumn_Count to iCount
  1150//    End_Procedure
  1151
  1152    //For database & SQL files
  1153    Procedure Add_Report_Column String sLabel Integer iSize Integer eDataType Integer eStyle String sTC_Name String sEval
  1154        tdRC_Column_Def[] tColumn_Defs
  1155        Integer iCount
  1156
  1157        Get ptColumn_Defs to tColumn_Defs
  1158        Move (SizeOfArray(tColumn_Defs)) to iCount
  1159
  1160        Move sLabel     to tColumn_Defs[iCount].sLabel
  1161        Move iSize      to tColumn_Defs[iCount].iSize
  1162        Move eDataType  to tColumn_Defs[iCount].eDataType
  1163        Move eStyle     to tColumn_Defs[iCount].eStyle
  1164        If (num_arguments >= 5) Move sTC_Name   to tColumn_Defs[iCount].sTC_Name
  1165        If (num_arguments  = 6) Move sEval      to tColumn_Defs[iCount].sEval
  1166
  1167        Set ptColumn_Defs to tColumn_Defs
  1168        Set Private_piColumn_Count to iCount
  1169    End_Procedure
  1170
  1171    //-------------------------------------------------------------------------
  1172
  1173    Procedure Create_Columns
  1174        Integer iColumnCount iCount
  1175        Integer eDataType
  1176        Handle  hoColumns hoCol
  1177        Variant  vColumns vCol
  1178        tdRC_Column_Def[] tColumn_Defs
  1179        tdRC_Column_Formats tColumn_Formats
  1180
  1181        Get ptColumn_Formats to tColumn_Formats
  1182        Get ptColumn_Defs    to tColumn_Defs
  1183        Get piColumn_Count   to iColumnCount
  1184
  1185        Get phoReportColumns to hoColumns
  1186        Get phoReportColumn  to hoCol
  1187
  1188        Get ComColumns to vColumns
  1189        Set pvComObject of hoColumns to vColumns
  1190
  1191        For iCount from 0 to iColumnCount
  1192            Get ComAdd of hoColumns iCount tColumn_Defs[iCount].sLabel tColumn_Defs[iCount].iSize True to vCol
  1193            Set pvComObject of hoCol to vCol
  1194
  1195            Set ComAlignment       of hoCol to tColumn_Formats[tColumn_Defs[iCount].eDataType].eAlignment
  1196            Set ComHeaderAlignment of hoCol to tColumn_Formats[tColumn_Defs[iCount].eDataType].eAlignment
  1197
  1198            Set ComBestFitMode of hoCol to tColumn_Formats[tColumn_Defs[iCount].eDataType].eBestFit
  1199            //create a hidden column
  1200            If (tColumn_Defs[iCount].iSize  = 0) Begin
  1201                Set ComVisible of hoCol to False
  1202                Set ComShowInFieldChooser of hoCol to False
  1203            End
  1204            If (tColumn_Defs[iCount].eStyle = eRC_Preview) Begin
  1205                If (pbPreviewMode(Self)) Set ComPreviewMode to True
  1206            End
  1207            Send OnCreateColumn iCount hoCol
  1208        Loop
  1209    End_Procedure
  1210
  1211    Procedure OnCreateColumn Integer iColumn Handle hoCol
  1212        // Hook
  1213    End_Procedure
  1214
  1215    //-------------------------------------------------------------------------
  1216
  1217    Procedure DoLoad_Data
  1218        Integer  eDb_Type
  1219        DateTime dtStart dtEnd
  1220
  1221        If (pbColumn_Resort(Self)) Send Remove_Sorted_Columns
  1222        Get peDb_Type to eDb_Type
  1223
  1224        Send OnBefore_Load_Data
  1225        If (piLoad_Monitor(Self) > 0) Send OnLoad_Start (piMax_Rows(Self))
  1226
  1227        Move (CurrentDateTime()) to dtStart
  1228        If (eDb_Type = eRC_db_Table) Send DoLoad_Table
  1229        If (eDb_Type = eRC_db_SQL  ) Send DoLoad_SQL
  1230        If (eDb_Type = eRC_db_Text ) Send DoLoad_Text
  1231        Move (CurrentDateTime()) to dtEnd
  1232        Set ptsTimeSpan_Load to (dtEnd - dtStart)
  1233
  1234        If (piLoad_Monitor(Self) > 0) Send OnLoad_End (piRow_Count(Self))
  1235
  1236        Send DoSetColumnOrdering
  1237        Send DoSetColumnGrouping  
  1238        
  1239        Send OnAfter_Load_Data
  1240    End_Procedure
  1241
  1242    Procedure OnBefore_Load_Data
  1243        // Event Hook
  1244    End_Procedure
  1245
  1246    Procedure OnAfter_Load_Data
  1247        // Event Hook
  1248    End_Procedure
  1249
  1250    Procedure OnLoad_Start Integer iMax_Rows
  1251    End_Procedure
  1252
  1253    Procedure OnLoad_Monitor Integer iRow_Count
  1254    End_Procedure
  1255
  1256    Procedure OnLoad_End Integer iRow_Count
  1257    End_Procedure
  1258
  1259    //-------------------------------------------------------------------------
  1260
  1261    Procedure Set pbGroup_Sorted_Columns Boolean bState
  1262        Variant vOrder
  1263        Handle  hoOrder
  1264
  1265        Get phoReportColumnOrder to hoOrder
  1266        Set ComShowItemsInGroups to bState
  1267
  1268        If (not(bState)) Begin
  1269            Get ComGroupsOrder to vOrder
  1270            Set pvComObject    of hoOrder to vOrder
  1271            Send ComDeleteAll  of hoOrder
  1272
  1273            Get ComSortOrder   to vOrder
  1274            Set pvComObject    of hoOrder to vOrder
  1275            Send ComDeleteAll  of hoOrder
  1276        End
  1277
  1278        Send ComPopulate
  1279    End_Procedure
  1280
  1281    Procedure Remove_Sorted_Columns 
  1282        Variant vOrder
  1283        Handle  hoOrder
  1284
  1285        Get phoReportColumnOrder to hoOrder
  1286        Get ComSortOrder   to vOrder
  1287        Set pvComObject    of hoOrder to vOrder
  1288        Send ComDeleteAll  of hoOrder
  1289        Send ComPopulate
  1290    End_Procedure
  1291
  1292    //=========================================================================
  1293    //Selection
  1294
  1295    Procedure SelectAll
  1296        Integer iCount iRow
  1297        Handle  hoReport_Rows hoRow
  1298        Variant vReport_Rows  vRow
  1299
  1300        Get phoReportRows to hoReport_Rows
  1301        Get phoReportRow  to hoRow
  1302
  1303        Get ComRows to vReport_Rows
  1304        Set pvComObject of hoReport_Rows to vReport_Rows
  1305
  1306        Get ComCount of hoReport_Rows to iCount
  1307        Decrement iCount
  1308        For iRow from 0 to iCount
  1309            Get ComRow of hoReport_Rows iRow to vRow
  1310            Set pvComObject of hoRow to vRow
  1311            Set ComSelected of hoRow to True
  1312        Loop
  1313        Send Selected_Row_Count
  1314    End_Procedure
  1315
  1316    //-------------------------------------------------------------------------
  1317
  1318    Procedure DeselectAll
  1319        Variant vSelected_Rows
  1320        Handle  hoSelected_Rows
  1321
  1322        Get phoReportSelectedRows to hoSelected_Rows
  1323        Get ComSelectedRows to vSelected_Rows
  1324        Set pvComObject of hoSelected_Rows to vSelected_Rows
  1325        Send ComDeleteAll of hoSelected_Rows
  1326        Send Selected_Row_Count
  1327    End_Procedure
  1328
  1329    //-------------------------------------------------------------------------
  1330
  1331    Procedure Invert_Selection
  1332        Integer iCount iRow
  1333        Handle  hoReport_Rows hoRow
  1334        Variant vReport_Rows  vRow
  1335
  1336        Get phoReportRows to hoReport_Rows
  1337        Get phoReportRow  to hoRow
  1338
  1339        Get ComRows to vReport_Rows
  1340        Set pvComObject of hoReport_Rows to vReport_Rows
  1341
  1342        Get ComCount of hoReport_Rows to iCount
  1343        Decrement iCount
  1344        For iRow from 0 to iCount
  1345            Get ComRow of hoReport_Rows iRow to vRow
  1346            Set pvComObject of hoRow to vRow
  1347            Set ComSelected of hoRow to (not(ComSelected(hoRow)))
  1348        Loop
  1349        Send Selected_Row_Count
  1350    End_Procedure
  1351
  1352    //-------------------------------------------------------------------------
  1353
  1354    Procedure Find_Row_Tag String sValue
  1355        Boolean bGroupRow
  1356        Integer iCount iRow
  1357        RowID   Row_ID
  1358        String  sID
  1359        Handle  hoReport_Rows hoRow hoRec
  1360        Variant  vReport_Rows vRow   vRec
  1361
  1362        Get phoReportRows to hoReport_Rows
  1363        Get phoReportRow          to hoRow
  1364        Get phoReportRecord       to hoRec
  1365
  1366        Get ComRows to vReport_Rows
  1367        Set pvComObject of hoReport_Rows to vReport_Rows
  1368
  1369        Get ComCount of hoReport_Rows to iCount
  1370        Decrement iCount
  1371        For iRow from 0 to iCount
  1372            Get ComRow of hoReport_Rows iRow to vRow
  1373            Set pvComObject of hoRow to vRow
  1374
  1375            Get ComGroupRow of hoRow to bGroupRow
  1376            If (not(bGroupRow)) Begin
  1377                Get ComRecord   of hoRow to vRec
  1378                Set pvComObject of hoRec to vRec
  1379
  1380                Get ComTag      of hoRec to sID
  1381
  1382                If (sID = sValue) Begin
  1383                    Set ComFocusedRow to vRow
  1384                    Send OnComFocusChanging vRow Nothing Nothing Nothing
  1385                    Move (iCount + 1) to iRow
  1386                End
  1387            End
  1388        Loop
  1389    End_Procedure
  1390
  1391    //-------------------------------------------------------------------------
  1392
  1393    // Hooks for left click options
  1394    Procedure OnLeftClick_Header Handle hoColumn
  1395    End_Procedure
  1396    Procedure OnLeftClick_GroupBox Handle hoColumn
  1397    End_Procedure
  1398    Procedure OnLeftClick_ReportArea Handle hoColumn Handle hoRow Handle hoItem 
  1399    End_Procedure
  1400    
  1401    // On Mouse Up set Left click options and Right click context menu options
  1402    Procedure OnComMouseUp Short llButton Short llShift Integer llx Integer lly 
  1403        Handle hoHitTestInfo hoReportColumn hoRow hoItem 
  1404        Handle hoContextMenu_Header hoContextMenu_GroupBox hoContextMenu_ReportArea
  1405        Variant vHitTest vColumn vRow vItem 
  1406        Integer iReportInfoCode iIndex iColumns
  1407        String  sName
  1408        
  1409        Get phoHitTestInfo to hoHitTestInfo 
  1410        Get phoContextMenu_Header     to hoContextMenu_Header     
  1411        Get phoContextMenu_GroupBox   to hoContextMenu_GroupBox   
  1412        Get phoContextMenu_ReportArea to hoContextMenu_ReportArea 
  1413        
  1414        Get ComHitTest llx lly to vHitTest 
  1415        Set pvComObject of hoHitTestInfo to vHitTest 
  1416        
  1417        Get ComColumn of hoHitTestInfo to vColumn
  1418        Get ComRow    of hoHitTestInfo to vRow
  1419        Get ComItem   of hoHitTestInfo to vItem
  1420        Get ComHt     of hoHitTestInfo to iReportInfoCode  
  1421
  1422        If (iReportInfoCode = OLExtpHitTestUnknown) Begin
  1423            Set peHitTest to eRC_HitTest_Unknown
  1424
  1425        End
  1426        If (iReportInfoCode = OLExtpHitTestGroupBox) Begin
  1427            Set peHitTest to eRC_HitTest_GroupBox
  1428           
  1429            If ((llButton = 1) and (hoContextMenu_GroupBox > 0)) Begin
  1430                Get phoReportColumn    to hoReportColumn 
  1431                Set pvComObject        of hoReportColumn to vColumn
  1432                Send OnLeftClick_GroupBox hoReportColumn
  1433            End
  1434            If ((llButton = 2) and (hoContextMenu_GroupBox > 0)) Begin
  1435                Send Popup of hoContextMenu_GroupBox
  1436            End
  1437        End
  1438        If (iReportInfoCode = OLExtpHitTestHeader) Begin
  1439            Set peHitTest to eRC_HitTest_Header
  1440
  1441            Get phoReportColumn to hoReportColumn 
  1442            Set pvComObject of hoReportColumn to vColumn
  1443            If (IsComObjectCreated(hoReportColumn)) Begin 
  1444            Get ComIndex    of hoReportColumn to iIndex 
  1445            Set Private_piCurrentColumnIndex  to iIndex
  1446            End
  1447
  1448            If ((llButton = 1) and (hoContextMenu_Header > 0)) Begin
  1449                Get phoReportColumn  to hoReportColumn 
  1450                Set pvComObject      of hoReportColumn to vColumn
  1451                Send OnLeftClick_Header hoReportColumn
  1452            End
  1453            
  1454            If ((llButton = 2) and (hoContextMenu_Header > 0)) Begin
  1455                Send Popup of hoContextMenu_Header
  1456            End
  1457        End
  1458        If (iReportInfoCode = OLExtpHitTestReportArea) Begin
  1459            Set peHitTest to eRC_HitTest_ReportArea
  1460            
  1461            If ((llButton = 1) and (hoContextMenu_ReportArea > 0)) Begin
  1462                Get phoReportColumn to hoReportColumn 
  1463                Set pvComObject     of hoReportColumn to vColumn
  1464                Get phoReportRow    to hoRow
  1465                Set pvComObject     of hoRow  to vRow
  1466                Get phoReportRecordItem to hoItem 
  1467                Set pvComObject     of hoItem to vItem
  1468                Send OnLeftClick_ReportArea hoReportColumn hoRow hoItem 
  1469            End
  1470            If ((llButton = 2) and (hoContextMenu_ReportArea > 0)) Begin
  1471                Send Popup of hoContextMenu_ReportArea
  1472            End
  1473        End
  1474        Set peHitTest to eRC_HitTest_None
  1475    End_Procedure
  1476
  1477    // FreezeColumn option             
  1478    Procedure FreezeColumn
  1479        Integer iIndex 
  1480     
  1481        Get Private_piCurrentColumnIndex  to iIndex
  1482        Set piFreezeColumnsCount          to iIndex 
  1483        Send ComReDraw 
  1484    End_Procedure
  1485
  1486    Procedure FreezeClear
  1487        Set piFreezeColumnsCount to 0 
  1488        Send ComReDraw 
  1489    End_Procedure
  1490
  1491    //-------------------------------------------------------------------------
  1492
  1493    Procedure PreviewReport
  1494        Send ComPrintPreview True
  1495    End_Procedure
  1496
  1497    Procedure PrintReport
  1498        Send ComPrintReport 0
  1499    End_Procedure
  1500
  1501    Procedure CSV_Export
  1502        Boolean bComer
  1503        Integer iCount iRow iColumn iColumn_Count iWidth iChannel
  1504        RowID   Row_ID
  1505        String  sID sValue sExport_File
  1506        Handle  hoReport_Rows hoRow hoRec hoItem
  1507        Variant  vReport_Rows vRow   vRec  vItem
  1508        tdRC_Column_Def[] tColumn_Defs
  1509
  1510        Get phoReportSelectedRows to hoReport_Rows
  1511        Get phoReportRow          to hoRow
  1512        Get phoReportRecord       to hoRec
  1513        Get phoReportRecordItem   to hoItem
  1514
  1515        Get ptColumn_Defs         to tColumn_Defs
  1516        Get piColumn_Count        to iColumn_Count
  1517
  1518        Set psExport_File to ""
  1519        Send Popup of oCSV_Export_Dialog
  1520        Get psExport_File to sExport_File
  1521
  1522        If (sExport_File <> "") Begin
  1523            Move (Seq_New_Channel()) to iChannel
  1524            Direct_Output channel iChannel sExport_File
  1525
  1526            Get ComSelectedRows to vReport_Rows
  1527            Set pvComObject of hoReport_Rows to vReport_Rows
  1528
  1529            // Output header
  1530            Move (False) to bComer
  1531            For iColumn from 0 to iColumn_Count
  1532                If (tColumn_Defs[iColumn].iSize > 0) Begin
  1533                    If (bComer) Write channel iChannel ","
  1534                    Write channel iChannel ('"' + String(tColumn_Defs[iColumn].sLabel) + '"')
  1535                    Move (True) to bComer
  1536                End
  1537            Loop
  1538            Writeln channel iChannel ""
  1539
  1540            Get ComCount of hoReport_Rows to iCount
  1541            Decrement iCount
  1542            For iRow from 0 to iCount
  1543                Get ComRow of hoReport_Rows iRow to vRow
  1544                Set pvComObject of hoRow to vRow
  1545
  1546                If (ComSelected(hoRow)) Begin
  1547                    If (not(ComGroupRow(hoRow))) Begin
  1548                        Get ComRecord of hoRow to vRec
  1549                        Set pvComObject of hoRec to vRec
  1550    
  1551                        Move (False) to bComer
  1552                        For iColumn from 0 to iColumn_Count
  1553                            Get ComItem     of hoRec  iColumn to vItem
  1554                            Set pvComObject of hoItem         to vItem
  1555                            Get ComCaption  of hoItem         to sValue
  1556                            If (tColumn_Defs[iColumn].iSize > 0) Begin
  1557                                If (bComer) Write channel iChannel ","
  1558                                Write channel iChannel ('"' + String(sValue) + '"')
  1559                                Move (True) to bComer
  1560                            End
  1561                        Loop
  1562                        Writeln channel iChannel ""
  1563                    End //bGroupRow
  1564                End
  1565            Loop
  1566            Close_Output  channel iChannel sExport_File
  1567            Send Seq_Release_Channel iChannel
  1568        End
  1569    End_Procedure
  1570
  1571    //-------------------------------------------------------------------------
  1572
  1573    Procedure Process_Rows
  1574        Integer iCount iRow iColumns iCol
  1575        Boolean bCancel
  1576        RowID   Row_ID
  1577        String  sID  sProcess_Type
  1578        Handle  hoReport_Rows hoRow hoRec hoItem
  1579        Variant  vReport_Rows vRow   vRec  vItem
  1580        String[] sData
  1581
  1582        tdRC_Column_Def[] tColumn_Defs
  1583
  1584        Get ptColumn_Defs         to tColumn_Defs
  1585        Get phoReportSelectedRows to hoReport_Rows
  1586        Get phoReportRow          to hoRow
  1587        Get phoReportRecord       to hoRec
  1588        Get phoReportRecordItem   to hoItem
  1589
  1590        Get ComSelectedRows to vReport_Rows
  1591        Set pvComObject of hoReport_Rows to vReport_Rows
  1592
  1593        Get piColumn_Count to iColumns
  1594        Get psProcess_Type to sProcess_Type
  1595
  1596        Get ComCount of hoReport_Rows to iCount
  1597        Decrement iCount
  1598        For iRow from 0 to iCount
  1599            Get ComRow of hoReport_Rows iRow to vRow
  1600            Set pvComObject of hoRow to vRow
  1601
  1602            If (ComSelected(hoRow)) Begin
  1603                Get ComRecord of hoRow to vRec
  1604                Set pvComObject of hoRec to vRec
  1605
  1606                If (not(ComGroupRow(hoRow))) Begin
  1607                    Get ComTag of hoRec to sID
  1608    
  1609                    //--- Get Column Data ---
  1610                    Move (ResizeArray(sData,0)) to sData
  1611                    For iCol from 0 to iColumns
  1612                        Get ComItem of hoRec iCol to vItem
  1613                        Set pvComObject of hoItem to vItem
  1614                        If (tColumn_Defs[iCol].eStyle = eRC_Preview) Begin
  1615                            Get ComPreviewText of hoRec to sData[iCol]
  1616                        End
  1617                        Else Begin
  1618                            If (tColumn_Defs[iCol].eStyle = eRC_CheckBox) Begin
  1619                                Get ComChecked of hoItem to sData[iCol]
  1620                            End
  1621                            Else Begin
  1622                                Get ComValue of hoItem to sData[iCol]
  1623                            End
  1624                        End
  1625                    Loop
  1626                    Set psData_Items to sData
  1627                    //--- Get Column Data ---
  1628    
  1629                    If (pbRowID_Mode(Self)) Begin
  1630                        Move (DeserializeRowID(sID)) to Row_ID
  1631                        Send OnProcess_Rows_RowID Row_ID sProcess_Type (&bCancel)
  1632                    End
  1633                    Else Begin
  1634                       Send OnProcess_Rows sID sProcess_Type (&bCancel)
  1635                    End
  1636                End //bGroupRow
  1637            End
  1638            If (bCancel) Move (iCount+1) to iRow
  1639        Loop
  1640    End_Procedure
  1641
  1642    Procedure OnProcess_Rows String sID String sProcess_Type Boolean ByRef bCancel
  1643        // Event Hook
  1644    End_Procedure
  1645
  1646    Procedure OnProcess_Rows_RowID RowID Row_ID String sProcess_Type Boolean ByRef bCancel
  1647        // Event Hook
  1648    End_Procedure
  1649
  1650    //-------------------------------------------------------------------------
  1651
  1652    Procedure OnComFocusChanging Variant llNewRow Variant llNewColumn Variant llNewItem Boolean ByRef llCancel
  1653        Boolean bFound bGroup
  1654        Integer iTable eDb_Type
  1655        String  sID
  1656        Handle  hoRow hoRec
  1657        Variant  vRow  vRec
  1658
  1659        Get phoReportRow    to hoRow
  1660        Get phoReportRecord to hoRec
  1661
  1662        If (pbActive_Track(Self)) Begin
  1663            Set pvComObject of hoRow to llNewRow
  1664
  1665            Get ComRecord of hoRow to vRec
  1666            Get ComGroupRow of hoRow to bGroup
  1667            If (not(bGroup)) Begin
  1668                Set pvComObject of hoRec to vRec
  1669
  1670                Get ComTag of hoRec to sID
  1671                Set psCurrent_Tag   to sID
  1672
  1673                If (pbRowID_Mode(Self)) Begin
  1674                    If (phoDD(Self) > 0) Begin
  1675                        Move (Main_File(phoDD(Self))) to iTable
  1676                        Send FindByRowId of (phoDD(Self)) iTable (DeserializeRowID(sID))
  1677                        Send OnActive_Track sID
  1678                    End
  1679                 End
  1680                 Else Begin
  1681                    Send OnActive_Track sID
  1682                End
  1683            End
  1684        End
  1685    End_Procedure
  1686
  1687    Procedure OnActive_Track String sID
  1688        // Event Hook
  1689    End_Procedure
  1690
  1691    //-------------------------------------------------------------------------
  1692
  1693    Procedure OnComRowDblClick Variant llRow Variant llItem
  1694        String  sID
  1695        Boolean bGroup
  1696        Handle  hoRow hoRec
  1697        Variant  vRow  vRec
  1698
  1699        Get phoReportRow    to hoRow
  1700        Get phoReportRecord to hoRec
  1701
  1702        Set pvComObject of hoRow to llRow
  1703
  1704        Get ComRecord of hoRow to vRec
  1705        Get ComGroupRow of hoRow to bGroup
  1706        If (not(bGroup)) Begin
  1707            Set pvComObject of hoRec to vRec
  1708
  1709            Get ComTag of hoRec to sID
  1710
  1711            If (pbRowID_Mode(Self)) Begin
  1712                Send OnDouble_Click_RowID (DeserializeRowID(sID))
  1713            End
  1714            Else Begin
  1715                Send OnDouble_Click sID
  1716            End
  1717        End
  1718    End_Procedure
  1719
  1720    Procedure OnDouble_Click String sID
  1721        // Event Hook
  1722    End_Procedure
  1723
  1724    Procedure OnDouble_Click_RowID RowID Row_ID
  1725        // Event Hook
  1726    End_Procedure
  1727
  1728    //=========================================================================
  1729
  1730    Procedure DoBest_Fit
  1731        Integer iColumn iColumn_Count iBestFit
  1732        Handle  hoColumns hoCol
  1733        Variant  vColumns  vCol
  1734
  1735        tdRC_Column_Def[] tColumn_Defs
  1736        tdRC_Column_Formats tColumn_Formats
  1737
  1738        Get ptColumn_Defs    to tColumn_Defs
  1739        Get ptColumn_Formats to tColumn_Formats
  1740
  1741        Get ComColumns to vColumns
  1742        Get Create U_cSigCjComReportColumns to hoColumns
  1743            Set pvComObject of hoColumns to vColumns
  1744
  1745            Get ComCount of hoColumns to iColumn_Count
  1746            Decrement iColumn_Count //make zero based
  1747
  1748            Get Create U_cSigCjComReportColumn to hoCol
  1749
  1750                For iColumn from 0 to iColumn_Count
  1751                    Move tColumn_Formats[tColumn_Defs[iColumn].eDataType].eBestFit to iBestFit
  1752                    If (iBestFit <> eRC_BestFit_None) Begin
  1753                        Get ComColumn of hoColumns iColumn to vCol
  1754                        Set pvComObject of hoCol to vCol
  1755                        Send ComBestFit of hoCol
  1756                    End
  1757                Loop
  1758
  1759            Send Destroy of hoCol
  1760        Send Destroy of hoColumns
  1761    End_Procedure
  1762
  1763    //=========================================================================
  1764
  1765    Procedure Add_Report_Item Handle hoRec Integer iColumn Boolean bRow_Item Integer eDataType Integer eStyle Boolean bRow_Colors tdRC_Column_Format tColumn_Format String sValue
  1766        Boolean   bAdded bItem_Colors
  1767        Integer   iValue iItem_ForeColor iItem_BackColor iDecSep
  1768        Number    nValue
  1769        DateTime dtValue
  1770        Handle   hoItem
  1771        Variant   vItem                    
  1772        String    sPreviewText
  1773        Get phoReportRecordItem to hoItem
  1774        Move False to bAdded
  1775         
  1776        If (eStyle = eRC_Preview) Begin
  1777            Get ComPreviewText of hoRec to sPreviewText
  1778            If (sPreviewText <> "") Move (Append(sPreviewText, (" " + String(Trim(sValue))) )) to sPreviewText
  1779            Else Move (Trim(sValue)) to sPreviewText
  1780            Set ComPreviewText of hoRec to sPreviewText 
  1781        End
  1782         
  1783        If (eStyle = eRC_CheckBox) Begin
  1784            Get ComAddItem  of hoRec sValue to vItem
  1785            Set pvComObject of hoItem to vItem
  1786
  1787            Set ComHasCheckBox of hoItem to True
  1788            Set ComAlignment   of hoItem to OLExtpAlignmentIconCenter
  1789            Set ComChecked     of hoItem to sValue
  1790            Set ComCaption     of hoItem to " " // This stops the value from being shown
  1791
  1792            Move True to bAdded
  1793        End
  1794
  1795        If (eStyle = eRC_Standard) Begin
  1796            //Date, DateTime & Time - Must use DateTime var so report control
  1797            //sorts column correctly
  1798            If ((eDataType = eRC_Date    ) or ;
  1799                (eDataType = eRC_DateTime) or ;
  1800                (eDataType = eRC_DTString) or ;
  1801                (eDataType = eRC_Time    )) Begin
  1802
  1803                //Expects DD/MM/CCYY HH:MM:SS for none sql tables CCYY/MM/DD HH:MM:SS for sql tables
  1804
  1805                //Add date
  1806                If ((eDataType = eRC_Date) or (eDataType = eRC_DateTime) or (eDataType = eRC_DTString)) Begin
  1807                    If ((peDb_Type(Self) = eRC_db_SQL) and (eDataType <> eRC_DTString)) Begin
  1808                        Move (DateSetDay   (dtValue, (Mid(sValue,2,9)))) to dtValue
  1809                        Move (DateSetMonth (dtValue, (Mid(sValue,2,6)))) to dtValue
  1810                        Move (DateSetYear  (dtValue, (Mid(sValue,4,1)))) to dtValue
  1811                    End
  1812                    Else Begin
  1813                        Move (DateSetDay   (dtValue, (DateGetDay(sValue))))   to dtValue
  1814                        Move (DateSetMonth (dtValue, (DateGetMonth(sValue)))) to dtValue
  1815                        Move (DateSetYear  (dtValue, (DateGetYear(sValue))))  to dtValue
  1816                    End
  1817                End
  1818                //Add Time
  1819                If ((eDataType = eRC_DateTime) or (eDataType = eRC_Time) or eDataType = eRC_DTString) Begin
  1820                    If ((peDb_Type(Self) = eRC_db_SQL) and (eDataType <> eRC_DTString)) Begin
  1821                        Move (DateSetHour   (dtValue, (Mid(sValue,2,12)))) to dtValue
  1822                        Move (DateSetMinute (dtValue, (Mid(sValue,2,15)))) to dtValue
  1823                        Move (DateSetSecond (dtValue, (Mid(sValue,2,18)))) to dtValue
  1824                    End
  1825                    Else Begin 
  1826                        Move (DateSetHour   (dtValue, (DateGetHour(sValue))))   to dtValue
  1827                        Move (DateSetMinute (dtValue, (DateGetMinute(sValue)))) to dtValue
  1828                        Move (DateSetSecond (dtValue, (DateGetSecond(sValue)))) to dtValue
  1829                    End
  1830                End
  1831                If ((dtValue = "01/01/1753 00:00:00") or (dtValue = "00:00:00" )) Begin
  1832                    Get ComAddItem of hoRec "" to vItem // Don't show blank dates
  1833                End
  1834                Else Get ComAddItem of hoRec dtValue to vItem
  1835                Move True to bAdded
  1836            End
  1837
  1838            If (eDataType = eRC_Currency) Begin
  1839                Move sValue to nValue
  1840                Get ComAddItem of hoRec nValue to vItem
  1841                Set pvComObject of hoItem to vItem
  1842                Move (ToOEM(FormatCurrency(nValue,2))) to sValue
  1843                Set ComCaption  of hoItem to sValue
  1844                Move True to bAdded
  1845            End
  1846
  1847            If (eDataType = eRC_Integer) Begin
  1848                Get ComAddItem of hoRec (Integer(sValue)) to vItem
  1849                Move True to bAdded
  1850            End
  1851
  1852            If ((eDataType = eRC_Real) or (eDataType = eRC_Decimal)) Begin
  1853                
  1854                Get_Attribute DF_DECIMAL_SEPARATOR to iDecSep
  1855                If ((iDecSep = 46) and Pos(",", sValue)) Begin
  1856                    Set_Attribute DF_DECIMAL_SEPARATOR to 44
  1857                    Move sValue to nValue
  1858                    Set_Attribute DF_DECIMAL_SEPARATOR to iDecSep
  1859                End
  1860                Else If ((iDecSep = 44) and Pos(".", sValue)) Begin
  1861                    Set_Attribute DF_DECIMAL_SEPARATOR to 46
  1862                    Move sValue to nValue
  1863                    Set_Attribute DF_DECIMAL_SEPARATOR to iDecSep
  1864                End
  1865                Else Begin
  1866                   Move sValue to nValue 
  1867                End
  1868
  1869                Get ComAddItem of hoRec nValue to vItem
  1870                Set pvComObject of hoItem to vItem
  1871                Set ComCaption  of hoItem to sValue
  1872                Move True to bAdded
  1873            End
  1874
  1875            //All previously unhandled data types
  1876            If (not(bAdded)) Begin
  1877                Get ComAddItem of hoRec sValue to vItem
  1878                Move True to bAdded
  1879            End
  1880        End
  1881
  1882        //Check just incase an invalid Style is passed
  1883        If (not(bAdded)) Begin
  1884            //Add empty item
  1885            Get ComAddItem of hoRec "" to vItem
  1886        End
  1887
  1888        //Now format the column
  1889        If (bAdded) Begin
  1890            Set pvComObject of hoItem to vItem
  1891
  1892            //Alignment done at column level
  1893            If (not(bRow_Colors) and tColumn_Format.bColorColumn) Begin
  1894                If ((eDataType = eRC_Currency) and (sValue < 0)) Begin
  1895                    Set ComBackColor of hoItem to tColumn_Format.iBackColor_Neg
  1896                    Set ComForeColor of hoItem to tColumn_Format.iForeColor_Neg
  1897                End
  1898                Else Begin
  1899                    Set ComBackColor of hoItem to tColumn_Format.iBackColor
  1900                    Set ComForeColor of hoItem to tColumn_Format.iForeColor
  1901                End
  1902            End
  1903
  1904            Set ComBold of hoItem to tColumn_Format.bBold
  1905            If (tColumn_Format.sFormat <> "") Begin
  1906                Set ComFormat of hoItem to tColumn_Format.sFormat
  1907            End
  1908            If (bRow_Item) Begin
  1909                If ((eDataType = eRC_Date) or (eDataType = eRC_DateTime) or (eDataType = eRC_DTString)) Begin
  1910                    // Do not process date formats and codejock stores them correctly
  1911                End
  1912                Else Get ComValue of hoItem to sValue 
  1913                Send OnCreateRowItem iColumn hoItem sValue 
  1914            End
  1915            If (bRow_Colors) Begin
  1916                If ((eDataType = eRC_Date) or (eDataType = eRC_DateTime) or (eDataType = eRC_DTString)) Begin
  1917                    // Do not process date formats and codejock stores them correctly
  1918                End
  1919                Else Get ComValue of hoItem to sValue 
  1920                // Send OnSetRowColor   iColumn sValue
  1921            End
  1922
  1923            Get pbItem_Colors to bItem_Colors 
  1924            
  1925            If (bItem_Colors) Begin
  1926                Set piItem_ForeColor to 0
  1927                Set piItem_BackColor to 0
  1928                Send OnSetItemColor iColumn sValue
  1929                Get piItem_ForeColor to iItem_ForeColor
  1930                Get piItem_BackColor to iItem_BackColor
  1931                If (iItem_ForeColor) Set ComForeColor of hoItem to iItem_ForeColor
  1932                If (iItem_BackColor) Set ComBackColor of hoItem to iItem_BackColor
  1933            End               
  1934        End
  1935    End_Procedure
  1936
  1937    Procedure OnCreateRowItem Integer iColumn Handle hoItem String sValue
  1938        // Hook
  1939    End_Procedure
  1940
  1941    //=========================================================================
  1942    //Table Data
  1943
  1944    Procedure DoLoad_Table
  1945        Boolean bFound bRow_Colors bRow_Item
  1946        Integer iRow_Count iMax_Rows iColumn iColumn_Count iRef_Column 
  1947        Integer iRow_ForeColor iRow_BackColor iItem_ForeColor iItem_BackColor iLoad_Monitor
  1948        Handle  hoRecords hoRec hoItem
  1949        Variant  vRecords  vRec  vItem
  1950        String  sValue sTag
  1951
  1952        tdRC_Column_Def[] tColumn_Defs
  1953        tdRC_Column_Formats tColumn_Formats
  1954
  1955        //Table specific
  1956        Boolean bDescending bDeferredState
  1957        Handle  hoDD
  1958        Integer iFile_Number iIndex iTable
  1959        RowID   Row_ID
  1960
  1961        Send Cursor_Wait of Cursor_Control
  1962
  1963        Get phoDD to hoDD
  1964        If (hoDD > 0) Begin
  1965            Get phoReportRecordItem to hoItem
  1966            Get phoReportRecord     to hoRec
  1967            Get phoReportRecords    to hoRecords
  1968            Get ComRecords          to vRecords
  1969            Set pvComObject of hoRecords to vRecords
  1970
  1971            Get ptColumn_Formats to tColumn_Formats
  1972            Get ptColumn_Defs    to tColumn_Defs
  1973            Get piColumn_Count   to iColumn_Count
  1974            Get piRef_Column     to iRef_Column
  1975            Get piMax_Rows       to iMax_Rows
  1976            Get pbRow_Colors     to bRow_Colors
  1977            Get pbRow_Item       to bRow_Item
  1978            Get piLoad_Monitor   to iLoad_Monitor
  1979            
  1980            Get piTable_Index to iIndex
  1981            Get pbDescending  to bDescending
  1982            Get Main_File     of hoDD to iTable
  1983
  1984            If (peDataflex_Table_Find_Method(Self) = eRC_Find_Normal) Begin
  1985                Send Clear of hoDD
  1986                If (bDescending) Send Find of hoDD LAST_RECORD iIndex
  1987                Else             Send Find of hoDD GE          iIndex
  1988            End
  1989            Else If (peDataflex_Table_Find_Method(Self) = eRC_Find_RequestRead) Begin
  1990                Send Clear of hoDD
  1991                If (bDescending) Send Request_Read of hoDD LAST_RECORD iTable iIndex
  1992                Else             Send Request_Read of hoDD GE          iTable iIndex  
  1993            End
  1994            Else If (peDataflex_Table_Find_Method(Self) = eRC_Find_Constrained) Begin
  1995                Constrained_Clear (If(bDescending,LE,GE)) iTable by iIndex
  1996                Constrained_Find Next 
  1997            End
  1998
  1999            Move (Found) to bFound
  2000            While (bFound)
  2001                Get ComAdd of hoRecords to vRec
  2002                Set pvComObject of hoRec to vRec
  2003                Increment iRow_Count
  2004
  2005                //Reset row Colors
  2006                If (bRow_Colors) Begin
  2007                    Set piRow_ForeColor to 0
  2008                    Set piRow_BackColor to 0
  2009                End
  2010
  2011                For iColumn from 0 to iColumn_Count
  2012                    //Item Data
  2013                    If (Trim(tColumn_Defs[iColumn].sEval) = "") Move tColumn_Defs[iColumn].sTC_Name to sValue
  2014                    Else                                        Move tColumn_Defs[iColumn].sEval    to sValue
  2015                    Move (Eval(sValue)) to sValue
  2016
  2017                    //Add the item
  2018                    Send Add_Report_Item hoRec                                            ;
  2019                                         iColumn                                          ;
  2020                                         bRow_Item                                        ;
  2021                                         tColumn_Defs[iColumn].eDataType                  ;
  2022                                         tColumn_Defs[iColumn].eStyle                     ;
  2023                                         bRow_Colors                                      ;
  2024                                         tColumn_Formats[tColumn_Defs[iColumn].eDataType] ;
  2025                                         (Trim(sValue))
  2026
  2027                    //Tag value
  2028                    If (iColumn = iRef_Column) Move sValue to sTag
  2029
  2030                    //Set row Colors
  2031                    If (bRow_Colors) Send OnSetRowColor iColumn sValue
  2032                Loop
  2033
  2034                //Add Tag
  2035                If (pbRowID_Mode(Self)) Begin
  2036                    Get Main_File of (phoDD(Self)) to iFile_Number
  2037                    Move (GetRowID(iFile_Number)) to Row_ID
  2038                    Set ComTag of hoRec to (SerializeRowId(Row_ID))
  2039                End
  2040                Else Begin
  2041                    Set ComTag of hoRec to sTag
  2042                End
  2043
  2044                //Set row Color
  2045                If (bRow_Colors) Begin
  2046                    Get piRow_ForeColor to iRow_ForeColor
  2047                    Get piRow_BackColor to iRow_BackColor
  2048                    If ((iRow_ForeColor) or (iRow_BackColor)) Begin
  2049                        For iColumn from 0 to iColumn_Count
  2050                            Get ComItem      of hoRec iColumn to vItem
  2051                            Set pvComObject  of hoItem to vItem
  2052                            Get ComForeColor of hoItem to iItem_ForeColor
  2053                            Get ComBackColor of hoItem to iItem_BackColor
  2054                            If ((iRow_ForeColor) and (iItem_ForeColor = -1)) Set ComForeColor of hoItem to iRow_ForeColor
  2055                            If ((iRow_BackColor) and (iItem_BackColor = -1)) Set ComBackColor of hoItem to iRow_BackColor
  2056                        Loop
  2057                    End
  2058                End
  2059                
  2060                If (peDataflex_Table_Find_Method(Self) = eRC_Find_Normal) Begin
  2061                    If (bDescending) Send Find of hoDD LT iIndex
  2062                    Else             Send Find of hoDD GT iIndex
  2063                End
  2064                Else If (peDataflex_Table_Find_Method(Self) = eRC_Find_RequestRead) Begin
  2065                    If (bDescending) Send Request_Read of hoDD LT iTable iIndex
  2066                    Else             Send Request_Read of hoDD GT iTable iIndex
  2067                End
  2068                Else If (peDataflex_Table_Find_Method(Self) = eRC_Find_Constrained) Begin
  2069                    Constrained_Find Next     
  2070                End
  2071
  2072                Move (Found) to bFound
  2073                If ((bFound) and (iMax_Rows > 0)) Move (iRow_Count < iMax_Rows) to bFound
  2074
  2075                If (iLoad_Monitor > 0) Begin
  2076                    If ((iRow_Count > iLoad_Monitor) and (Mod(iRow_Count, iLoad_Monitor) = 0)) Send OnLoad_Monitor iRow_Count
  2077                End
  2078            Loop
  2079            // Send DoBest_Fit
  2080        End
  2081
  2082        Set Private_piRow_Count to iRow_Count
  2083        Send Cursor_Ready of Cursor_Control
  2084    End_Procedure
  2085
  2086    //=========================================================================
  2087    //SQL Data
  2088
  2089    Procedure Build_SQL_Statement
  2090        String  sSQL_Statement sSQL_Select sSQL_From sSQL_Where sSQL_OrderBy
  2091        String  sFieldName
  2092        Boolean bCase
  2093        Integer iColumnCount iCount iIndex iSegments iColumn
  2094        Handle  hoDD hTable
  2095        tdRC_Column_Def[] tColumn_Defs
  2096
  2097        Send OnBuild_SQL_Statement
  2098
  2099        Get phoDD         to hoDD
  2100        Get piTable_Index to iIndex
  2101        Get psSQL_Select  to sSQL_Select
  2102        Get psSQL_From    to sSQL_From
  2103        Get psSQL_Where   to sSQL_Where
  2104        Get psSQL_OrderBy to sSQL_OrderBy
  2105        Get pbSQL_Case    to bCase
  2106
  2107        //---------------------------------------------------------------------
  2108        //Sort out Select
  2109        If (sSQL_Select = "") Begin
  2110            Get ptColumn_Defs  to tColumn_Defs
  2111            Get piColumn_Count to iColumnCount
  2112            For iCount from 0 to iColumnCount
  2113                If (iCount > 0) Move (Append(sSQL_Select,", ")) to sSQL_Select
  2114                If ((bCase = True) and (tColumn_Defs[iCount].sEval <> "")) Begin
  2115                    Move (Append(sSQL_Select,String(tColumn_Defs[iCount].sEval))) to sSQL_Select
  2116                End
  2117                Else Move (Append(sSQL_Select,String(tColumn_Defs[iCount].sTC_Name))) to sSQL_Select
  2118            Loop
  2119            Set psSQL_Select  to sSQL_Select
  2120        End
  2121
  2122        //---------------------------------------------------------------------
  2123        //Sort out From
  2124        If (sSQL_From = "") Begin
  2125            Get Main_File of hoDD to hTable
  2126            Get_Attribute DF_FILE_LOGICAL_NAME of hTable to sSQL_From
  2127            Set psSQL_From    to sSQL_From
  2128        End
  2129
  2130        //---------------------------------------------------------------------
  2131        //Sort out Where
  2132        //This has to be specified by the user
  2133
  2134        //---------------------------------------------------------------------
  2135        //Sort out OrderBy
  2136        If ((sSQL_OrderBy = "") and (iIndex > 0)) Begin
  2137            Get Main_File of hoDD to hTable
  2138            Get_Attribute DF_INDEX_NUMBER_SEGMENTS of hTable iIndex to iSegments
  2139            For iCount from 1 to iSegments
  2140                Get_Attribute DF_INDEX_SEGMENT_FIELD of hTable iIndex iCount to iColumn
  2141                Get_Attribute DF_FIELD_NAME of hTable iColumn to sSQL_OrderBy
  2142                Move (Append(sSQL_OrderBy,(String(sSQL_OrderBy) * " "))) to sSQL_OrderBy
  2143            Loop
  2144        End
  2145
  2146        //---------------------------------------------------------------------
  2147        // Build the statement
  2148        If (psSQL_Select(Self)  <> "") Move (Append(sSQL_Statement,("select"    * String(psSQL_Select(Self))  ))) to sSQL_Statement
  2149        If (psSQL_From(Self)    <> "") Move (Append(sSQL_Statement,(" from"     * String(psSQL_From(Self))    ))) to sSQL_Statement
  2150        If (psSQL_Where(Self)   <> "") Move (Append(sSQL_Statement,(" where"    * String(psSQL_Where(Self))   ))) to sSQL_Statement
  2151        If (psSQL_OrderBy(Self) <> "") Move (Append(sSQL_Statement,(" order by" * String(psSQL_OrderBy(Self)) ))) to sSQL_Statement
  2152
  2153        Set psSQL_Select_Statment to sSQL_Statement
  2154    End_Procedure
  2155
  2156    Procedure OnBuild_SQL_Statement
  2157        //Event Hook
  2158    End_Procedure
  2159
  2160    //------------------------------------------------------ 
  2161    //
  2162    // Function   : piDriverIndex
  2163    // 
  2164    // Scope      : Public
  2165    //
  2166    // Parameters : sDriver -  Name of driver as returned by DF_FILE_DRIVER
  2167    //
  2168    // Returns    : Integer - ID of the driver, if present.
  2169    // 
  2170    // Purpose    : Different workstations may have different drivers installed. This functions (lifted from the help)
  2171    //              loops through a machines installed drivers matching their names to the passed value. If found
  2172    //              the this index can be used in the "Driver" series of Get_Attribute for querying further values
  2173    //
  2174    // Notes      : 
  2175    //
  2176    //------------------------------------------------------      
  2177    Function piDriverIndex String sDriver Returns Integer    
  2178        String sCurrentDriver    
  2179        Integer iDriver    
  2180        Integer iNumDrivers    
  2181         
  2182        Get_Attribute DF_NUMBER_DRIVERS to iNumDrivers    
  2183        For iDriver from 1 to iNumDrivers    
  2184            Get_Attribute DF_DRIVER_NAME of iDriver to sCurrentDriver    
  2185            If (Uppercase(sDriver) = Uppercase(sCurrentDriver)) ;    
  2186                Function_Return iDriver    
  2187        Loop
  2188    
  2189        Function_Return 0    
  2190    End_Function // piDriverIndex String sDriver Returns Integer    
  2191
  2192
  2193    //------------------------------------------------------ 
  2194    //
  2195    // Function   : psConnectionStringFromID
  2196    // 
  2197    // Scope      : Public
  2198    //
  2199    // Parameters : sDriver -  Name of driver as returned by DF_FILE_DRIVER
  2200    //              sConnectionID - "Fake" login with a connection ID instead of connection string
  2201    //
  2202    // Returns    : String - connection string
  2203    // 
  2204    // Purpose    : Having found the driver in use. Walk through its registered connection ID until
  2205    //              we find the one one we're interested in a return its connection string.
  2206    //
  2207    // Notes      : 
  2208    //
  2209    //------------------------------------------------------   
  2210    Function psConnectionStringFromID String sDriver String sConnectionID Returns String
  2211        Integer iDriver iConn iNumConn
  2212        String sID sConnectionString
  2213        
  2214        Get piDriverIndex sDriver to iDriver    
  2215        If (iDriver) Begin
  2216            //Walk through all Connection IDs for the relevant driver. Exit when we find something (or run out of IDs)
  2217            Move 0 to iConn
  2218            Get_Attribute DF_DRIVER_NUMBER_CONNECTION_IDS of iDriver to iNumConn            
  2219            While ((iConn < iNumConn) and (sConnectionString = ""))
  2220                
  2221                Get_Attribute DF_DRIVER_CONNECTION_ID of iDriver iConn to sID
  2222                If (Uppercase(sConnectionID) = Uppercase("DFCONNID=" + sID)) ;
  2223                    Get_Attribute DF_DRIVER_CONNECTION_ID_STRING of iDriver iConn to sConnectionString
  2224                    
  2225                Move (iConn + 1) to iConn    
  2226            Loop
  2227        End
  2228        
  2229        Function_Return sConnectionString        
  2230    End_Function // psConnectionStringFromID String sDriver String sConnectionID Returns String    
  2231
  2232    //-------------------------------------------------------------------------
  2233
  2234    Procedure DoLoad_SQL
  2235        Boolean bFound bRow_Colors bRow_Item
  2236        Integer iRow_Count iMax_Rows iColumn iColumn_Count iRef_Column 
  2237        Integer iRow_ForeColor iRow_BackColor iItem_ForeColor iItem_BackColor iLoad_Monitor
  2238        Handle  hoRecords hoRec hoItem
  2239        Variant  vRecords  vRec  vItem
  2240        String  sValue sTag
  2241
  2242        tdRC_Column_Def[] tColumn_Defs
  2243        tdRC_Column_Formats tColumn_Formats
  2244
  2245        //SQL specific
  2246        Boolean  bCase
  2247        Integer  iFetchResult 
  2248        Handle   hoSQL hoDD hdbc hstmt hTable
  2249        String   sDriver sConnection sSQL_Select_Statment                  
  2250        DateTime dtStart dtEnd
  2251
  2252        Send Cursor_Wait of Cursor_Control
  2253
  2254        Get phoReportRecordItem to hoItem
  2255        Get phoReportRecord     to hoRec
  2256        Get phoReportRecords    to hoRecords
  2257        Get ComRecords          to vRecords
  2258        Set pvComObject of hoRecords to vRecords
  2259
  2260        Get ptColumn_Formats to tColumn_Formats
  2261        Get ptColumn_Defs    to tColumn_Defs
  2262        Get piColumn_Count   to iColumn_Count
  2263        Get piRef_Column     to iRef_Column
  2264        Get piMax_Rows       to iMax_Rows
  2265        Get pbRow_Colors     to bRow_Colors
  2266        Get pbRow_Item       to bRow_Item
  2267        Get piLoad_Monitor   to iLoad_Monitor
  2268
  2269        Move (CurrentDateTime()) to dtStart
  2270
  2271        If (psSQL_Select_Statment(Self) = "") Send Build_SQL_Statement
  2272        Get psSQL_Select_Statment(Self)) to sSQL_Select_Statment
  2273
  2274        Get phoDD to hoDD
  2275        Get Main_File of hoDD to hTable
  2276        Get pbSQL_Case        to bCase
  2277
  2278        #IFDEF SigCj_Use_Mertech_Drivers
  2279            Get CreateResultSet to hoSQL
  2280            Send ExecuteQuery of hoSQL sSQL_Select_Statment
  2281        #ELSE
  2282            Move (oSQL_Report_Handler(Self)) to hoSQL
  2283
  2284            Get_Attribute DF_FILE_DRIVER of hTable to sDriver
  2285            Get_Attribute DF_FILE_LOGIN  of hTable to sConnection            
  2286            
  2287            // If have a connection ID. Translate it into a proper connection string
  2288            If (Uppercase(left(sConnection, 9)) = "DFCONNID=") ;
  2289                Get psConnectionStringFromID sDriver sConnection to sConnection            
  2290                        
  2291            Get SQLConnect of hoSQL ;
  2292                sDriver ;
  2293                sConnection to hdbc
  2294
  2295            Get SQLOpen        of hdbc to hstmt
  2296            Send SQLExecDirect of hstmt sSQL_Select_Statment
  2297        #ENDIF
  2298
  2299        Move (CurrentDateTime()) to dtEnd
  2300        Set ptsTimeSpan_SQL to (dtEnd - dtStart)
  2301
  2302        Repeat
  2303            #IFDEF SigCj_Use_Mertech_Drivers
  2304                Send Next of hoSQL
  2305                Move (Found) to iFetchResult
  2306            #ELSE
  2307                Get SQLFetch of hstmt to iFetchResult
  2308            #ENDIF
  2309
  2310            If (iFetchResult <> 0) Begin
  2311                If (iRow_Count = 1) Begin
  2312                    Move (CurrentDateTime()) to dtEnd
  2313                    Set ptsTimeSpan_SQL to (dtEnd - dtStart)
  2314                End
  2315
  2316                Get ComAdd of hoRecords to vRec
  2317                Set pvComObject of hoRec to vRec
  2318                Increment iRow_Count
  2319
  2320                //Reset row Colors
  2321                If (bRow_Colors) Begin
  2322                    Set piRow_ForeColor to 0 // Reset Row ForeColor
  2323                    Set piRow_BackColor to 0 // Reset Row BackColor
  2324                End
  2325
  2326                For iColumn from 0 to iColumn_Count
  2327                    // Get the Column data
  2328                    #IFDEF SigCj_Use_Mertech_Drivers
  2329                        Get getString of hoSQL (iColumn +1) to sValue
  2330                    #ELSE
  2331                        Get SQLColumnValue of hstmt (iColumn +1) to sValue
  2332                    #ENDIF
  2333
  2334                    Move (Trim(sValue)) to sValue
  2335
  2336                    If (not(bCase) and (Trim(tColumn_Defs[iColumn].sEval) <> "")) Begin
  2337                        Move (Replace(tColumn_Defs[iColumn].sTC_Name,tColumn_Defs[iColumn].sEval,('"' + String(sValue) + '"'))) to sValue
  2338                        Move (Eval(sValue)) to sValue
  2339                    End
  2340
  2341                    //Add the item
  2342                    Send Add_Report_Item hoRec                                            ;
  2343                                         iColumn                                          ;
  2344                                         bRow_Item                                        ;
  2345                                         tColumn_Defs[iColumn].eDataType                  ;
  2346                                         tColumn_Defs[iColumn].eStyle                     ;
  2347                                         bRow_Colors                                      ;
  2348                                         tColumn_Formats[tColumn_Defs[iColumn].eDataType] ;
  2349                                         (Trim(sValue))
  2350
  2351                    //Tag value
  2352                    If (iColumn = iRef_Column) Move sValue to sTag
  2353
  2354                    //Set row Colors
  2355                    If (bRow_Colors) Send OnSetRowColor iColumn sValue
  2356                Loop
  2357
  2358                //Add Tag
  2359                Set ComTag of hoRec to sTag
  2360
  2361                //Set row Color
  2362                If (bRow_Colors) Begin
  2363                    Get piRow_ForeColor to iRow_ForeColor
  2364                    Get piRow_BackColor to iRow_BackColor
  2365                    If ((iRow_ForeColor) or (iRow_BackColor)) Begin
  2366                        For iColumn from 0 to iColumn_Count
  2367                            Get ComItem      of hoRec iColumn to vItem
  2368                            Set pvComObject  of hoItem to vItem
  2369                            Get ComForeColor of hoItem to iItem_ForeColor
  2370                            Get ComBackColor of hoItem to iItem_BackColor
  2371                            If ((iRow_ForeColor) and (iItem_ForeColor = -1)) Set ComForeColor of hoItem to iRow_ForeColor
  2372                            If ((iRow_BackColor) and (iItem_BackColor = -1)) Set ComBackColor of hoItem to iRow_BackColor
  2373                        Loop
  2374                    End
  2375                End
  2376
  2377                If ((iMax_Rows > 0) and (iRow_Count = iMax_Rows)) Begin
  2378                    //Max rows specified and reach so bomb repeat loop
  2379                    Move 0 to iFetchResult
  2380                End
  2381            End
  2382            If (iLoad_Monitor > 0) Begin
  2383                If ((iRow_Count > iLoad_Monitor) and (Mod(iRow_Count, iLoad_Monitor) = 0)) Send OnLoad_Monitor iRow_Count
  2384            End
  2385        Until (iFetchResult = 0)
  2386
  2387        #IFDEF SigCj_Use_Mertech_Drivers
  2388            Send Destroy_Object of hoSQL
  2389        #ELSE
  2390            Send SQLClose       of hstmt
  2391            Send SQLDisconnect  of hdbc
  2392        #ENDIF
  2393
  2394        Set Private_piRow_Count to iRow_Count
  2395
  2396        //Send DoBest_Fit
  2397
  2398        Send Cursor_Ready of Cursor_Control
  2399    End_Procedure
  2400
  2401    Procedure OnSetRowColor Integer iColumn String sValue
  2402        /// Hook
  2403        // If ((iColumn = 11) and (sValue = "Equipment")) Begin
  2404        //    Set piRow_ForeColor to 255
  2405        //    Set piRow_BackColor to clFuchsia
  2406        // End
  2407    End_Procedure
  2408
  2409    Procedure OnSetItemColor Integer iColumn String sValue
  2410        /// Hook
  2411        // If ((iColumn = 11) and (sValue = "Equipment")) Begin
  2412        //    Set piItem_ForeColor to 255
  2413        //    Set piItem_BackColor to clFuchsia
  2414        // End
  2415    End_Procedure
  2416
  2417    //=========================================================================
  2418    //Text Data
  2419
  2420    Procedure DoLoad_Text
  2421        Boolean bFound bRow_Colors bRow_Item
  2422        Integer iRow_Count iMax_Rows iColumn iColumn_Count iRef_Column 
  2423        Integer iRow_ForeColor iRow_BackColor iItem_ForeColor iItem_BackColor iLoad_Monitor
  2424        Handle  hoRecords hoRec hoItem
  2425        Variant  vRecords  vRec  vItem
  2426        String  sValue sTag
  2427
  2428        tdRC_Column_Def[] tColumn_Defs
  2429        tdRC_Column_Formats tColumn_Formats
  2430
  2431        //Table specific
  2432        String[] sData
  2433
  2434        Send Cursor_Wait of Cursor_Control
  2435
  2436        Send OnOpen_DataSource
  2437        If (not(pbEOF(Self))) Begin
  2438            Get phoReportRecordItem to hoItem
  2439            Get phoReportRecord     to hoRec
  2440            Get phoReportRecords    to hoRecords
  2441            Get ComRecords          to vRecords
  2442            Set pvComObject of hoRecords to vRecords
  2443
  2444            Get ptColumn_Formats to tColumn_Formats
  2445            Get ptColumn_Defs    to tColumn_Defs
  2446            Get piColumn_Count   to iColumn_Count
  2447            Get piRef_Column     to iRef_Column
  2448            Get piMax_Rows       to iMax_Rows
  2449            Get pbRow_Colors    to bRow_Colors
  2450            Get pbRow_Item       to bRow_Item
  2451            Get piLoad_Monitor   to iLoad_Monitor
  2452
  2453            Move True to bFound
  2454            While (bFound)
  2455                Move (ResizeArray(sData,0)) to sData
  2456                Set psData_Items to sData
  2457
  2458                Send OnPrepare_RowData
  2459                If (not(pbEOF(Self))) Begin
  2460                    Get psData_Items   to sData
  2461
  2462                    Get ComAdd of hoRecords to vRec
  2463                    Set pvComObject of hoRec to vRec
  2464                    Increment iRow_Count
  2465
  2466                    //Reset row Colors
  2467                    If (bRow_Colors) Begin
  2468                        Set piRow_ForeColor to 0
  2469                        Set piRow_BackColor to 0
  2470                    End
  2471
  2472                    For iColumn from 0 to iColumn_Count
  2473                        //Item Data
  2474                        Move sData[iColumn] to sValue
  2475
  2476                        //Add the item
  2477                        Send Add_Report_Item hoRec                                            ;
  2478                                             iColumn                                          ;
  2479                                             bRow_Item                                        ;
  2480                                             tColumn_Defs[iColumn].eDataType                  ;
  2481                                             tColumn_Defs[iColumn].eStyle                     ;
  2482                                             bRow_Colors                                      ;
  2483                                             tColumn_Formats[tColumn_Defs[iColumn].eDataType] ;
  2484                                             (Trim(sValue))
  2485
  2486                        //Set row Colors
  2487                        If (bRow_Colors) Send OnSetRowColor iColumn sValue
  2488                    Loop
  2489
  2490                    //Add Tag
  2491                    If (pbAuto_Row_Ref(Self)) Begin
  2492                        Set ComTag of hoRec to iRow_Count
  2493                    End
  2494                    Else Begin
  2495                        Set ComTag of hoRec to sData[iRef_Column]
  2496                    End
  2497
  2498                    //Set row Color
  2499                    If (bRow_Colors) Begin
  2500                        Get piRow_ForeColor to iRow_ForeColor
  2501                        Get piRow_BackColor to iRow_BackColor
  2502                        If ((iRow_ForeColor) or (iRow_BackColor)) Begin
  2503                            For iColumn from 0 to iColumn_Count
  2504                                Get ComItem      of hoRec iColumn to vItem
  2505                                Set pvComObject  of hoItem to vItem
  2506                                Get ComForeColor of hoItem to iItem_ForeColor
  2507                                Get ComBackColor of hoItem to iItem_BackColor
  2508                                If ((iRow_ForeColor) and (iItem_ForeColor = -1)) Set ComForeColor of hoItem to iRow_ForeColor
  2509                                If ((iRow_BackColor) and (iItem_BackColor = -1)) Set ComBackColor of hoItem to iRow_BackColor
  2510                            Loop
  2511                        End
  2512                    End
  2513                    If (iMax_Rows > 0) Move (iRow_Count < iMax_Rows) to bFound
  2514                End
  2515                Else Begin
  2516                    Move (False) to bFound
  2517                End
  2518
  2519                If (iLoad_Monitor > 0) Begin
  2520                    If ((iRow_Count > iLoad_Monitor) and (Mod(iRow_Count, iLoad_Monitor) = 0)) Send OnLoad_Monitor iRow_Count
  2521                End
  2522            Loop
  2523
  2524            //Send DoBest_Fit
  2525        End
  2526
  2527        Send OnClose_DataSource
  2528        Set Private_piRow_Count to iRow_Count
  2529        Send Cursor_Ready of Cursor_Control
  2530    End_Procedure
  2531
  2532    //-------------------------------------------------------------------------
  2533
  2534    Procedure OnOpen_DataSource
  2535        // Event Hook
  2536    End_Procedure
  2537
  2538    //-------------------------------------------------------------------------
  2539
  2540    Procedure OnPrepare_RowData
  2541        // Event Hook
  2542        //
  2543        // Send Add_Item_Data for each column
  2544    End_Procedure
  2545
  2546    //-------------------------------------------------------------------------
  2547
  2548    Procedure OnClose_DataSource
  2549        // Event Hook
  2550    End_Procedure
  2551
  2552    //-------------------------------------------------------------------------
  2553
  2554    Procedure Add_Item_Data String sItem
  2555        String[] sData
  2556
  2557        Get psData_Items to sData
  2558        Move sItem to sData[SizeOfArray(sData)]
  2559        Set psData_Items to sData
  2560    End_Procedure
  2561
  2562    //=========================================================================
  2563
  2564    Procedure OnComGroupOrderChanged
  2565        Boolean bGroupRow
  2566        Integer iCount iRow iWork
  2567        Handle  hoReport_Rows hoRow hoGroupRow
  2568        Variant vReport_Rows  vRow
  2569
  2570        If (pbCollapseGroups(Self)) Begin
  2571            Get phoReportRows     to hoReport_Rows
  2572            Get phoReportRow      to hoRow
  2573            Get phoReportGroupRow to hoGroupRow
  2574            Get ComRows to vReport_Rows
  2575            Set pvComObject of hoReport_Rows to vReport_Rows
  2576    
  2577            Get ComCount of hoReport_Rows to iCount
  2578            Decrement iCount
  2579    
  2580            For iRow from 0 to iCount
  2581                Get ComRow of hoReport_Rows iRow to vRow
  2582                Set pvComObject of hoRow to vRow
  2583    
  2584                Get ComGroupRow of hoRow to bGroupRow
  2585                If (bGroupRow) Begin
  2586                    Set pvComObject of hoGroupRow to vRow
  2587                    Set ComExpanded of hoRow to False
  2588    
  2589                    Get ComCount of hoReport_Rows to iCount
  2590                    Decrement iCount
  2591                End
  2592            Loop
  2593        End
  2594    End_Procedure
  2595
  2596    Function Ensure_Visible String sTag Returns Boolean
  2597        Boolean bFound bGroupRow bExpanded
  2598        Integer iCount iLoop
  2599        Handle hoRecords hoRec hoReport_Rows hoRow hoGroupRow
  2600        Variant vRec vRow vReport_Rows vGroup_Row
  2601        String sRecTag
  2602        Integer[] aiRow
  2603                       
  2604        Get phoReportRecords  to hoRecords
  2605        Get phoReportRecord   to hoRec
  2606        Get phoReportRows     to hoReport_Rows
  2607        Get phoReportRow      to hoRow
  2608        Get phoReportGroupRow to hoGroupRow
  2609
  2610        Get ComRows to vReport_Rows
  2611        Set pvComObject of hoReport_Rows to vReport_Rows
  2612
  2613        Get ComCount of hoRecords to iCount
  2614
  2615        //Find record with matching TAG
  2616        Decrement iCount
  2617        Move False to bFound
  2618        Move 0 to iLoop         
  2619        Repeat
  2620            Get ComRecord of hoRecords iLoop to vRec
  2621            Set pvComObject of hoRec to vRec
  2622
  2623            Get ComTag of hoRec to sRecTag
  2624            If (sRecTag = sTag) Begin
  2625                Move True to bFound
  2626            End
  2627            Increment iLoop
  2628        Until ((iLoop = iCount) or bFound)
  2629
  2630        If (bFound) Begin
  2631            //tag found so find row
  2632            Get ComFindRow of hoReport_Rows vRec to vRow
  2633            If (IsNullComObject(vRow)) Begin
  2634                //Row not found so must be in a collapsed group.
  2635                //Have to expand each group until we find row
  2636                Move False to bFound
  2637                Get ComCount of hoReport_Rows to iCount
  2638                Decrement iCount
  2639                For iLoop from 0 to iCount
  2640                    Get ComRow of hoReport_Rows iLoop to vRow
  2641                    Set pvComObject of hoRow to vRow
  2642
  2643                    Get ComGroupRow of hoRow to bGroupRow
  2644                    If (bGroupRow) Begin
  2645                        Set pvComObject of hoGroupRow to vRow
  2646                        Get ComExpanded of hoGroupRow to bExpanded
  2647                        If (not(bExpanded)) Begin
  2648                            Set ComExpanded of hoGroupRow to True
  2649                            Get ComFindRow of hoReport_Rows vRec to vRow
  2650                            If (IsNullComObject(vRow)) Begin
  2651                                Move iLoop to aiRow[SizeOfArray(aiRow)]
  2652                                Get ComCount of hoReport_Rows to iCount
  2653                                Decrement iCount
  2654                            End
  2655                            Else Begin
  2656                                Move True to bFound
  2657                                Move (iCount + 1) to iLoop  //bomb loop
  2658                            End
  2659                        End
  2660                    End            
  2661                Loop
  2662
  2663                //Collapse any groups that we have just expanded
  2664                Move (SizeOfArray(aiRow)) to iCount
  2665                While (iCount > 0) 
  2666                    Decrement iCount
  2667                    Get ComRow of hoReport_Rows aiRow[iCount] to vGroup_Row
  2668                    Set pvComObject of hoGroupRow to vGroup_Row
  2669                    Set ComExpanded of hoGroupRow to False
  2670                Loop
  2671            End
  2672        End
  2673
  2674        If (bFound) Begin
  2675            //Found row so make it the focus.
  2676            //We use FocusedRow as this makes the row visible and 
  2677            //highlights it. EnsureVisible only makes row visible.
  2678            Set pvComObject of hoRow to vRow
  2679            Set ComFocusedRow to vRow 
  2680            //Send ComEnsureVisible of hoRow
  2681        End
  2682
  2683        Function_Return bFound
  2684    End_Function
  2685
  2686    //=========================================================================
  2687
  2688    {MethodType=Event}
  2689    Procedure OnSetOrdering tdRC_Ordering[] ByRef taRC_Ordering
  2690    End_Procedure
  2691
  2692    {MethodType=Event}
  2693    Procedure OnSetGrouping tdRC_Ordering[] ByRef taRC_Ordering
  2694    End_Procedure    
  2695    
  2696    {MethodType=Method Visibility=Private}
  2697    Procedure DoSetOrdering Boolean bGroup
  2698        tdRC_Ordering[] taRC_Ordering
  2699        Integer iColumns iSort
  2700        Handle hoOrder hoColumns hoColumn
  2701        Variant vColumn vColumns vOrder  
  2702        
  2703        If (bGroup) Begin
  2704            Get ComGroupsOrder to vOrder
  2705            Send OnSetGrouping (&taRC_Ordering)
  2706        End
  2707        Else Begin
  2708            Get ComSortOrder to vOrder
  2709            Send OnSetOrdering (&taRC_Ordering)
  2710        End
  2711        
  2712        Move (SizeOfArray(taRC_Ordering)) to iColumns
  2713        If (iColumns=0) Begin
  2714            Procedure_Return
  2715        End
  2716        
  2717        Get phoReportColumnOrder to hoOrder
  2718        Get phoReportColumns to hoColumns
  2719        Get phoReportColumn to hoColumn
  2720        
  2721        Get ComColumns to vColumns
  2722        Set pvComObject of hoOrder to vOrder
  2723        Set pvComObject of hoColumns to vColumns
  2724
  2725        For iSort from 0 to (iColumns-1)
  2726            Get ComColumn of hoColumns taRC_Ordering[iSort].iColumn to vColumn 
  2727            Set pvComObject of hoColumn to vColumn 
  2728            Set ComSortAscending of hoColumn to (not(taRC_Ordering[iSort].bDescending)) 
  2729            Send ComAdd of hoOrder vColumn   
  2730        Loop
  2731    End_Procedure
  2732    
  2733    {MethodType=Method Visibility=Private}
  2734    Procedure DoSetColumnOrdering
  2735        Send DoSetOrdering False
  2736    End_Procedure
  2737    
  2738    {MethodType=Method Visibility=Private}
  2739    Procedure DoSetColumnGrouping
  2740        Send DoSetOrdering True
  2741    End_Procedure
  2742    
  2743    {MethodType=Method}
  2744    Procedure SortGridByColumn tdRC_Ordering[] tRC_Ordering
  2745        Handle hoSortOrder hoCol
  2746        Integer iItem
  2747
  2748        Get phoReportColumn to hoCol
  2749        Get phoReportColumnOrder to hoSortOrder
  2750                
  2751        Send ComDeleteAll of hoSortOrder                    
  2752        For iItem from 0 to (SizeOfArray(tRC_Ordering) -1)
  2753            Set pvComObject of hoCol to (ComColumn(phoReportColumns(Self), tRC_Ordering[iItem].iColumn))
  2754            Set ComSortAscending of hoCol to tRC_Ordering[iItem].bDescending
  2755            Send ComAdd of hoSortOrder (pvComObject(hoCol))
  2756        Loop
  2757    End_Procedure //SortGridByColumn tdRC_Ordering[] tRC_Ordering     
  2758    
  2759    //=========================================================================
  2760    // Other features
  2761
  2762    Procedure Standard_PrintFooter
  2763        Handle hoPrintPageHeaderFooter  hoReportPrintOptions hoClient
  2764        String sLabel
  2765
  2766        Get Client_id                to hoClient
  2767        Get Label       of  hoClient to sLabel
  2768        Get phoReportPrintOptions    to hoReportPrintOptions
  2769        Get phoPrintPageHeaderFooter to hoPrintPageHeaderFooter
  2770
  2771        Set pvComObject     of hoPrintPageHeaderFooter to (ComFooter(hoReportPrintOptions))
  2772        Set ComFormatString of hoPrintPageHeaderFooter to ("&D &b" * String(sLabel) * "&b Page &p of &P")
  2773    End_Procedure
  2774
  2775    Procedure Set PrintFooter String sValue
  2776        Handle hoPrintPageHeaderFooter  hoReportPrintOptions
  2777        Get phoReportPrintOptions    to hoReportPrintOptions
  2778        Get phoPrintPageHeaderFooter to hoPrintPageHeaderFooter
  2779
  2780        Set pvComObject     of hoPrintPageHeaderFooter to (ComFooter(hoReportPrintOptions))
  2781        Set ComFormatString of hoPrintPageHeaderFooter to sValue
  2782    End_Procedure
  2783
  2784    Procedure Set PrintHeader String sValue
  2785        Handle hoPrintPageHeaderFooter  hoReportPrintOptions
  2786        Get phoReportPrintOptions    to hoReportPrintOptions
  2787        Get phoPrintPageHeaderFooter to hoPrintPageHeaderFooter
  2788
  2789        Set pvComObject     of hoPrintPageHeaderFooter to (ComHeader(hoReportPrintOptions))
  2790        Set ComFormatString of hoPrintPageHeaderFooter to sValue
  2791    End_Procedure
  2792
  2793    //=========================================================================
  2794    //Standard Dataflex methods
  2795
  2796    Procedure Deactivating Returns Integer
  2797        Integer iRetVal
  2798
  2799        Forward Get Msg_Deactivating to iRetVal
  2800
  2801        If (phoFieldChooser(Self)) Begin
  2802            Set Visible_State of (phoFieldChooser(Self)) to False
  2803        End
  2804        Send PX_Save
  2805
  2806        Procedure_Return iRetVal
  2807    End_Procedure
  2808
  2809    //=========================================================================
  2810    //
  2811    //The following procedures are to stop data aware error messages
  2812    //
  2813    Procedure Prompt
  2814    End_Procedure
  2815
  2816    Procedure Request_Clear
  2817    End_Procedure
  2818
  2819    Procedure Request_Clear_All
  2820    End_Procedure
  2821
  2822    Procedure Request_Save
  2823    End_Procedure
  2824
  2825    Procedure Request_Delete
  2826    End_Procedure
  2827
  2828    Procedure Find_Next
  2829    End_Procedure
  2830
  2831    Procedure Find_Previous
  2832    End_Procedure
  2833
  2834    Procedure Beginning_Of_Data
  2835    End_Procedure
  2836
  2837    Procedure End_Of_Data
  2838    End_Procedure
  2839
  2840    Procedure Find_Ge
  2841    End_Procedure
  2842
  2843    Procedure Superfind
  2844    End_Procedure
  2845
  2846    Procedure Superfind_Next
  2847    End_Procedure
  2848
  2849    Procedure Superfind_Previous
  2850    End_Procedure
  2851
  2852    Procedure OnComColumnClick Variant llColumn
  2853        Forward Send OnComColumnClick llColumn
  2854    End_Procedure
  2855End_Class
  2856
  2857//==============================================================================
  2858//End of package - cSigCJReportControl.pkg
  2859//==============================================================================
  2860