File: eaf_n_cst_dataobjectrulesservice.sru
Size: 87505
Date: Tue, 22 Jan 2008 23:39:41 +0100
$PBExportHeader$eaf_n_cst_dataobjectrulesservice.sru
forward
global type eaf_n_cst_dataobjectrulesservice from n_cst_baseservice
end type
end forward

shared variables

end variables

global type eaf_n_cst_dataobjectrulesservice from n_cst_baseservice
string is_logservice = "n_cst_loggingservice"
end type
global eaf_n_cst_dataobjectrulesservice eaf_n_cst_dataobjectrulesservice

type variables
Protected:
// Expression constants
constant string   NO_EXPRESSION              = '___NOTAPPLICABLE___' // NOT_APPLICABLE_STRING
constant long     NO_COLOR                   = -99999                // NOT_APPLICABLE_NUMBER

// Colors constants
constant long     BUTTONFACE              = 78682240
constant long     WINDOW_BACKGROUND       = 1087434968
constant long     WINDOW_TEXT             = 33554592

// Other attributes
datastore         ids_requestor
long              il_defaultcolor         = 0
long              il_boldtext             = 700
long              il_normaltext           = 400
end variables

forward prototypes
public function long setrequestor (datastore ads_requestor)
public function boolean computedexists (string as_computed)
public function boolean computedexists (string as_computeds[])
public function boolean datafieldexists (string as_object)
public function boolean datafieldexists (string as_objects[])
public function long requestboldtext (string as_object)
public function long requestdisplayonly (string as_column)
public function long requestemptyisnull (string as_column)
public function long requestnormaltext (string as_object)
public function long requestprotect (string as_object)
public function long requestprotectbackgroundbuttonface (string as_object)
public function long requestreadonly (string as_column)
public function long requestreadonly (string as_columns[])
public function long requestrequiredemptyisnull (string as_column)
public function long requesttextcolor (string as_object, long al_color)
public function long requesttextcolor (string as_object, string as_expression)
public function long requesttextcolor (string as_object, string as_expression, long al_color)
public function boolean columnexists (string as_column)
public function boolean columnexists (string as_columns[])
public function long requestrequired (string as_column)
public function boolean objectexists (string as_objects[])
public function long requestbackgroundbuttonface (string as_object)
public function long requestbackgroundbuttonface (string as_object, string as_expression)
public function long requestboldtext (string as_object, string as_expression)
public function long requestinitialvalue (string as_column, string as_value)
public function long requestprotect (string as_object, string as_expression)
public function long requestprotectbackgroundbuttonface (string as_object, string as_expression)
public function long requestprotectbackgroundcolor (string as_object, string as_expression, long al_color)
public function long requestnormaltext (string as_object, string as_expression)
public function long requestvalidation (string as_column, string as_expression, string as_displaymessage)
public function long requestrequiredemptyisnull (string as_columns[])
public function long modify (string as_expressionlist)
protected function long requesttextcolor (string as_object, string as_expression, long al_expression_truecolor, long al_expression_falsecolor)
public function long requestrequired (string as_columns[])
public function long requestemptyisnull (string as_columns[])
public function long requestdisplayonly (string as_columns[])
public function string calculatedefaultcolor (string as_expression, string as_default)
public function boolean objectexists (string as_object)
public function long requestprotectbackgroundcolor (string as_object, long al_color)
public function long requestbackgroundcolor (string as_object, string as_expression, long al_color)
public function long requestbackgroundcolor (string as_object, long al_color)
public function long requestbackgroundcolor (string as_object, string as_expression)
protected function long requestbackgroundcolor (string as_object, string as_expression, long al_expression_truecolor, long al_expression_falsecolor)
public function string evaluate (string as_expression, long al_row)
public function long setdropdownlistbox (string as_column, string as_selectsql, boolean ab_showcode, ref string as_modifyexpression)
public function long setdropdownlistbox (string as_column, string as_selectsql, boolean ab_showcode)
end prototypes

public function long setrequestor (datastore ads_requestor);////////////////////////////////////////////////////////////////
// Description:
//    Sets the requestor object requesting the service
//    A requirement for much of the functionality provided by the
//    service
// Revisions
//    1.0   - Initial version
// Arguments:  
//    ads_requestor - The requesting object
// Returns: 
//     1 = success
//    -1 = failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setRequestor "

// Validate arguments
If IsNull(ads_requestor) or Not isValid(ads_requestor) Then
   addError(METHOD_NAME, "Invalid ads_requestor argument")
   Return -1
End If

ids_requestor = ads_requestor

Return 1
end function

public function boolean computedexists (string as_computed);////////////////////////////////////////////////////////////////
// Description:
//    Checks if the computed field passed in exists
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_computed - The computed field names to check on
// Returns: 
//    true or false depending if the objects exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "computedExists "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_computed)    as_computed="+as_computed)
End If   

// Declare local variables
string   ls_computeds[]
boolean  lb_method_rc

// Move single entry into array
ls_computeds[1] = as_computed

lb_method_rc = columnExists(ls_computeds)
Return lb_method_rc
end function

public function boolean computedexists (string as_computeds[]);////////////////////////////////////////////////////////////////
// Description:
//    Checks if all the Computed Fields passed in exists
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_computeds[] - The computed fields names to check on
// Returns: 
//    true or false depending if the objects exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "computedExists "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_computeds[])")
End If   

// Declare local variables
long     ll_upper
long     ll_idx
string   ls_type

// Validate arguments
If IsNull(as_computeds) Then
   addError(METHOD_NAME, "Invalid as_computeds argument")
   Return false
End If
ll_upper = upperBound(as_computeds)
If upperBound(as_computeds) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_computeds argument")
   Return false
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return false
End If

