' Public portfolio sample - adapted from an individual academic VB.NET project.
' The original project used a Windows Forms interface, a DataGridView, and CSV export.

Private Function ValidateRecord(fullName As String, recordId As String,
                                phone As String, address As String,
                                category As String) As Boolean
    ErrorProviderValidar.Clear()

    If String.IsNullOrWhiteSpace(fullName) Then
        ErrorProviderValidar.SetError(TxtNombre, "Enter a name.")
        Return False
    ElseIf String.IsNullOrWhiteSpace(recordId) Then
        ErrorProviderValidar.SetError(TxtIdentificacion, "Enter a record ID.")
        Return False
    ElseIf String.IsNullOrWhiteSpace(phone) Then
        ErrorProviderValidar.SetError(TxtTelefono, "Enter a phone number.")
        Return False
    ElseIf String.IsNullOrWhiteSpace(address) Then
        ErrorProviderValidar.SetError(TxtDireccion, "Enter an address.")
        Return False
    ElseIf String.IsNullOrWhiteSpace(category) Then
        ErrorProviderValidar.SetError(CbxGenero, "Select a category.")
        Return False
    End If

    Return True
End Function

Private Function IsUniqueRecordId(recordId As String) As Boolean
    For Each row As DataGridViewRow In DgvDatos.Rows
        If row.Cells("ColumnIdentificacion").Value IsNot Nothing AndAlso
           row.Cells("ColumnIdentificacion").Value.ToString() = recordId Then
            ErrorProviderValidar.SetError(TxtIdentificacion, "Use a different record ID.")
            Return False
        End If
    Next
    Return True
End Function

Private Sub ExportToCsv(fileName As String)
    Using writer As New IO.StreamWriter(fileName)
        writer.WriteLine("Name,Record ID,Phone,Address,Category")
        For Each row As DataGridViewRow In DgvDatos.Rows
            If Not row.IsNewRow Then
                writer.WriteLine($"{row.Cells("ColumnNombre").Value}," &
                                 $"{row.Cells("ColumnIdentificacion").Value}," &
                                 $"{row.Cells("ColumnTelefono").Value}," &
                                 $"{row.Cells("ColumnDireccion").Value}," &
                                 $"{row.Cells("ColumnGenero").Value}")
            End If
        Next
    End Using
End Sub
