Imports BaseDeDatos

Class ReglaCajasTextoVacias
  Inherits ValidationRule
  Public Overrides Function Validate(value As Object, cultureInfo As System.Globalization.CultureInfo) As ValidationResult
    Dim bindingGroup As BindingGroup = DirectCast(value, BindingGroup)
    ' Sólo hay un elemento en la colección Items.
    Dim al As Alumno = TryCast(bindingGroup.Items(0), Alumno)
    ' al contiene los valores originales
    Dim n As Double
    ' Verificar los valores nuevos
    Dim nom As String = bindingGroup.GetValue(al, "NomAlumno").ToString()
    Dim dir As String = bindingGroup.GetValue(al, "DirAlumno").ToString()
    Dim est As String = bindingGroup.GetValue(al, "EstAlumno").ToString()
    If Double.TryParse(nom, n) OrElse Double.TryParse(dir, n) OrElse Double.TryParse(est, n) Then
      Return New ValidationResult(False, "No puede ser un dato numérico")
    End If

    If nom.Length = 0 OrElse dir.Length = 0 OrElse est.Length = 0 Then
      Return New ValidationResult(False, String.Format("La cadena de entrada está vacía"))
    End If

    Return ValidationResult.ValidResult
  End Function
End Class