// Determine that requirements are met by looping around all objects
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_computeds[ll_idx] = trim(as_computeds[ll_idx])
   If IsNull(as_computeds[ll_idx]) Or Len(as_computeds[ll_idx]) = 0 Then 
      If IsNull(as_computeds[ll_idx]) Then as_computeds[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_computeds["+string(ll_idx)+"] = '"+as_computeds[ll_idx]+"'")
      Return false
   End If      
   
   // Check for the desired object type
   ls_type = lower(ids_requestor.Describe (as_computeds[ll_idx]+'.Type'))     
   If ls_type <> 'compute' Then
      Return false
   End If
Next

// All objects passed in were of the appropriate type
Return true
end function

public function boolean datafieldexists (string as_object);////////////////////////////////////////////////////////////////
// Description:
//    Checks if the object passed in exists as a DataField
//    DataField is defined as a Column or ComputedField
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The as_object name to check on
// Returns: 
//    true or false depending if the object exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "dataFieldExists "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object)    as_object="+as_object)
End If   

// Declare local variables
string   ls_objects[]
boolean  lb_method_rc

// Move single entry into array
ls_objects[1] = as_object

lb_method_rc = dataFieldExists(ls_objects)
Return lb_method_rc
end function

public function boolean datafieldexists (string as_objects[]);////////////////////////////////////////////////////////////////
// Description:
//    Checks if the object passed in exists as a DataField
//    DataField is defined as a Column or ComputedField
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_objects[] - The object names to check on
// Returns: 
//    true or false depending if the object exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "dataFieldExists "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_objects[])")
End If   

// Declare local variables
long     ll_upper
long     ll_idx
string   ls_type

// Validate arguments
If IsNull(as_objects) Then
   addError(METHOD_NAME, "Invalid as_objects argument")
   Return false
End If
ll_upper = upperBound(as_objects)
If upperBound(as_objects) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_objects argument")
   Return false
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return false
End If

// Determine that requirements are met by looping around all objects
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_objects[ll_idx] = trim(as_objects[ll_idx])
   If IsNull(as_objects[ll_idx]) Or Len(as_objects[ll_idx]) = 0 Then 
      If IsNull(as_objects[ll_idx]) Then as_objects[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_objects["+string(ll_idx)+"] = '"+as_objects[ll_idx]+"'")
      Return false
   End If      
   
   // Check for a Column
   If columnExists(as_objects[ll_idx]) Then
      Continue
   End If   

   
   // Check for a Computed Field
   If computedExists(as_objects[ll_idx]) Then
      Continue
   End If   
   
   // Not the appropriate type
   Return false
Next

// Success, All the fields were found
Return true
end function

public function long requestboldtext (string as_object);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get BOLDed
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified

// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestBoldText "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object)   as_object="+as_object)
End If   

Return requestBoldText(as_object, NO_EXPRESSION)
end function

public function long requestdisplayonly (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Requests a ReadOnly column
//
//    This is not applicable to all column editstyles
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The column to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestDisplayOnly "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_column)   as_column="+as_column)
End If

// Declare local variables
string   ls_columns[]
long     ll_method_rc

// Move single entry into array
ls_columns[1] = as_column

ll_method_rc = requestDisplayOnly (ls_columns)
Return ll_method_rc
end function

public function long requestemptyisnull (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in column get its NillIsNull property 
//    turned on
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The object to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestEmptyIsNull "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_column)   as_column="+as_column)
End If

// Declare local variables
string   ls_columns[]
long     ll_method_rc

// Move single entry into array
ls_columns[1] = as_column

ll_method_rc = requestEmptyIsNull (ls_columns)
Return ll_method_rc
end function

public function long requestnormaltext (string as_object);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get Normal Text
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestNormalText "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object)   as_object="+as_object)
End If

Return requestNormalText(as_object, NO_EXPRESSION)
end function

public function long requestprotect (string as_object);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get Protected
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestProtect "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object)   as_object="+as_object)
End If

Return requestProtect(as_object, NO_EXPRESSION)
end function

public function long requestprotectbackgroundbuttonface (string as_object);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive a Protect and BUTTONFACE color
//    for its background
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestProtectBackgroundButtonface "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object)   as_object="+as_object)
End If

Return requestProtectBackgroundButtonface( as_object, NO_EXPRESSION)
end function

public function long requestreadonly (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Requests a set of ReadOnly column (tab set to zero)
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The column to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestReadOnly "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_column)   as_column="+as_column)
End If

// Declare local variables
string   ls_columns[]
long     ll_method_rc

// Move single entry into array
ls_columns[1] = as_column

ll_method_rc = requestReadOnly(ls_columns)
Return ll_method_rc
end function

public function long requestreadonly (string as_columns[]);////////////////////////////////////////////////////////////////
// Description:
//    Requests a set of ReadOnly columns (tab set to zero)
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_columns[] - The columns to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestReadOnly "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_columns[])")
End If   

// Declare local variables
constant string   ATTRIBUTE = 'TabSequence'
long     ll_upper
long     ll_idx
long     ll_method_rc = 1
string   ls_modifyexp

// Validate arguments
If IsNull(as_columns) Then
   addError(METHOD_NAME, "Invalid as_columns argument")
   Return -1
End If
ll_upper = upperBound(as_columns)
If upperBound(as_columns) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_columns argument")
   Return -1
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// Loop around all entries 
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_columns[ll_idx] = trim(as_columns[ll_idx])
   If IsNull(as_columns[ll_idx]) Or Len(as_columns[ll_idx]) = 0 Then 
      If IsNull(as_columns[ll_idx]) Then as_columns[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      ll_method_rc = -1
      Continue
   End If      

   // Build the Modify Expression
   ls_modifyexp = as_columns[ll_idx] + '.' + ATTRIBUTE + ' = ' + "0"

   // Execute the Expression
   If modify (ls_modifyexp) <= 0 Then
      ll_method_rc = -1
   End If
Next

Return ll_method_rc
end function

public function long requestrequiredemptyisnull (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Request a Required and EmptyIsNull column
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The column to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestRequiredEmptyIsNull "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_column)   as_column="+as_column)
End If

// Declare local variables
string   ls_columns[]
long     ll_method_rc

// Move single entry into array
ls_columns[1] = as_column

ll_method_rc = requestRequiredEmptyIsNull (ls_columns)
Return ll_method_rc

end function

public function long requesttextcolor (string as_object, long al_color);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get its TEXT COLORED to the
//    passed in color
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    al_color - The color to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestTextColor "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, al_color)   " + &
      "as_object="+as_object+"   al_color="+string(al_color))
End If

Return requestTextColor(as_object, NO_EXPRESSION, al_color, NO_COLOR)
end function

public function long requesttextcolor (string as_object, string as_expression);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get its TEXT COLORED to the
//    passed in Color Expression
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//   as_expression string value - The expression to be used to come up with the color
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestTextColor "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression)    " + &
      "as_object="+as_object+"   as_expression="+as_expression)
End If

Return requestTextColor(as_object, as_expression, NO_COLOR, NO_COLOR)
end function

public function long requesttextcolor (string as_object, string as_expression, long al_color);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get its TEXT COLORED to the
//    passed in Color when the passed in Expression is met
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
//    al_color -  The color to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestTextColor "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression, al_color)    " + &
      "as_object="+as_object+"   as_expression="+as_expression+"   al_color="+string(al_color))
End If

Return requestTextColor(as_object, as_expression, al_color, NO_COLOR)
end function

