-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUtils.vb
105 lines (97 loc) · 3.84 KB
/
Utils.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Public Class Utils
''' <summary>
''' Verifica que el campo no esté vacio
''' </summary>
''' <param name="campo">Control TextBox a verificar</param>
''' <param name="Err">Control para el seteo de errores</param>
''' <returns>True si el campo está vacio de lo contrario False </returns>
Public Shared Function EsCampoVacio(ByRef campo As TextBox, ByRef Err As ErrorProvider) As Boolean
If campo.Text.Trim.Length = 0 Then
Err.SetIconPadding(campo, 5)
Err.SetError(campo, "El nombre de archivo es obligatorio")
Return False
Else
Err.SetError(campo, "")
Return True
End If
End Function
Public Shared Function EsCuitValido(ByRef campo As TextBox, ByRef Err As ErrorProvider) As Boolean
If Not ValidarCUIT(campo.Text) Then
Err.SetIconPadding(campo, 5)
Err.SetError(campo, "La CUIT no es válida")
Return False
Else
Err.SetError(campo, "")
Return True
End If
End Function
Public Shared Function DirectorioExiste(ByRef campo As TextBox, ByRef ctrl As Button, ByRef Err As ErrorProvider) As Boolean
If Not My.Computer.FileSystem.DirectoryExists(campo.Text) Then
Err.SetIconPadding(ctrl, 5)
Err.SetError(ctrl, "La carpeta de salida no existe")
Return False
Else
Err.SetError(ctrl, "")
Return True
End If
End Function
Public Shared Function ArchivoExiste(ByRef campo As TextBox, ByRef ctrl As Button, ByRef Err As ErrorProvider) As Boolean
If Not My.Computer.FileSystem.FileExists(campo.Text) Then
Err.SetIconPadding(ctrl, 5)
Err.SetError(ctrl, "El archivo no existe")
Return False
Else
Err.SetError(ctrl, "")
Return True
End If
End Function
Public Shared Function ContraseniasCoinciden(ByRef pass As TextBox, ByRef passConfirmacion As TextBox, ByRef Err As ErrorProvider) As Boolean
If pass.Text.Trim.Length = 0 Then
Err.SetIconPadding(pass, 5)
Err.SetError(pass, "El nombre de archivo es obligatorio")
Return False
ElseIf pass.Text <> passConfirmacion.Text Then
Err.SetIconPadding(pass, 5)
Err.SetError(pass, "El nombre de archivo es obligatorio")
Return False
Else
Err.SetError(pass, "")
Return True
End If
End Function
''' <summary>
''' Valida el formato y digito verificador de un número de CUIT.
''' </summary>
''' <param name="cuit">El número de CUIT a validar</param>
''' <returns>True si el número es válido, False si no lo es.</returns>
Public Shared Function ValidarCUIT(ByVal cuit As String) As Boolean
' En caso que la CUIT venga en formato con guiones
cuit = cuit.Replace("-", "")
If IsNumeric(cuit) Then
Try
If (cuit.Length <> 11) Then Return False
Dim tmpCuit As String = cuit.Substring(0, 10)
Dim total As Integer = 0
Dim tabla() As Integer = {5, 4, 3, 2, 7, 6, 5, 4, 3, 2}
For i = 0 To tmpCuit.Length - 1
Dim currChar As Integer = CInt(tmpCuit.Substring(i, 1))
total += currChar * tabla(i)
Next
Dim preDV As Integer = 11 - (total Mod 11)
If preDV >= 10 Then
preDV = 0
End If
tmpCuit &= preDV
If cuit = tmpCuit Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
Else
Return False
End If
End Function
End Class