Module Dfdtcent.pkg

     1// 07/23/96 JJT - New Class names
     2// 2/26/2002  JJT - 8.2 clean up (indirect_file, local, self, etc.)
     3
     4Use DfbsCent.pkg // dfCombo_Basic_entry_form class
     5
     6Enum_list
     7   Define CB_ERR_UPDATE_NONE
     8   Define CB_ERR_UPDATE_BLANK_VALUE
     9   Define CB_ERR_UPDATE_WINDOW_VALUE
    10End_Enum_list
    11
    12#REPLACE CB_INVALID_VALUE |CS"CBInvalidValue"
    13
    14{ ClassType=Abstract }
    15{ HelpTopic=dbDataComboForm }
    16Class dbDataComboForm is a dbBasicComboForm
    17
    18  Procedure Construct_Object
    19    forward send construct_object
    20    { Category=Data }
    21    Property String Default_Value            ''
    22    { Category=Data }
    23    Property String  Undefined_Value         ''
    24    { EnumList="CB_Err_Update_None, CB_Err_Update_Blank_Value, CB_Err_Update_Window_Value" }
    25    { Category=Behavior }
    26    Property Integer Undefined_Display_Mode  CB_Err_Update_Window_Value
    27    { EnumList="CB_Err_Update_None, CB_Err_Update_Blank_Value, CB_Err_Update_Window_Value" }
    28    { Category=Behavior }
    29    Property Integer Undefined_Save_Mode     CB_Err_Update_Window_Value
    30    { EnumList="CB_Code_Display_Code, CB_Code_Display_Description, CB_Code_Display_Both" }
    31    { Category=Behavior }
    32    Property Integer Code_Display_Mode       CB_Code_Display_Description
    33
    34    { Visibility=Private }
    35    Property Integer Entry_Values            0
    36
    37    // Private: Set by object if desc and data are one and the same
    38    { Visibility=Private }
    39    Property Integer Data_Only_State         False
    40
    41    Object EV is an Array         // keeps values of database
    42    End_Object                    // items for each selection
    43
    44    Set entry_values to (Ev(self))
    45    Set form_margin item 0 to 100
    46    // Set Entry_state to False // this never did anything because the item param (needed in constructor) was missing. So this changes nothing.
    47  End_Procedure
    48
    49   { MethodType=Property Visibility=Private }
    50  Procedure Set Entry_Value Integer Itm String Val
    51    Set Value of (Entry_Values(self)) Item Itm to Val
    52  End_Procedure
    53
    54  { MethodType=Property Visibility=Private }
    55  Function Entry_Value Integer Itm Returns String
    56    string sValue
    57    Get Value of (Entry_Values(self)) Item Itm to sValue
    58    Function_Return sValue
    59  End_Function
    60
    61  //
    62  // created for EntItem simulation and Server support:
    63  //  if file# = 0, display only if Target_File is in Done-array
    64  //  else display only if file# = Target_File
    65  //
    66  { Visibility=Private }
    67  procedure Entry_Display integer file# integer flag
    68    integer dFile dField
    69    string sVal
    70    get Data_File  to dFile
    71    get Data_Field to dField
    72    //
    73    //  We will display this if the following conditions exist:
    74    //    passed file is 0 and the target file is in the done array <or>
    75    //    passed file= target File or flag = true)
    76    if file# eq 0 is_file_included dFile 1  // set found if in done array
    77    else indicate found as (file# = dFile OR flag = TRUE)
    78    [FOUND] begin
    79       Get_field_value dFile dField to sVal
    80       Send Display_Description sVal
    81       Set Changed_State to False
    82    End
    83  End_procedure
    84
    85  //
    86  //  Set the Combo item to the value passed. If not found make it 0
    87  //  with nothing selected
    88  //
    89  { Visibility=Private }
    90  Procedure Display_Description String DataVal
    91    String sValue
    92    Get Data_to_Description DataVal to sValue
    93    If sValue ne CB_INVALID_VALUE ;
    94       Set Value item 0 to sValue
    95  End_Procedure // Display_Description
    96
    97  //
    98  // created for EntItem simulation and Server support
    99  //
   100  //  Normally entry_update gets called during saves and finds. When
   101  //     Save:  file#  = 0   flag = 3
   102  //     Find:  file# <> 0   flag = 1
   103  //
   104  //  Allow Update Rules:
   105  //    if Save update (file#=0, flag=3)
   106  //       Allow Update if not noput and Target_File is in Done-array
   107  //                    and (new record or changed_state).
   108  //    else if Find_Update (file#=Target_File, Flag=1) or misc (file#=0)
   109  //       Allow Update
   110  //
   111  //  Modified so that an unchanged item is moved to the field if
   112  //  the main file is a new record.
   113  //
   114  { Visibility=Private }
   115  procedure Entry_Update integer file# integer flag
   116    integer dFile dField C_Item Srvr# ok NP Mode
   117    integer iStat
   118    string val
   119    Get Server       to Srvr#
   120    Get Data_File  to dFile
   121    Get Data_Field to dField
   122    if (file# = 0 AND flag = 3) Begin
   123       // this should be a save a record update.check for no put
   124       Get Item_Option Item 0 NOPUT to NP
   125       If NP Indicate Found False
   126       else is_file_included dFile 1
   127    End
   128    else indicate FOUND as (file# = dFile OR file# = 0) // new change
   129    // **JJT**(2) I think this was wrong. Flag is used to figure if
   130    // item_changed_state should be ignored. I don't think it is meant
   131    // to override the file param.
   132    //else indicate FOUND as (file# = dFile OR flag = TRUE OR file# = 0)
   133    Move (found) to OK
   134    If Ok Begin
   135       // If flag<>do it always and no change we normally do not update.
   136       // However, if this is a new record we will move it
   137       if ( Flag<>1 and changed_State(self)=0) Begin
   138          Get_attribute DF_FILE_STATUS of dFile to iStat
   139          If (iStat<>DF_FILE_INACTIVE) Move 0 to Ok // old record...not ok
   140       end
   141       if Ok Begin
   142          Get Data_Value Item 0 to Val
   143          If Val ne CB_INVALID_VALUE ;
   144             Set_Field_Value dFile dField to Val
   145       end
   146    End
   147  end_procedure
   148
   149  { MethodType=Property Visibility=Private }
   150  Function Data_Value integer item# Returns String
   151     string sValue
   152     Get Value item item# to sValue
   153     Get Description_to_Data sValue to sValue
   154     Function_Return SValue
   155  End_Function
   156
   157  { Visibility=Private }
   158  Function Data_To_Description String sValue returns String
   159    integer Itms Itm MatchItem iMode
   160    If (Data_Only_State(self) OR ;
   161        Code_Display_Mode(self)=CB_CODE_DISPLAY_CODE) ;
   162           Function_Return sValue
   163    //showln "Data-to-desc " svalue
   164    Move -1 to MatchItem
   165    Move ( Combo_Item_count(self) - 1) to Itms
   166    For Itm from 0 to Itms
   167       If ( Entry_Value(self,Itm)=sValue ) ;
   168          Move Itm to MatchItem
   169    Until MatchItem ne -1
   170    If MatchItem ne -1 ; // if valid value, use it
   171       Move (Combo_Value(self,MatchItem)) to sValue
   172    Else Begin // we handle invalid values various ways.
   173       Get Undefined_Display_Mode to iMode
   174       if iMode eq CB_ERR_UPDATE_BLANK_VALUE ;
   175          Get Undefined_Value to sValue
   176       else If iMode eq CB_Err_Update_None ; // if do nothing
   177          Move CB_INVALID_VALUE to sValue
   178    End
   179    Function_Return sValue
   180  End_function
   181
   182  { Visibility=Private }
   183  Function Description_to_Data String sValue returns String
   184     integer iItem
   185     integer iMode
   186     If (Data_Only_State(self) OR ;
   187         Code_Display_Mode(self)=CB_CODE_DISPLAY_CODE) ;
   188            Function_Return sValue
   189     //showln "desc-Data " svalue
   190     Get Combo_item_matching sValue to iItem
   191     If iItem ge 0 ; // if value is found
   192        Get Entry_value item iItem to sValue
   193     Else Begin // invalid. Handle various ways
   194        Get Undefined_Save_Mode to iMode
   195        If iMode eq CB_Err_Update_Blank_Value ; // if return error Value
   196           Get Undefined_Value to sValue
   197        If iMode eq CB_Err_Update_None ; // if do nothing
   198           Move CB_INVALID_VALUE to sValue
   199     End
   200      //showln "desc-Data ret " svalue
   201     Function_Return sValue
   202  End_Function
   203
   204  { NoDoc=True }
   205  Procedure Combo_Delete_Data
   206    integer obj#
   207    forward send Combo_delete_Data
   208    move (Entry_Values(self)) to obj#
   209    // we do this to get around program close down problems. Delete_data
   210    // gets called by destroy-object.
   211    if (object_id(obj#)) ne 0 send delete_Data to obj#
   212  End_Procedure // Delete_Data
   213
   214  // Public augmentation point. Pass current datavalue and all info
   215  // in record buffer. Should return what you want to see on the screen.
   216  // Augment to support various description/data Display formats.
   217  //
   218  { MethodType=Event }
   219  Function Combo_Description_Value String DescVal String DataVal returns string
   220      Integer Mode
   221      Get Code_Display_Mode to mode
   222      If mode eq CB_CODE_DISPLAY_CODE ;
   223         Move DataVal to DescVal
   224      Else If mode eq CB_CODE_DISPLAY_BOTH ;
   225         Move (DataVal * "-" * DescVal) to DescVal
   226      Function_Return DescVal
   227   End_Function // Combo_Description_Value
   228
   229
   230
   231  // Message to add Items to a list. Similar to Add_Item except
   232  // it handles an optional second parameter. If no 2nd param the first
   233  // is used in its place. This will normally be used inside of Fill_List.
   234  //
   235  // Send Add_Combo_Item Descr_Value {Data_Value}
   236  //
   237  Procedure Combo_Add_Item String Descr_value String Data_Value
   238    String  dVal
   239    Integer itm
   240    // If one param passed use it for both display and database values
   241    If num_arguments le 1 Move Descr_Value to dVal
   242    Else                  Move Data_Value  to dVal
   243    Get Combo_item_count to itm         // get this before we add the item.
   244
   245    // If no items we have a new list. We want to know if it is data only
   246    // of data descr. By default, assume that it is data-only
   247    If itm eq 0 Set Data_Only_State to True
   248
   249    // this lets us convert the description. By default it returns the
   250    // value passed. This allows you to pass a data param that gets
   251    // changed for display purposes.
   252    If (Code_Display_Mode(self)=CB_CODE_DISPLAY_CODE) ;
   253       Move dVal to Descr_Value
   254    Else ;
   255       Get Combo_Description_Value Descr_Value dVal to Descr_Value
   256    Forward send Combo_Add_Item Descr_Value // used by the display list
   257    Set Entry_Value Item itm to dVal  // the actual data value
   258
   259    // If description does not match the data we set this flag false
   260    If (Descr_Value<>dVal AND Data_Only_State(self) ) ;
   261       Set Data_Only_State to False
   262  End_Procedure
   263
   264  // Can be used by iEntry or inside of Entry_Defaults
   265  //
   266  Procedure Default_Prompt Integer Item#
   267    Integer OldSt
   268    Get Change_Disabled_State to OldSt     // As it was in the beginning
   269    Set Change_Disabled_State to TRUE      // though changed by the tides
   270    Send Default_Code (Default_Value(self))
   271    Set Change_Disabled_State to OldSt     // it will be as it was. Amen
   272  End_Procedure
   273
   274  Procedure Default_Code string Dflt
   275    If ( Item_Changed_State(self,0)=0 AND ;
   276         Value(self,0)="" ) Begin
   277            Send Display_Description Dflt
   278            Set Item_Changed_State Item 0 to TRUE
   279    end
   280  End_Procedure
   281
   282End_Class
   283
   284
   285