public function boolean columnexists (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Checks if the column passed in exists
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The column name to check on
// Returns: 
//    true or false depending if the object exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "columnExists "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_column)    as_column="+as_column)
End If   

// Declare local variables
string   ls_columns[]
boolean  lb_method_rc

// Move single entry into array
ls_columns[1] = as_column

lb_method_rc = columnExists(ls_columns)
Return lb_method_rc
end function

public function boolean columnexists (string as_columns[]);////////////////////////////////////////////////////////////////
// Description:
//    Checks if all the columns passed in exists
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_columns[] - The column names to check on
// Returns: 
//    true or false depending if the objects exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "columnExists "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_columns[])")
End If   

// Declare local variables
long     ll_upper
long     ll_idx
string   ls_type

// Validate arguments
If IsNull(as_columns) Then
   addError(METHOD_NAME, "Invalid as_columns argument")
   Return false
End If
ll_upper = upperBound(as_columns)
If upperBound(as_columns) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_columns argument")
   Return false
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return false
End If

// Determine that requirements are met by looping around all objects
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_columns[ll_idx] = trim(as_columns[ll_idx])
   If IsNull(as_columns[ll_idx]) Or Len(as_columns[ll_idx]) = 0 Then 
      If IsNull(as_columns[ll_idx]) Then as_columns[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      Return false
   End If      
   
   // Check for the desired object type
   ls_type = lower(ids_requestor.Describe (as_columns[ll_idx]+'.Type'))    
   If ls_type <> 'column' Then
      Return false
   End If
Next

// All objects passed in were of the appropriate type
Return true
end function

public function long requestrequired (string as_column);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in column get Marked as Required
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The object to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestRequired "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_column)   as_column="+as_column)
End If

// Declare local variables
string   ls_columns[]
long     ll_method_rc

// Move single entry into array
ls_columns[1] = as_column

ll_method_rc = requestRequired (ls_columns)
Return ll_method_rc
end function

public function boolean objectexists (string as_objects[]);////////////////////////////////////////////////////////////////
// Description:
//    Checks if the object passed in exists 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_objects[] - The object names to check on
// Returns: 
//    true or false depending if the object exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "objectExists "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_objects[])")
End If   

// Declare local variables
long     ll_upper
long     ll_idx
string   ls_type

// Validate arguments
If IsNull(as_objects) Then
   addError(METHOD_NAME, "Invalid as_objects argument")
   Return false
End If
ll_upper = upperBound(as_objects)
If upperBound(as_objects) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_objects argument")
   Return false
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return false
End If

// Determine that requirements are met by looping around all objects
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_objects[ll_idx] = trim(as_objects[ll_idx])
   If IsNull(as_objects[ll_idx]) Or Len(as_objects[ll_idx]) = 0 Then 
      If IsNull(as_objects[ll_idx]) Then as_objects[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_objects["+string(ll_idx)+"] = '"+as_objects[ll_idx]+"'")
      Return false
   End If      
   
   // Check for the existance
   ls_type = lower(ids_requestor.Describe (as_objects[ll_idx]+'.Type'))    
   If isNull(ls_type) Or ls_type='!' Or ls_type='?' Or ls_type='' Then
      Return false
   End If
Next

// Success, All the fields were found
Return true
end function

public function long requestbackgroundbuttonface (string as_object);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive the BUTTONFACE color
//    for its background
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestBackgroundButtonface "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object)    as_object="+as_object)
End If   

Return requestBackgroundColor (as_object, BUTTONFACE)
end function

public function long requestbackgroundbuttonface (string as_object, string as_expression);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive the BUTTONFACE color
//    for its background when the passed in expression is met
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestBackgroundButtonface "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression)  "+ &
      "as_object="+as_object+"  as_expression="+as_expression)
End If   

Return requestBackgroundColor (as_object, as_expression, BUTTONFACE)
end function

public function long requestboldtext (string as_object, string as_expression);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get BOLDed when the passed
//    in expression is met
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestBoldText "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression) ~r~n" + &
      "   as_object     =" + as_object + "~r~n" + &
      "   as_expression =" + as_expression)
End If   

// Declare local variables
constant string ATTRIBUTE = 'Font.Weight'
string   ls_ifexpression
string   ls_modifyexp
string   ls_default

// Perform cleanup
as_object = Trim (as_object)
as_expression = Trim (as_expression)

// Validate arguments
If IsNull(as_object) Or Len (as_object)=0 Then 
   addError(METHOD_NAME, "Invalid as_object argument")   
   Return -1
End If
If IsNull(as_expression) Or Len(as_expression) = 0 Then 
   addError(METHOD_NAME, "Invalid as_expression argument")  
   Return -1
End If

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// If need be, clear out the expression variable
If as_expression = NO_EXPRESSION Then
   as_expression = ''
End If

// Determine if this will have an ifExpression
If Len(as_expression) > 0 Then
   // Determine the default value
   ls_default = string(il_normaltext)

   // Construct the ifExpression
   ls_ifexpression = "If ( " + as_expression + ", " + &
                     string(il_boldtext) + ", " + &
                     string(il_normaltext) + " )"
Else
   ls_default = string(il_boldtext)
End If

// Build the Modify Expression
ls_modifyexp = as_object + '.' + ATTRIBUTE + ' = ' + "~"" + ls_default
If Len(ls_ifexpression) > 0 Then 
   ls_modifyexp += "~t" + ls_ifexpression
End If
ls_modifyexp += "~""

// Execute the Expression
Return modify (ls_modifyexp)
end function

public function long requestinitialvalue (string as_column, string as_value);////////////////////////////////////////////////////////////////
// Description:
//    Requests a column to have an Initial value attribute
//
//    This is not applicable to all column editstyles
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column   - The column to be modified
//    as_value    - The initial value to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestInitialValue "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_column, as_value)    "+ &
      "as_column="+as_column+" as_value="+as_value)
End If   

// Declare local variables
constant string ATTRIBUTE = 'Initial'
string   ls_type
string   ls_modifyexp

// Perform cleanup
as_column = Trim (as_column)

// Validate arguments
If IsNull(as_column) Or len(as_column) = 0 Then
   addError(METHOD_NAME, "Invalid as_column argument")
   Return -1
End If
If IsNull(as_value) Then 
   // It is OK to have an empty value
   addError(METHOD_NAME, "Invalid as_value argument") 
   Return -1
End If

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// Validate the column
ls_type = ids_requestor.Describe (as_column+'.Type')
If Lower(ls_type) <> 'column' Then 
   addError(METHOD_NAME, "Invalid as_column argument (not column type)")   
   Return -1
End If   

// Construct the Expression
if Left(as_value, 1) <> "'" and Left(as_value, 1) <> '"' then
   as_value = "~"" + as_value
end if
if Right(as_value, 1) <> "'" and Right(as_value, 1) <> '"' then
   as_value = as_value + "~""
end if
ls_modifyexp = as_column + '.' + ATTRIBUTE + ' = ' + as_value

// Execute the Expression
Return modify (ls_modifyexp)
end function

public function long requestprotect (string as_object, string as_expression);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get Protected when the passed
//    in expression is met
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestProtect "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression) ~r~n" + &
      "   as_object     =" + as_object + "~r~n" + &
      "   as_expression =" + as_expression)
End If   

// Declare local variables
constant string ATTRIBUTE = 'Protect'
string   ls_ifexpression
string   ls_modifyexp
string   ls_default

// Perform cleanup
as_object = Trim (as_object)
as_expression = Trim (as_expression)

// Validate arguments
If IsNull(as_object) Or Len (as_object)=0 Then 
   addError(METHOD_NAME, "Invalid as_object argument")      
   Return -1
