Custom Error Checking

<< Click to Display Table of Contents >>

Navigation:  EDP > Customizability >

Custom Error Checking

A custom error check is a check that involves values from one or several related fields within the same section. For example, suppose you have a section named EFW2LabRES with fields RESULT_VALUE, DETECT_FLAG, and RESULT_TYPE_CODE. When field RESULT_VALUE has a value of ‘Y’ and field RESULT_TYPE_CODE has a value of ‘TRG’ or ‘TIC,' you want field RESULT_VALUE to be required. Below are several excerpts of code from a format custom handler that illustrate how to implement a custom error check.

 

'Create a variable that will be linked to the EFW2LabRES section

 

Private EFW2LabRES As EarthSoft.EDP.EddTable

 

 

 

Public Overrides Sub AddDataHandlers(ByRef Efd As EarthSoft.EDP.EddFormatDefinition)

 

'Link the variable to the section

 

Me.EFW2LabRES = Efd.Tables.Item("EFW2LabRES")

 

'Add a method to be executed when a value in the section is changed

 

AddHandler Me.EFW2LabRES.ColumnChanged, AddressOf Me.Check_EFW2LabRES

 

 

End Sub

 

 

           'Method executed when a value within section EFW2LabRES is changed

 

Private Sub Check_EFW2LabRES(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs)

 

'Need to determine what field the value was changed for.  If it is one of the three we are checking then we execute method ERR22

 

                       Select Case e.Column.ColumnName.ToLower

 

   Case "result_value"

 

                                   ERR22(e)          'ERR22: Result_value is required where detect_flag='Y' and result_type_code=TRG, TIC. (6)

 

                               Case "detect_flag"                          

 

                 ERR22(e)          'ERR22: Result_value is required where detect_flag='Y' and result_type_code=TRG, TIC. (6)                          

 

   Case "result_type_code"

 

ERR22(e)          'ERR22: Result_value is required where detect_flag='Y' and result_type_code=TRG, TIC. (6)

 

.

 

                                   .           (code omitted)

 

                                   .

 

End Select

 

     End Sub

 

 

'ERR22: Result_value is required where detect_flag=Y and result_type_code=TRG, TIC. (6)

 

      Friend Sub ERR22(ByVal e As System.Data.DataColumnChangeEventArgs)

 

 

 

'We check if field “detect_flag” is not empty and if it is not empty then we convert the value in “detect_flag” to upper case to determine if it equals ‘Y’.  If field “detect_flag” has a value of ‘Y’ then we convert the value in “result_type_code” to uppercase to determine if it equals ‘TIC’ or ‘TRG’.  If field “result_type_code” contains one of theose values then we check if field “result_value” contains a value.  If “result_value” does not contains a value then we add our custom error to field “detect_flag”.

 

           With e.Row

 

              If Not .Item("detect_flag") Is DBNull.Value AndAlso Utilities.String.ToUpper(.Item("detect_flag")) = "Y" AndAlso _

 

                 (Utilities.String.ToUpper(.Item("result_type_code")) = "TRG" OrElse Utilities.String.ToUpper(.Item("result_type_code")) = "TIC") AndAlso _

 

                 .Item("result_value") Is DBNull.Value Then

 

                    'Add custom error to field “detect_flag”

 

  Me.AddError(e.Row, e.Row.Table.Columns.Item("detect_flag"), EddErrors.CustomError6)

 

              Else

 

                    'If one of the above conditions is not true then we remove the custom error from field “detect_flag”

 

                    Me.RemoveError(e.Row, e.Row.Table.Columns.Item("detect_flag"), EddErrors.CustomError6)

 

              End If

 

           End With

 

 

 

     End Sub

 

 

Public Overloads Overrides Function ErrorMessage(ByVal err As EddErrors) As String

 

           ' Specify the message we want to display to the user when the custom error is added.  Message is displayed as a tooltip.

 

           Select Case err

 

               Case EddErrors.CustomError6

 

                 Return "Result_value is required where detect_flag=Y and result_type_code=TRG, TIC. (6)"

 

.

 

                                   .           (code omitted)

 

                                   .

 

End Select

 

 

 

           Return String.Empty

 

     End Function

 

 

 

Public Overrides Sub Grid_AfterCellUpdate(ByVal sender As Object, ByVal e As Object, ByVal edp As Object)

 

 

 

           ' make an explicit call to AfterCellUpdate to show/clear the error on the other cell

 

           Select Case e.Cell.Column.Key.ToLower

 

   Case "result_value"

 

                 edp.AfterCellUpdate(sender, e.Cell.Row.Cells.Item("detect_flag"))                  

 

               Case "result_type_code"

 

                 edp.AfterCellUpdate(sender, e.Cell.Row.Cells.Item("detect_flag"))

 

 

 

           End Select

 

     End Sub