Module Ddvaltbl.pkg

     1//****************************************************************************//
     2//                                                                            //
     3// $File name  : ddvaltbl.pkg                                                 //
     4// $File title :                                                              //
     5// Notice      :                                                              //
     6// $System     : Extended Data Sets 3.1                                       //
     7// Created     : 03/28/96 04:48 pm                                            //
     8// $Last Rev   : 03/28/96 04:48 pm41                                          //
     9//                                                                            //
    10// $Description                                                               //
    11//                                                                            //
    12//                                                                            //
    13// $Rev History                                                               //
    14//JT 02/04/97 Changed Validate_value in FileValidationTable to no use the code//
    15//            DSO if operation mode is busy. In DDOs validtion sets operation_//
    16//            mode to busy.                                                   //
    17//JT 12/23/96 Made sure field values are always trimmed!                      //
    18//JT 07/23/96 New Class names                                                 //
    19//JT 06/12/96 Modified "indirect-file" finding methods and replaced them with //
    20//            3.1 API commands                                                //
    21//JT 05/28/96 Add Public Message Find_Code_Description. Passes Code and       //
    22//            returns the description. Created properties current_description //
    23//            current_code and current_Record to speed up this process        //
    24//JT 02-04-96 Changed Validation_xxx_table to xxx_Validation_Table            //
    25//JT 28-03-96 File header created                                             //
    26//                                                                            //
    27//****************************************************************************//
    28
    29
    30//****************************************************************************//
    31//  Validation Table Support for Extended Data-Sets. Fields may               //
    32//  attached to validation tables which can then be used for                  //
    33//  validation (if Validate_state is true) or list loading.                   //
    34//  Developers can create their own validation tables as long as they         //
    35//  conform to the following external interface:                              //
    36//                                                                            //
    37// Properties                                                                 //
    38//   Static_State       - if list must be rebuilt each validation, load       //
    39//   Allow_Blank_state  - If Blank or 0 is a valid response                   //
    40//   Validate_State     - should table be used for validation                 //
    41//   Table_Loaded_State - is the validation table initialized?                //
    42//                                                                            //
    43// Methods                                                                    //
    44//  Get Validate_Value sValue to iVal - if iVal=0, it is legal                //
    45//  Send Fill_list                    - fills a static list                   //
    46//  Send Request_Fill_From_List iObject iMessage                              //
    47//        This is a callback that will fill an external list by sending       //
    48//        the passed message (iMessage) back to the requesting object         //
    49//        (iObject). It will send this message for each item in the           //
    50//        validation table. It always passes back four params. Those are:     //
    51//                     iItem - Item count being passed back                   //
    52//                     sData - The Database value of the item                 //
    53//                     sDesc - The Value's description, "" if none            //
    54//                     iFile - File number associated with the item (if any)  //
    55//                     iRec  - Record associated with the item (if any)       //
    56// Developers can create classes of any complexity to support validation      //
    57// tables. We have provided the following four classes.                       //
    58//                                                                            //
    59//  ValidationTable is an Array                                               //
    60//           Provides simple one dimensional table support. The table must be //
    61//           loaded manually by creating fill_list and sending the message    //
    62//           Add_Table_Value (send Add_Table_Value Value). If list is static      //
    63//           it is filled once. If non-static it is filled each time it is    //
    64//           requested to validate or fill a foreign lis.                     //
    65//                                                                            //
    66//  DescriptionValidationTable is a ValidationTable                           //
    67//           Provides a more complex three dimension array allowing the       //
    68//           object to store a data value, description value and a record     //
    69//           number. The developer must fill this list using the Add_table_   //
    70//           value message passing up to three values (data, desc, record).   //
    71//                                                                            //
    72//  FileValidationTable is a DescriptionValidationTable                       //
    73//           Provides a data aware table. This can be used to load data from  //
    74//           data-files, from data-sets. If you use data-sets you can place   //
    75//           constraints within the data-set. You must define the file-number,//
    76//           data-set (if any), the file index, the file's data field, and    //
    77//           the file's description field. You can also define an optional    //
    78//           "Type". All records are constrained to this type (with or with-  //
    79//           data-sets). If is assumed that this file has an optimized finding//
    80//           index.                                                           //
    81//                                                                            //
    82//  CodeValidationTable is a FileValidationTable                              //
    83//           Used for Code lists. Simply set Type_Value to the "type"         //
    84//                                                                            //
    85//                                                                            //
    86//****************************************************************************//
    87use VDFBase.pkg
    88
    89
    90{ ClassLibrary=Common }
    91{ HelpTopic=ValidationTable }
    92Class ValidationTable is an Array
    93
    94   Procedure Construct_Object
    95      Forward Send Construct_Object
    96      { Category=Behavior }
    97      { PropertyType=Boolean }
    98      Property Integer Static_State        True
    99
   100      { Visibility=Private }
   101      Property Integer Table_Loaded_State  False
   102
   103      { Category=Behavior }
   104      { PropertyType=Boolean }
   105      Property Integer Validate_State      True
   106      { Category=Behavior }
   107      { PropertyType=Boolean }
   108      Property Integer Allow_Blank_State   False
   109      { Category=Behavior }
   110      Property Integer Main_File           0
   111      { Category=Behavior }
   112      Property String  Table_Title         DD_VALIDATION_LIST_TITLE
   113
   114      { Visibility=Private }
   115      Property Integer Number_Elements     1
   116
   117      // System maintained. Sub-classes use these
   118      // These are SET by Next_Code_Record. You may GET their values
   119
   120      { Visibility=Private }
   121      Property String  Current_Code            ''
   122
   123      { Visibility=Private }
   124      Property String  Current_Description     ''
   125
   126      { Visibility=Private }
   127      Property RowId Current_RowId
   128   End_Procedure // Construct_Object
   129
   130   { MethodType=Property Visibility=Private }
   131   Function Data_Item_Count returns integer
   132     Function_return (Item_Count(Self))
   133   End_Function
   134
   135   { MethodType=Property Visibility=Private }
   136   Function Data_Value Integer iItem returns string
   137      Function_return (Value(Self,iItem))
   138   End_function
   139
   140   { MethodType=Property Visibility=Private }
   141   Procedure Set Data_Value Integer iItem String sValue
   142      Set Value Item iItem to sValue
   143   End_Procedure
   144
   145   { MethodType=Property Visibility=Private }
   146   Function Data_Description Integer iItem returns string
   147      Function_Return ''
   148   End_function
   149
   150   { MethodType=Property Visibility=Private }
   151   Procedure Set Data_Description Integer iItem String sValue
   152   End_function
   153
   154   { MethodType=Property Visibility=Private }
   155   Function Data_RowId Integer iItem returns RowId
   156       Function_return (NullRowId())
   157   End_function
   158
   159   { MethodType=Property Visibility=Private }
   160   Procedure Set Data_RowId Integer iItem RowId riValue
   161   End_function
   162
   163
   164   Procedure Add_Table_Value String sValue
   165     Set Data_Value Item (Data_Item_Count(self)) to sValue
   166   End_Procedure
   167
   168   Function Validate_Value String sCode Returns Integer
   169      Integer iMax
   170      Integer iCnt
   171      If sCode eq '';
   172         Function_Return (not(Allow_Blank_State(Self)))
   173      If (Table_Loaded_State(Self)=0 or Static_State(Self)=0) Begin
   174         Send Delete_Data
   175         Send Fill_list
   176         Set Table_Loaded_State to TRUE
   177      End
   178      Get Data_Item_Count to iMax
   179      Decrement iMax
   180      For iCnt from 0 to iMax
   181          If (sCode=Data_Value(Self,iCnt)) Begin
   182             Set Current_Code        to sCode
   183             Set Current_Description to (Data_Description(Self,iCnt))
   184             Set Current_RowId       to (Data_RowId(Self,iCnt))
   185             Function_return 0
   186          End
   187      Loop
   188      Function_Return 1 // 0=OK
   189   End_Function
   190
   191   Function Find_Code_Description String sCode Returns String
   192      If (sCode='' OR ;
   193           (sCode<>Current_Code(Self) AND ;
   194            Validate_Value(Self,sCode) ) );
   195                Function_Return ''
   196      Function_Return (Current_Description(Self))
   197   End_Function
   198
   199
   200   //  The deveveloper (or a sub-class) must fill this list. It is done
   201   //  by finding the item and sending the Message:
   202   //    Send Add_Table_Value sValue {sDescr}
   203   //
   204   { MethodType=Event }
   205   Procedure Fill_List
   206      Set Table_Loaded_State to TRUE
   207   End_Procedure
   208
   209   { Visibility=Private }
   210   Procedure Request_Fill_From_List integer iObj integer iMsg
   211      Integer iMax
   212      Integer iCnt
   213      Integer iFile
   214
   215      If (iObj=0 or iMsg=0) Procedure_return
   216
   217      If (Table_Loaded_State(Self)=0 OR Static_State(Self)=0) Begin
   218         Send Delete_Data
   219         Send Fill_list
   220         Set Table_Loaded_State to TRUE
   221      End
   222      Get Main_File to iFile
   223      Get Data_Item_Count to iMax
   224      Decrement iMax
   225      For iCnt from 0 to iMax
   226          Send iMsg to iObj iCnt (Data_Value(Self,iCnt)) ;
   227                                 (Data_Description(Self,iCnt)) iFile ;
   228                                 (Data_RowId(Self,iCnt))
   229      Loop
   230   End_Procedure
   231
   232
   233    // returns all data in a two dimension variant array.
   234    // [i][0] = data
   235    // [i][1] = description
   236    // This can be used by Crystal CDO classes (this is why a variant array is used)
   237    Function TableData returns variant[][]
   238        Variant[][2] vData
   239        Integer iMax i
   240        If (Table_Loaded_State(Self)=0 OR Static_State(Self)=0) Begin
   241            Send Delete_Data
   242            Send Fill_list
   243            Set Table_Loaded_State to TRUE
   244        End
   245        Get Data_Item_Count to iMax
   246        For i from 0 to (iMax-1)
   247            Get Data_Value       i to vData[i][0]
   248            Get Data_Description i to vData[i][1]
   249        Loop
   250        function_Return vData
   251    End_Function
   252
   253End_Class
   254
   255
   256
   257{ ClassLibrary=Common }
   258{ HelpTopic=DescriptionValidationTable }
   259Class DescriptionValidationTable is an ValidationTable
   260
   261    Procedure Construct_Object
   262       Forward Send Construct_Object
   263       Set Number_Elements to 2
   264    End_Procedure // Construct_Object
   265
   266    { MethodType=Property Visibility=Private }
   267    Function Data_Item_Count returns integer
   268       function_return (item_count(Self)/3)
   269    End_Function // Data_item_Count
   270
   271    { MethodType=Property Visibility=Private }
   272    Function Data_Value Integer iItem returns string
   273       Function_return (Value(Self,iItem*3))
   274    End_function
   275
   276    { MethodType=Property Visibility=Private }
   277    Procedure Set Data_Value Integer iItem String sValue
   278       Set Value Item (iItem*3) to sValue
   279    End_Procedure
   280
   281    { MethodType=Property Visibility=Private }
   282    Function Data_Description Integer iItem returns string
   283       Function_return (Value(Self,iItem*3+1))
   284    End_function
   285
   286    { MethodType=Property Visibility=Private }
   287    Procedure Set Data_Description Integer iItem String sValue
   288       Set Value Item (iItem*3+1) to sValue
   289    End_function
   290
   291    { MethodType=Property Visibility=Private }
   292    Function Data_RowId Integer iItem returns RowId
   293       String sRowId
   294       Get Value (iItem*3+2) to sRowId
   295       Function_return (DeSerializeRowId(sRowId))
   296    End_function
   297
   298    { MethodType=Property Visibility=Private }
   299    Procedure Set Data_RowId Integer iItem RowId riValue
   300       Set Value Item (iItem*3+2) to (SerializeRowId(riValue))
   301    End_function
   302
   303    Procedure Add_Table_Value String sData String sDescr RowId riRec
   304      String  sVal
   305      RowId   riRecVal
   306      Integer iCnt
   307      Get Data_Item_Count to iCnt
   308      Set Data_Value iCnt to sData
   309
   310      // If one param passed use it for both display and database values
   311      If num_arguments le 1 Move sData  to sVal
   312      Else                  Move sDescr to sVal
   313      Set Data_Description iCnt to sVal
   314
   315      If num_arguments le 2 Move (NullRowId()) to riRecVal
   316      Else                  Move riRec        to riRecVal
   317      Set Data_RowId iCnt to riRecVal
   318    End_Procedure
   319End_Class
   320
   321
   322{ ClassLibrary=Common }
   323{ HelpTopic=FileValidationTable }
   324Class FileValidationTable is an DescriptionValidationTable
   325
   326   Procedure Construct_Object
   327      Forward Send Construct_Object
   328      { Visibility=Private Obsolete=True }
   329      Property Integer No_Fill_State     False // this is never used and is obsolete. (JJT)
   330      { Category=Data }
   331      Property Integer Ordering          1   // Indx1 is a good guess.
   332      { Category=Data }
   333      Property String  Type_Value        ''  // default these two to
   334      { Category=Data }
   335      Property Integer Type_Field        0   // Undefined (none).
   336      { Category=Data }
   337      Property Integer Code_Field        1   // Fld 1=code, 2=descr
   338      { Category=Data }
   339      Property Integer Description_Field 2   // are good guesses.
   340
   341      { Visibility=Private }
   342      Property Integer Code_Load_Object  0   // or (Code_Loader(Self))
   343   End_Procedure // Construct_Object
   344
   345   { MethodType=Property Visibility=Private }
   346   Function Table_Loaded_State Returns Integer
   347      integer iRVal
   348      Get No_fill_State to iRVal // if true, table always is loaded
   349      If Not iRval ;
   350         Forward get table_loaded_State to iRVal
   351      Function_Return iRval
   352   End_Function
   353
   354   { NoDoc=True }
   355   Function Validate_Value String sCode Returns Integer
   356      Integer iRVal
   357      Integer iDSO
   358      Get Code_Load_Object  to iDSO
   359      // we use standard validate, if code is blank, OR if
   360      //   1. if no code DSO or the code DSO exists but is not busy.
   361      //   2. AND it is not no-fill
   362      //   3. AND it is static
   363      // Else we find the record directly
   364      // Note that the operation mode is busy during request_validate (the
   365      // ddo does this). WHen operation mode is busy we must not use
   366      // the code dso (must find manually).
   367      If (sCode='' OR ;
   368           ( (iDSO=0 OR Operation_Mode=0)    AND ; // if no code DSO or DSO not busy
   369             No_Fill_State(Self)=0 AND ;
   370             Static_State(Self) ) ) ;
   371               Forward Get Validate_Value sCode to iRVal
   372      Else If (sCode<>Current_Code(Self)) ;
   373          Get Find_Value sCode to iRVal
   374      Function_Return iRVal // OK
   375   End_Function
   376
   377   { Visibility=Private }
   378   Procedure Initialize_File
   379      integer iFile iCodeField iDescField iDSO iIndex iTypeField
   380      Get Code_Load_Object  to iDSO
   381      Get Main_File         to iFile
   382      Get Code_Field        to iCodeField
   383      Get Description_Field to iDescField
   384      Get Ordering          to iIndex
   385      Get Type_Field        to iTypeField
   386      If (iDSO AND Operation_Mode=0) ;
   387         Send Initialize_File to iDSO ;
   388              iFile iIndex iCodeField iDescField ;
   389              iTypeField (Type_Value(Self))
   390      Else Begin
   391         Clear iFile
   392         // if Type exists, seed the type value
   393         If iTypeField ;
   394            Set_Field_Value iFile iTypeField to (Type_Value(Self))
   395      End
   396   End_Procedure
   397
   398   { Visibility=Private }
   399   Function Find_Value string Code returns Integer
   400     integer iFile iCodeField iDescField iDSO iIndex iTypeField
   401     Get Code_Load_Object  to iDSO
   402     Get Main_File         to iFile
   403     Get Ordering          to iIndex
   404     Get Code_Field        to iCodeField
   405     Get Description_Field to iDescField
   406     Get Type_Field        to iTypeField
   407     Send Initialize_File
   408     //
   409     Set_Field_Value iFile iCodeField to Code
   410     If (iDSO AND Operation_Mode=0) ;
   411        Send Request_Find to iDSO EQ iFile iIndex
   412     Else ;
   413        vFind iFile iIndex EQ
   414     If not (Found) Function_Return 1
   415     // Set properties Current_code and Current_Description
   416     Send Store_Current_Data iFile iCodeField iDescField
   417     Function_Return 0
   418   End_Function // Function
   419
   420   // internal
   421   { Visibility=Private }
   422   Procedure Store_Current_Data Integer iFile Integer iCodeField Integer iDescField
   423     String sVal
   424//     Integer iRec
   425     Get_Field_Value iFile iCodeField to sVal
   426     Set Current_Code to (trim(sVal))
   427     If iDescField Begin
   428        Get_Field_Value iFile iDescField to sVal
   429        Set Current_Description to (trim(sVal))
   430     End
   431     Set Current_RowId to (GetRowId(iFile))
   432//     Get_Field_Value iFile 0 to iRec // recnum
   433//     Set Current_Record to iRec
   434   End_Procedure
   435
   436   { Visibility=Private }
   437   Function Next_Code_Record Returns boolean
   438     integer iFile iCodeField iDescField iIndex
   439     Integer iTypeField
   440     String sTypeValue sFoundTypeValue
   441     boolean bFound
   442     handle hoDSO
   443     Get Code_Load_Object  to hoDSO
   444     Get Description_Field to iDescField
   445     Get Code_Field        to iCodeField
   446     Get Main_File         to iFile
   447
   448     If hoDSO begin
   449        Get Next_Code_record of hoDSO to bFound
   450     end
   451     Else Begin
   452        Get Ordering to iIndex
   453        vFind iFile iIndex GT
   454        Move (Found) to bFound
   455        If bFound Begin
   456            // if found see if we are at the end of the valid list of types
   457            Get Type_Field To iTypeField
   458            Get Type_Value To sTypeValue
   459            If ((iTypeField<>0) And (sTypeValue<>"")) Begin
   460                Get_Field_Value iFile iTypeField To sFoundTypeValue
   461                Move (Trim(sTypeValue)=Trim(sFoundTypeValue)) To bFound
   462             End
   463        End
   464     End
   465     if bFound Begin
   466        Send Store_Current_Data iFile iCodeField iDescField
   467     End
   468     Function_Return bFound
   469   End_Function // next_Code_record
   470
   471   { Visibility=Private }
   472   Procedure Fill_List
   473      RowId riId
   474      boolean bFound
   475      String sCode sDesc
   476      If (Static_State(Self)=0 OR No_Fill_State(Self)) ;
   477         Procedure_Return
   478      //
   479      Send Delete_Data
   480      Send Initialize_File
   481      Get Next_Code_Record to bFound
   482      While bFound
   483         Get Current_Code        to sCode
   484         Get Current_Description to sDesc
   485         Get Current_RowId       to riId
   486         Send Add_Table_Value sCode sDesc riId
   487         Get Next_Code_Record to bFound
   488      Loop
   489      Set Table_Loaded_State to TRUE
   490   End_Procedure // Fill_list
   491
   492   { Visibility=Private }
   493   Procedure Request_Fill_From_List integer iObj integer iMsg
   494      Integer iItem
   495      Integer iFile
   496      RowId   riId
   497      Boolean bFound
   498      String sCode sDesc
   499
   500      If (iObj=0 or iMsg=0) Procedure_return
   501
   502      If (Static_State(Self) AND No_Fill_State(Self)=0 ) ;
   503         Forward Send Request_Fill_From_List iObj iMsg
   504      Else Begin
   505         Get Main_File to iFile
   506         Send Initialize_File
   507         Get Next_Code_Record to bFound
   508         While bFound
   509            Get Current_Code        to sCode
   510            Get Current_Description to sDesc
   511            Get Current_RowId       to riId
   512            Send iMSG to iObj iItem sCode sDesc iFile riId
   513            Increment iItem
   514            Get Next_Code_Record to bFound
   515         Loop
   516      End
   517   End_procedure
   518End_Class
   519
   520use CodeLoad.pkg
   521Use cCodeMaintOpen_Mixin.pkg
   522
   523#IFDEF Code_Loader
   524#ELSE
   525  //
   526  //  This is the object we need for loading files.
   527  //
   528  Object Code_loader is a Code_loader_Data_Set no_Image
   529  End_Object
   530#ENDIF
   531
   532
   533{ ClassLibrary=Common }
   534{ HelpTopic=CodeValidationTable }
   535Class CodeValidationTable is an FileValidationTable
   536
   537    // supports opening of file in reserved filelist area.
   538    Import_Class_Protocol cCodeMaintOpen_Mixin
   539
   540    Procedure Construct_Object
   541        Forward Send Construct_Object
   542
   543        Send OpenCodeMast                       // methods supports w/ filelist (new) and without (old)
   544
   545        Set Main_File to CodeMast.File_Number   // name of file is CODEMAST
   546        Set Ordering to 1                       // Index 1: Types x Code
   547        Set Type_Field to 1                     // Fld 1: Type
   548        Set Code_Field to 2                     // Fld 2: Code
   549        Set Description_Field to 3              // Fld 3: Description
   550        Set Code_load_Object to (Code_Loader(self))
   551    End_Procedure // Construct_Object
   552
   553End_Class
   554
   555
   556