End If   
If IsNull(as_expression) or Len(as_expression) = 0 Then 
   addError(METHOD_NAME, "Invalid as_expression argument")     
   Return -1
End If      

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// If need be, clear out the expression variable
If as_expression = NO_EXPRESSION Then
   as_expression = ''
End If

// Determine if this will have an ifExpression
If Len(as_expression) > 0 Then
   // Determine the default value
   ls_default = "0"

   // Construct the ifExpression
   ls_ifexpression = "If ( " + as_expression + ", " + &
                     "1" + ", " + ls_default + " )"
Else
   ls_default = "1"
End If

// Build the Modify Expression
ls_modifyexp = as_object + '.' + ATTRIBUTE + ' = ' + "~"" + ls_default
If Len(ls_ifexpression) > 0 Then
   ls_modifyexp += "~t" + ls_ifexpression
End If
ls_modifyexp += "~""

// Execute the Expression
Return modify (ls_modifyexp)
end function

public function long requestprotectbackgroundbuttonface (string as_object, string as_expression);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive a Protect and BUTTONFACE color
//    for its background when the passed in expression is met
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestProtectBackgroundButtonface "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression) ~r~n" + &
      "   as_object     =" + as_object + "~r~n" + &
      "   as_expression =" + as_expression)
End If   

// Declare local variables
long  ll_rc
long  ll_method_rc = 1

// Perform the Protection modify
ll_rc = requestProtect (as_object, as_expression)
If ll_rc <= 0 Then
   ll_method_rc = -1
End If

// Perform the Background Buttonface modify
ll_rc = requestBackgroundButtonface (as_object, as_expression)
If ll_rc <= 0 Then
   ll_method_rc = -1
End If

Return ll_method_rc
end function

public function long requestprotectbackgroundcolor (string as_object, string as_expression, long al_color);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive a Protect and a passed in color
//    for its background when the passed in expression is met
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
//    al_color - The color to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestProtectBackgroundColor "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression, al_color) ~r~n" + &
      "   as_object     =" + as_object + "~r~n" + &
      "   as_expression =" + as_expression + "~r~n" + &
      "   al_color      =" + string(al_color))
End If   

// Declare local variables
long  ll_rc
long  ll_method_rc

// Perform the Protection modify
ll_rc = requestProtect (as_object, as_expression)
If ll_rc <= 0 Then
   ll_method_rc = -1
End If

// Perform the Background Color modify
ll_rc = requestBackgroundColor (as_object, as_expression, al_color)
If ll_rc <= 0 Then
   ll_method_rc = -1
End If

Return ll_method_rc
end function

public function long requestnormaltext (string as_object, string as_expression);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get Normal Text when the passed
//    in expression is met
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestNormalText "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression) ~r~n" + &
      "   as_object     =" + as_object + "~r~n" + &
      "   as_expression =" + as_expression)
End If   

// Declare local variables
constant string ATTRIBUTE = 'Font.Weight'
string   ls_ifexpression
string   ls_modifyexp
string   ls_default

// Perform cleanup
as_object = Trim (as_object)
as_expression = Trim (as_expression)

// Validate arguments
If IsNull(as_object) Or Len (as_object)=0 Then 
   addError(METHOD_NAME, "Invalid as_object argument")   
   Return -1
End If
If IsNull(as_expression) Or Len(as_expression) = 0 Then 
   addError(METHOD_NAME, "Invalid as_expression argument")  
   Return -1
End If

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// If need be, clear out the expression variable
If as_expression = NO_EXPRESSION Then
   as_expression = ''
End If

// Determine if this will have an ifExpression
If Len(as_expression) > 0 Then
   // Determine the default value
   ls_default = string(il_boldtext)

   // Construct the ifExpression
   ls_ifexpression = "If ( " + as_expression + ", " + &
                     string(il_normaltext) + ", " + &
                     string(il_boldtext) + " )"
Else
   ls_default = string(il_normaltext)
End If

// Build the Modify Expression
ls_modifyexp = as_object + '.' + ATTRIBUTE + ' = ' + "~"" + ls_default
If Len(ls_ifexpression) > 0 Then 
   ls_modifyexp += "~t" + ls_ifexpression
End If   
ls_modifyexp += "~""

// Execute the Expression
Return modify (ls_modifyexp)
end function

public function long requestvalidation (string as_column, string as_expression, string as_displaymessage);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in column receive the passed in validation
//    expression and validation message
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column - The column to be modified
//    as_expression - The expression to be assigned
//    as_displaymessage - The message to be assigned
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestValidation "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_column, as_expression, " + &
      "as_displaymessage)~r~n" + &
      "   as_column         ="+as_column + "~r~n" + &
      "   as_expression     ="+as_expression + "~r~n" + &
      "   as_displaymessage ="+string(as_displaymessage) )
End If   

// Declare local variables
constant string ATTRIBUTE = 'Validation'
constant string ATTRIBUTE_MESSAGE = 'ValidationMsg'
long     ll_method_rc = 1 
string   ls_ifexpression
string   ls_modifyexp
string   ls_expression

// Perform cleanup
as_column = Trim (as_column)
as_expression = Trim (as_expression)
as_displaymessage = Trim (as_displaymessage)

// Validate arguments
If IsNull(as_column) Or Len (as_column)=0 Then 
   addError(METHOD_NAME, "Invalid as_column argument")   
   Return -1
End If   
If IsNull(as_expression) Then 
   // Allow empty expression
   addError(METHOD_NAME, "Invalid as_expression argument")     
   Return -1
End If   
If IsNull(as_displaymessage) Then 
   // Allow empty display message   
   addError(METHOD_NAME, "Invalid as_displaymessage argument")    
   Return -1
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// Build the Validation expression
ls_modifyexp = as_column + '.' + ATTRIBUTE + ' = ' + &
                  "~"" + as_expression + "~""

// Execute the Expression
If modify (ls_modifyexp) < 0 Then
   ll_method_rc = -1
End If

// Build the Validation Message expression
ls_modifyexp = as_column + '.' + ATTRIBUTE_MESSAGE + ' = ' + &
                     "~"" + as_displaymessage + "~""

// Execute the Expression
If modify (ls_modifyexp) < 0 Then
   ll_method_rc = -1
End If

Return ll_method_rc
end function

public function long requestrequiredemptyisnull (string as_columns[]);////////////////////////////////////////////////////////////////
// Description:
//    Request a set of Required and EmptyIsNull columns
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_columns[] - The columns to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestRequiredEmptyIsNull "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_columns[])")
End If

// Declare local variables
long  ll_method_rc = 1

If requestRequired (as_columns) <= 0 Then
   ll_method_rc = -1 
End If

If requestEmptyIsNull (as_columns) <= 0 Then
   ll_method_rc = -1
End If

Return ll_method_rc
end function

public function long modify (string as_expressionlist);////////////////////////////////////////////////////////////////
// Description:
//    Modifies a DataWindow object by applying specifications, 
//    given as a list of instructions, that change the DataWindow 
//    object's definition
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_expressionlist - The expression list
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "modify "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_expressionlist)    as_expressionlist="+as_expressionlist)
End If

// Declare local variables
string ls_return

// Perform cleanup
as_expressionlist = Trim(as_expressionlist)

// Validate arguments
If IsNull(as_expressionlist) Or Len(as_expressionlist)=0 Then 
   Return -1
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// Perform the actual Modify of the expressionlist
ls_return = ids_requestor.Modify ( as_expressionlist )

// Validate the Modify expression return code
If Len(ls_return) > 0 Then
   If ib_debug Or ib_warning Then
      inv_log.warningLog (METHOD_NAME,"Modify Expression Failed ("+ as_expressionlist + ")~r~n" + &
         "rc="+ls_return)
   End If
   Return -1
End If

inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Modify Expression Succeeded: "+ as_expressionlist)

Return 1
end function

protected function long requesttextcolor (string as_object, string as_expression, long al_expression_truecolor, long al_expression_falsecolor);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object get its TEXT COLORED according
//    to the passed in arguments
//
//    If an expression is found it must be one that can be resolved into a color
//    If no expression is found then it is always a True expression
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression that needs to be met
//    al_expression_truecolor -  The color to be assigned when the expression is true
//    al_expression_falsecolor - The color to be assigned when the expression is false
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestTextColor "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression, " + &
      "al_expression_truecolor, al_expression_falsecolor)~r~n" + &
      "   as_object                ="+as_object + "~r~n" + &
      "   as_expression            ="+as_expression + "~r~n" + &
      "   al_expression_truecolor  ="+string(al_expression_truecolor) + "~r~n" + &
      "   al_expression_falsecolor ="+string(al_expression_falsecolor) )
End If   

// Declare local variables
constant string ATTRIBUTE = 'Color'
string   ls_ifexpression
string   ls_modifyexp
string   ls_defaultcolor

// Perform cleanup
as_object = Trim (as_object)
as_expression = Trim (as_expression)

// Validate arguments
If IsNull(as_object) Or Len (as_object)=0 Then 
   addError(METHOD_NAME, "Invalid as_object argument")   
   Return -1
End If   
If IsNull(as_expression) or Len(as_expression) = 0 Then 
   addError(METHOD_NAME, "Invalid as_expression argument")  
   Return -1
End If      
If IsNull(al_expression_truecolor)  Then 
   addError(METHOD_NAME, "Invalid al_expression_truecolor argument")    
   Return -1
End If      
If IsNull(al_expression_falsecolor) Then 
   addError(METHOD_NAME, "Invalid al_expression_falsecolor argument")      
   Return -1
End If      
If al_expression_truecolor >= 0 Or al_expression_truecolor = NO_COLOR Then
   // Either a color or the Internal code for NO_COLOR was passed in
Else
   addError(METHOD_NAME, "Invalid al_expression_truecolor argument")          
   Return -1
End If
If al_expression_falsecolor >= 0 Or al_expression_falsecolor = NO_COLOR Then
   // Either a color or the Internal code for NO_COLOR was passed in
Else
   addError(METHOD_NAME, "Invalid al_expression_falsecolor argument")            
   Return -1
End If
If as_expression = NO_EXPRESSION And al_expression_truecolor = NO_COLOR Then
   addError(METHOD_NAME, "Invalid as_expression/al_expression_truecolor argument combination")  
   Return -1
End If

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// If need be, clear out the expression variable
If as_expression = NO_EXPRESSION Then
   as_expression = ''
End If

// Set up the default value
ls_defaultcolor = ids_requestor.Describe(as_object+"."+ATTRIBUTE)
If ls_defaultcolor='!' Or ls_defaultcolor='?' Then 
   If ib_warning Then
      inv_log.warningLog (METHOD_NAME, "Describe(" + as_object+"."+ATTRIBUTE +") failed")
   End If
   Return -1
End If   
ls_defaultcolor = calculateDefaultColor (ls_defaultcolor, String(WINDOW_TEXT))

// Determine what type of expression is buing built
If al_expression_truecolor < 0 And al_expression_falsecolor < 0 And Len(as_expression) > 0 Then
   // The as_expression is an expression whose result is the color
   ls_modifyexp = as_object + '.' + ATTRIBUTE + ' = ' + "~"" + ls_defaultcolor + &
                  "~t" + as_expression + "~""
Else
   // Determine if this will have an ifExpression
   If Len(as_expression) > 0 Then
      // Determine the default value
      If al_expression_falsecolor >= 0 Then
         ls_defaultcolor = String (al_expression_falsecolor)
      End If
      
      // Construct the ifExpression
      ls_ifexpression = "If ( " + as_expression + ", " + &
                     String(al_expression_truecolor) + ", " + &
                     ls_defaultcolor + " )"
   Else
      ls_defaultcolor = String(al_expression_truecolor)
   End If

   // Build the Modify Expression
   ls_modifyexp = as_object + '.' + ATTRIBUTE + ' = ' + "~"" + ls_defaultcolor
   If Len(ls_ifexpression) > 0 Then 
      ls_modifyexp += "~t" + ls_ifexpression
   End If
   ls_modifyexp += "~""
End If

// Execute the Expression
Return modify (ls_modifyexp)
end function

public function long requestrequired (string as_columns[]);////////////////////////////////////////////////////////////////
// Description:
//    Requests a set of Required columns 
//
//    This is not applicable to all column editstyles
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_columns[] - The columns to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestRequired "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_columns[])")
End If   

// Declare local variables
constant string PARTIAL_ATTRIBUTE = 'Required'
long     ll_idx
long     ll_upper
long     ll_method_rc = 1
boolean  lb_supported
string   ls_editstyle
string   ls_modifyexp
string   ls_attribute = ''

// Validate arguments
If IsNull(as_columns) Then
   addError(METHOD_NAME, "Invalid as_columns argument")
   Return -1
End If
ll_upper = upperBound(as_columns)
If upperBound(as_columns) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_columns argument")
   Return -1
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// Loop around all entries on the array
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_columns[ll_idx] = trim(as_columns[ll_idx])
   If IsNull(as_columns[ll_idx]) Or Len(as_columns[ll_idx]) = 0 Then 
      If IsNull(as_columns[ll_idx]) Then as_columns[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      ll_method_rc = -1
      Continue
   End If   
   
   // Determine the column editstyle
   ls_editstyle = Lower(ids_requestor.Describe(as_columns[ll_idx]+".Edit.Style"))
   If isNull(ls_editstyle) Or ls_editstyle = '' Or ls_editstyle='!' Or ls_editstyle='?' Then
      If ib_warning Then
         inv_log.warningLog(METHOD_NAME, "Invalid editstyle in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      End If         
      ll_method_rc = -1
      Continue
   End If

   // Build the Attribute to be modified (taking into consideration what is suported)
   Choose Case ls_editstyle
      Case 'dddw'
         ls_attribute = 'DDDW.'+ PARTIAL_ATTRIBUTE
         lb_supported = true
      Case 'ddlb'
         ls_attribute = 'DDLB.'+ PARTIAL_ATTRIBUTE 
         lb_supported = true
      Case 'edit'
         ls_attribute = 'Edit.'+ PARTIAL_ATTRIBUTE
         lb_supported = true
      Case 'editmask'
         ls_attribute = 'EditMask.'+ PARTIAL_ATTRIBUTE   
         lb_supported = true
      Case 'radiobutton', 'checkbox'
         // Not supported by PB 7
         lb_supported = false
      Case Else
         // Unrecognized edit style
         lb_supported = true
   End Choose

   // Check if call is supported
   If Not lb_supported Then
      If ib_warning Then
         inv_log.warningLog(METHOD_NAME,'- Call not supported due to EditStyle('+ls_editstyle+'): '+ &
                  as_columns[ll_idx]+'.'+ls_attribute)
      End If
      ll_method_rc = -1
      Continue
   End If

   // Build and Exectue the Expression
   ls_modifyexp = as_columns[ll_idx] + '.' + ls_attribute + ' = ' + "Yes" 
   If modify (ls_modifyexp) <= 0 Then
      ll_method_rc = -1
      Continue
   End If   
Next

Return ll_method_rc
end function

public function long requestemptyisnull (string as_columns[]);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in columns get its NillIsNull property
//    turned on
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_columns[] - The columns to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestEmptyIsNull "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_columns[])")
End If

// Declare local variables
constant string PARTIAL_ATTRIBUTE = 'NilIsNull'
long     ll_idx
long     ll_upper
long     ll_method_rc = 1
boolean  lb_supported
string   ls_editstyle
string   ls_modifyexp
string   ls_attribute = ''

// Validate arguments
If IsNull(as_columns) Then
   addError(METHOD_NAME, "Invalid as_columns argument")
   Return -1
End If
ll_upper = upperBound(as_columns)
If upperBound(as_columns) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_columns argument")
   Return -1
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// Loop around all entries on the array
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_columns[ll_idx] = trim(as_columns[ll_idx])
   If IsNull(as_columns[ll_idx]) Or Len(as_columns[ll_idx]) = 0 Then 
      If IsNull(as_columns[ll_idx]) Then as_columns[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      ll_method_rc = -1
      Continue
   End If   

   // Determine the column editstyle
   ls_editstyle = Lower(ids_requestor.Describe(as_columns[ll_idx]+".Edit.Style"))
   If isNull(ls_editstyle) Or ls_editstyle = '' Or ls_editstyle='!' Or ls_editstyle='?' Then
      If ib_warning Then
         inv_log.warningLog(METHOD_NAME, "Invalid editstyle in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      End If         
      ll_method_rc = -1
      Continue
   End If

   // Build the Attribute to be modified (taking into consideration what is suported)
   Choose Case ls_editstyle
      Case 'dddw'
         ls_attribute = 'DDDW.'+ PARTIAL_ATTRIBUTE
         lb_supported = true
      Case 'ddlb'
         ls_attribute = 'DDLB.'+ PARTIAL_ATTRIBUTE
         lb_supported = true        
      Case 'edit'
         ls_attribute = 'Edit.'+ PARTIAL_ATTRIBUTE
         lb_supported = true        
      Case 'editmask', 'checkbox', 'radiobutton'
         // Not supported by PB 7
         lb_supported = false       
      Case Else
         // Unrecognized edit style
         lb_supported = false
   End Choose
   
   // Check if call is supported
   If Not lb_supported Then
      If ib_warning Then
         inv_log.warningLog(METHOD_NAME,'- Call not supported due to EditStyle('+ls_editstyle+'): '+ &
                  as_columns[ll_idx]+'.'+ls_attribute)
      End If
      ll_method_rc = -1
      Continue
   End If

   // Build and Exectue the Expression
   ls_modifyexp = as_columns[ll_idx] + '.' + ls_attribute + ' = ' + "Yes"
   If modify (ls_modifyexp) <= 0 Then
      ll_method_rc = -1
      Continue
   End If   
Next

Return ll_method_rc
end function

public function long requestdisplayonly (string as_columns[]);////////////////////////////////////////////////////////////////
// Description:
//    Requests a set of ReadOnly columns 
//
//    This is not applicable to all column editstyles
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_columns[] - The columns to be modified
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestDisplayOnly "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_columns[])")
End If   

// Declare local variables
constant string PARTIAL_ATTRIBUTE = 'DisplayOnly'
long     ll_idx
long     ll_upper
long     ll_method_rc = 1
boolean  lb_supported
string   ls_editstyle
string   ls_modifyexp
string   ls_attribute

// Validate arguments
If IsNull(as_columns) Then
   addError(METHOD_NAME, "Invalid as_columns argument")
   Return -1
End If
ll_upper = upperBound(as_columns)
If upperBound(as_columns) <= 0 Then
   addError(METHOD_NAME, "Invalid number of entries on as_columns argument")
   Return -1
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// Loop around all entries on the array
For ll_idx = 1 to ll_upper
   // Cleanup and validate each entry in array
   as_columns[ll_idx] = trim(as_columns[ll_idx])
   If IsNull(as_columns[ll_idx]) Or Len(as_columns[ll_idx]) = 0 Then 
      If IsNull(as_columns[ll_idx]) Then as_columns[ll_idx] = "null"
      addError(METHOD_NAME, "Invalid entry in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      ll_method_rc = -1
      Continue
   End If      

   // Determine the column editstyle
   ls_editstyle = Lower(ids_requestor.Describe(as_columns[ll_idx]+".Edit.Style"))
   If isNull(ls_editstyle) Or ls_editstyle = '' Or ls_editstyle='!' Or ls_editstyle='?' Then
      If ib_warning Then
         inv_log.warningLog(METHOD_NAME, "Invalid editstyle in as_columns["+string(ll_idx)+"] = '"+as_columns[ll_idx]+"'")
      End If
      ll_method_rc = -1
      Continue
   End If
   
   // Build the Attribute to be modified (taking into consideration what is suported)
   Choose Case ls_editstyle
      Case 'edit'
         ls_attribute = 'Edit.'+ PARTIAL_ATTRIBUTE
         lb_supported = true
      Case 'checkbox', 'dddw', 'ddlb', 'editmask', 'radiobutton'
         // Not supported by PB 7
         lb_supported = false       
      Case Else
         // Unrecognized edit style
         lb_supported = false
   End Choose
   
   // Check if call is supported
   If Not lb_supported Then
      If ib_warning Then
         inv_log.warningLog(METHOD_NAME,'- Call not supported due to EditStyle('+ls_editstyle+'): '+ &
                  as_columns[ll_idx]+'.'+ls_attribute)
      End If
      ll_method_rc = -1
      Continue
   End If
   
   // Build and Execute the Expression
   ls_modifyexp = as_columns[ll_idx] + '.' + ls_attribute + ' = ' + "Yes"  
   If modify (ls_modifyexp) <= 0 Then
      ll_method_rc = -1
      Continue
   End If      
Next

Return ll_method_rc
end function

public function string calculatedefaultcolor (string as_expression, string as_default);////////////////////////////////////////////////////////////////
// Description:
//    Determine the best possible default value
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_expression - The expression
//    as_default     - A default value
// Returns: 
//    The default value
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "calculateDefaultColor "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_expression, as_default)    " + &
      "as_expression="+as_expression+"  as_default="+as_default)
End If   

// Declare local variables
string            ls_working

// Perform cleanup
as_expression = Trim(as_expression)
as_default = Trim(as_default)

// Internal/Protected method to always return a Color
If IsNull(as_default) Or Len(as_default)=0 Or Not isNumber(as_default) Then
   as_default = string(il_defaultcolor)
End If

// Validate arguments
If IsNull(as_expression) Or Len(as_expression)=0 Then
   Return as_default
End If

// Check for a Color and not an expression
If IsNumber(as_expression) Then
   Return as_expression
End If

// Check for an Expression (contains a Tab delimeter)
If Pos(as_expression, '~t') > 0 Then
   ls_working = Left (as_expression, Pos(as_expression, '~t') -1)

   // Have the desired value if the Left Side of the expression is a Color
   If IsNumber(ls_working) Then
      Return ls_working
   End If

   // Remove any Quotes or DoubleQuotes
   If Pos(ls_working, '"') > 0 Then
      ls_working = Right(ls_working, Len(ls_working) - Pos(ls_working, '"'))
   End If
   If Pos(ls_working, "'") > 0 Then
      ls_working = Right(ls_working, Len(ls_working) - Pos(ls_working, "'"))
   End If
   
   // Have the desired value if it is a Color
   If IsNumber(ls_working) Then
      Return ls_working
   End If   
      
End If

// Return the default color
Return as_default
end function

public function boolean objectexists (string as_object);////////////////////////////////////////////////////////////////
// Description:
//    Checks if the object passed in exists 
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object name to check on
// Returns: 
//    true or false depending if the object exists
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "objectExists "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object)    as_object="+as_object)
End If   

// Declare local variables
string   ls_objects[]
boolean  lb_method_rc

// Move single entry into array
ls_objects[1] = as_object

lb_method_rc = objectExists(ls_objects)
Return lb_method_rc
end function

public function long requestprotectbackgroundcolor (string as_object, long al_color);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive a Protect and color
//    for its background
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    al_color - The actual color for the object
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
////////////////////////////////////////////////////////////////

constant string METHOD_NAME = "requestProtectBackgroundColor "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, al_color)   " + &
      "as_object="+as_object+"   al_color="+string(al_color))
End If

Return requestProtectBackgroundColor(as_object, NO_EXPRESSION, al_color)
end function

public function long requestbackgroundcolor (string as_object, string as_expression, long al_color);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive the passed in "Expression" 
//    for its background
//
//    The as_expression must be one that can be resolved into a color
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression describing the color
//    al_color - The actual color for the object
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestBackgroundColor "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression, al_color)~r~n"+ &
      "   as_object="+as_object+"~r~n" + &
      "   as_expression="+as_expression+"~r~n" + &
      "   al_color="+string(al_color))
End If   

Return requestBackgroundColor(as_object, as_expression, al_color, NO_COLOR)

end function

public function long requestbackgroundcolor (string as_object, long al_color);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive the passed in color 
//    for its background
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    al_color - The actual color for the object
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestBackgroundColor "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, al_color)  "+ &
      "as_object="+as_object+"  al_color="+string(al_color))
End If   

Return requestBackgroundColor( &
                  as_object, NO_EXPRESSION, al_color, NO_COLOR)               
end function

public function long requestbackgroundcolor (string as_object, string as_expression);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive the passed in "Expression" 
//    for its background
//
//    The as_expression must be one that can be resolved into a color
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression describing the color
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestBackgroundColor "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression)~r~n"+ &
      "   as_object="+as_object+"  as_expression="+as_expression)
End If   

Return requestBackgroundColor( &
            as_object, as_expression, NO_COLOR, NO_COLOR)
end function

protected function long requestbackgroundcolor (string as_object, string as_expression, long al_expression_truecolor, long al_expression_falsecolor);////////////////////////////////////////////////////////////////
// Description:
//    Requests that the passed in object receive the al_expression_truecolor when
//    the passed in as_expression is true.  When the as_expression is false the
//    background color is set to al_expression_falsecolor
//
//    If an expression is found it must be one that can be resolved into a color
//    If no expression is found then it is always a True expression
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_object - The object to be modified
//    as_expression - The expression describing the color
//    al_expression_truecolor - The color to be applied when the expression is found
//                               to be true
//    al_expression_falsecolor - The color to be applied when the expression is found
//                               to be false
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "requestBackgroundColor "

If ib_trace Then
   inv_log.traceLog (METHOD_NAME, "(as_object, as_expression, " + &
      "al_expression_truecolor, al_expression_falsecolor)~r~n" + &
      "   as_object                ="+as_object + "~r~n" + &
      "   as_expression            ="+as_expression + "~r~n" + &
      "   al_expression_truecolor  ="+string(al_expression_truecolor) + "~r~n" + &
      "   al_expression_falsecolor ="+string(al_expression_falsecolor) )
End If   

// Declare local variables
constant string ATTRIBUTE = 'Background.Color'
string   ls_ifexpression
string   ls_modifyexp
string   ls_defaultcolor

// Perform cleanup
as_object = Trim (as_object)
as_expression = Trim (as_expression)

// Validate arguments
If IsNull(as_object) Or Len (as_object)=0 Then 
   addError(METHOD_NAME, "Invalid as_object argument")
   Return -1
End If   
If IsNull(as_expression) Then 
   addError(METHOD_NAME, "Invalid as_expression argument")  
   Return -1
End If   
If IsNull(al_expression_truecolor)  Then 
   addError(METHOD_NAME, "Invalid al_expression_truecolor argument")    
   Return -1
End If   
If IsNull(al_expression_falsecolor) Then 
   addError(METHOD_NAME, "Invalid al_expression_falsecolor argument")         
   Return -1
End If   
If al_expression_truecolor >= 0 Or al_expression_truecolor = NO_COLOR Then
   // Either a color or the Internal code for NO_COLOR was passed in
Else
   addError(METHOD_NAME, "Invalid al_expression_truecolor argument")          
   Return -1
End If
If al_expression_falsecolor >= 0 Or al_expression_falsecolor = NO_COLOR Then
   // Either a color or the Internal code for NO_COLOR was passed in
Else
   addError(METHOD_NAME, "Invalid al_expression_falsecolor argument")               
   Return -1
End If
If as_expression = NO_EXPRESSION And al_expression_truecolor = NO_COLOR Then
   addError(METHOD_NAME, "Invalid as_expression/al_expression_truecolor argument combination")
   Return -1
End If

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return -1
End If

// If need be, clear out the expression variable
If as_expression = NO_EXPRESSION Then
   as_expression = ''
End If

// Set up the default value
ls_defaultcolor = ids_requestor.Describe(as_object+"."+ATTRIBUTE)
If IsNull(ls_defaultcolor) Or ls_defaultcolor='!' Or ls_defaultcolor='?' Then 
   addError (METHOD_NAME, "Describe(" + as_object+"."+ATTRIBUTE +") failed")  
   Return -1
End If   
ls_defaultcolor = calculateDefaultColor (ls_defaultcolor, String(WINDOW_BACKGROUND))

// Determine what type of expression is buing built
If al_expression_truecolor < 0 And &
      al_expression_falsecolor < 0 And &
      Len(as_expression) > 0 Then
   // The as_expression is an expression whose result is the color
   ls_modifyexp = as_object + '.' + ATTRIBUTE + ' = ' + "~"" + ls_defaultcolor + &
                  "~t" + as_expression + "~""
Else
   // Determine if this will have an ifExpression
   If Len(as_expression) > 0 Then
      // Determine the default value
      If al_expression_falsecolor >= 0 Then
         ls_defaultcolor = String (al_expression_falsecolor)
      End If
   
      // Construct the ifExpression
      ls_ifexpression = "If ( " + as_expression + ", " + &
                        String(al_expression_truecolor) + ", " + &
                        ls_defaultcolor + " )"
   Else
      ls_defaultcolor = String(al_expression_truecolor)                    
   End If
   
   // Build the Modify Expression
   ls_modifyexp = as_object + '.' + ATTRIBUTE + ' = ' + "~"" + ls_defaultcolor
   If Len(ls_ifexpression) > 0 Then
      ls_modifyexp += "~t" + ls_ifexpression
   End If
   ls_modifyexp += "~""
End If

// Execute the Expression
Return modify (ls_modifyexp)
end function

public function string evaluate (string as_expression, long al_row);////////////////////////////////////////////////////////////////
// Description:
//    Evaluate expression on a DataWindow object
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_expressionion - The expression list
//    al_row - current row
// Returns: 
//   <> "" - Success
//    = "" - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "evaluate "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "as_expressionion = " + as_expression)
End If

String ls_ret
Integer li_Pos
n_cst_stringservice lnvo_string

as_expression = Trim(as_expression) 

// Validate arguments
If IsNull(as_expression) Or Len(as_expression) = 0 Then 
   Return ""
End If   

// Validate required references
If isNull(ids_requestor) Or Not isValid(ids_requestor) Then
   addError (METHOD_NAME, "Requestor object is not valid")
   Return ""
End If

lnvo_string = create n_cst_stringservice
as_expression = lnvo_string.GlobalReplace(as_expression,'"',"'", false)
destroy lnvo_string

IF Left(as_expression,1) = "'" AND Right(as_expression,1) = "'"  Then
   as_expression = Mid(as_expression,2,Len(as_expression) -2) 
END IF 

li_Pos = Pos(as_expression,"~t")
IF li_Pos>0 Then
   as_expression = Mid(as_expression,li_POs+1) 
END IF 

ls_ret = ids_requestor.Describe('Evaluate("' + as_expression + '", ' +string(al_row)+ ")")

IF ls_ret = "?" OR ls_ret = "!" THEN
   If ib_debug Or ib_warning Then
      inv_log.warningLog (METHOD_NAME,"Evaluate Expression Failed (" + as_expression + ")")
   End If
   ls_ret = ""
END IF

if ls_ret <> "" then
   inv_log.debugLog (METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Evaluate Expression Succeeded: " + as_expression)
end if

Return ls_ret
end function

public function long setdropdownlistbox (string as_column, string as_selectsql, boolean ab_showcode, ref string as_modifyexpression);////////////////////////////////////////////////////////////////
// Description:
//    Set the dynamic dropdownlistbox for the passed in column
// Revisions
//    1.0   - Initial version
// Arguments:  
//    as_column      - The column name to be set
//    as_selectsql   - The select sql, include two columns; one is code another is code name
//    ab_showcode    - show code + code name as display value
// Returns: 
//     1  - Success
//    -1  - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft Inc.  All rights reserved.
// Any distribution of the Youngsoft Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "SetDropdownlistbox "

If ib_trace And ib_detailed Then
   inv_log.traceLog (METHOD_NAME, "")
End If

String ls_value, ls_code, ls_codename, ls_error, ls_runtimeerror
Long ll_row
n_cst_helperservice lnvo_helper
n_datastore ldsobj

try
   
   ls_value = as_column + ".values='"
   
   lnvo_helper = create n_cst_helperservice
   
   ldsobj = create n_datastore
   
   if lnvo_helper.datastorefromsql(as_selectsql, ldsobj ) = -1 then
      inv_messaging.append(lnvo_helper.inv_messaging )
      return -1
   end if
   
   for ll_row = 1 to ldsobj.RowCount()
      ls_code = String(ldsobj.GetItemAny(ll_row, 1))
      ls_codename = String(ldsobj.GetItemAny(ll_row, 2))
      if ll_row > 1 then ls_value += "/"
      if IsNull(ls_codename) or Trim(ls_codename) = "" then ls_codename = ls_code
      if ab_showcode then
         ls_value += Trim(ls_code) + "-" + Trim(ls_codename) + "~t" + Trim(ls_code)
      else
         ls_value += Trim(ls_codename) + "~t" + Trim(ls_code)
      end if
   next
   ls_value += "'"
   
   lnvo_helper.SetDropDownListBox(ids_requestor, as_column, ls_value, true, as_modifyexpression)
   
catch ( RuntimeError re )
   
   ls_runtimeerror = "Runtime Error:" + inv_constants.CRLF + inv_constants.CRLF
   ls_runtimeerror += "Error Code: " + string(re.number) + inv_constants.CRLF
   ls_runtimeerror += "Object: " + re.objectName + inv_constants.CRLF
   ls_runtimeerror += "Class: " + re.class + inv_constants.CRLF
   ls_runtimeerror += "Function/Event: " + re.routineName + inv_constants.CRLF
   ls_runtimeerror += "Line: " + string(re.line) + inv_constants.CRLF
   ls_runtimeerror += "Message: " + re.getMessage() + inv_constants.CRLF
   
   addError( METHOD_NAME, "Runtime Error: " + ls_runtimeerror)

   return -1
   
finally
   
   if IsValid(ldsobj) then
      destroy ldsobj
   end if
   
   if IsValid(lnvo_helper) then
      destroy lnvo_helper
   end if
   
end try

return 1
end function

public function long setdropdownlistbox (string as_column, string as_selectsql, boolean ab_showcode);String ls_ret

return setdropdownlistbox(as_column, as_selectsql, ab_showcode, ls_ret)
end function

on eaf_n_cst_dataobjectrulesservice.create
call super::create
end on

on eaf_n_cst_dataobjectrulesservice.destroy
call super::destroy
end on