TFS_ANTIGUO/PrendarioDavivienda/ULA.Davivienda.WCFServiciosGenerales/ULA.Davivienda.WCFServiciosGenerales.BL/Utilitario/UtilitarioGenBL.vb

205 lines
8.6 KiB
VB.net

Partial Class UtilitarioGenBL
Public Shared Function Valida_Fecha(ByVal valor As String,
ByVal formato As Integer,
ByVal variable As String,
ByVal tipo_ref As String,
ByVal acepta_blanco As Integer) As String
Dim mtzFecha() As String
Dim strDescError As String = String.Empty
Try
If valor.Trim().Length = 0 And acepta_blanco = 0 Then
strDescError = "Error: Este campo no debe llevar valores en blanco. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
Else
If valor.Trim().Length = 0 And acepta_blanco = 1 Then
Return valor
Else
If formato = 1 Then 'dd/mm/yyyy
mtzFecha = valor.Split("/")
If mtzFecha.Length <> 3 Then
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
Else
If Not IsDate(mtzFecha(2) & "-" & mtzFecha(1) & "-" & mtzFecha(0)) Then
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
Else
If mtzFecha(0).Trim().Length = 2 And mtzFecha(1).Trim().Length = 2 And mtzFecha(2).Trim().Length = 4 Then
Return valor
Else
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
End If
End If
End If
End If
If formato = 2 Then 'mm/dd/yyyy
mtzFecha = valor.Split("/")
If mtzFecha.Length <> 3 Then
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
Else
If Not IsDate(mtzFecha(2) & "-" & mtzFecha(0) & "-" & mtzFecha(1)) Then
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
Else
If mtzFecha(0).Trim().Length = 2 And mtzFecha(1).Trim().Length = 2 And mtzFecha(2).Trim().Length = 4 Then
Return valor
Else
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
End If
End If
End If
End If
End If
End If
Catch ex As Exception
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. " & ex.Message & ". COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
Finally
If strDescError <> "" Then
Err.Raise("9999", "Cargar CIC", strDescError)
End If
End Try
Return valor
End Function
Public Shared Function Valida_Numero(ByVal valor As String,
ByVal variable As String,
ByVal tipo_ref As String) As String
Dim strDescError As String
Dim nfi As New System.Globalization.NumberFormatInfo
nfi.CurrencyDecimalSeparator = "."
nfi.NumberGroupSeparator = ","
If valor.Trim().Length = 0 Then
valor = "0"
End If
If Not IsNumeric(valor) Then
strDescError = "Error: El valor " & valor & " tiene un formato incorrecto. COLUMNA: " & variable & " - REFERENCIA: " & tipo_ref
Err.Raise("9999", "Cargar CIC", strDescError)
End If
Return valor
End Function
Public Shared Function EncuentraTipoOperacion(ByVal Codigo As Integer) As String
Dim Descripciones(7), Codigos(7) As String
Dim i As Integer
Dim Respuesta As String = String.Empty
Try
Descripciones(1) = "1 - 98 DIRECTA" : Codigos(1) = "1"
Descripciones(2) = "2 - CRÉDITO CON OBLIGACIÓN DE DESEMBOLSO" : Codigos(2) = "2"
Descripciones(3) = "3 - TARJETAS DE CRÉDITO" : Codigos(3) = "3"
Descripciones(4) = "4 - LÍNEAS DE UTILIZACIÓN AUTOMÁTICA" : Codigos(4) = "4"
Descripciones(5) = "5 - LÍNEA DE CRÉDITO CON COMPROMISO" : Codigos(5) = "5"
Descripciones(6) = "6 - LÍNEA DE CRÉDITO SIN COMPROMISO" : Codigos(6) = "6"
Descripciones(7) = "7 - 99 CONTINGENCIA CREDITICIA" : Codigos(7) = "7"
For i = 1 To Descripciones.Length - 1
If Codigo = Codigos(i) Then
Respuesta = Descripciones(i)
End If
Next
Catch ex As Exception
Throw ex
End Try
Return Respuesta
End Function
Public Shared Function EncuentraEstadoOperacion(ByVal Codigo As Integer) As String
Dim i As Integer = 0
Dim Respuesta As String = String.Empty
Dim Descripciones(11), Codigos(11) As String
Try
Descripciones(1) = "VIGENTE" : Codigos(1) = "1"
Descripciones(2) = "VENCIDA <= A 90 DÍAS" : Codigos(2) = "2"
Descripciones(3) = "VENCIDA A > 90 DÍAS Y <= 180 DÍAS" : Codigos(3) = "3"
Descripciones(4) = "VENCIDA < A 180 DÍAS" : Codigos(4) = "4"
Descripciones(5) = "COBRO JUDICIAL" : Codigos(5) = "5"
Descripciones(6) = "NORMAL" : Codigos(6) = "91"
Descripciones(7) = "ARREGLO DE PAGO" : Codigos(7) = "92"
Descripciones(8) = "ADMINISTRACIÓN INTERVENCIÓN JUDICIAL" : Codigos(8) = "95"
Descripciones(9) = "ADMINISTRACIÓN INTERVENCIÓN SUGEF" : Codigos(9) = "96"
Descripciones(10) = "OPERACIONES CASTIGADAS" : Codigos(10) = "97"
Descripciones(11) = "OPERACIONES BACK TO BACK" : Codigos(11) = "99"
For i = 1 To Descripciones.Length - 1
If Codigo = Codigos(i) Then
Respuesta = Descripciones(i)
End If
Next
Catch ex As Exception
Throw ex
End Try
Return Respuesta
End Function
Public Shared Function Formato_Fecha(ByVal valor As String) As String
Dim mtzFecha() As String
Dim fecha_fin As String
Dim objFecha As Date
Try
mtzFecha = valor.Split("/")
If mtzFecha.Length = 3 Then
If mtzFecha(0).Trim() = "01" Then
objFecha = CDate(mtzFecha(2) & "-" & mtzFecha(1) & "-" & mtzFecha(0))
objFecha = objFecha.AddMonths(1)
objFecha = objFecha.AddDays(-1)
fecha_fin = Rellena_Posiciones("1", 2, "0", objFecha.Day.ToString()) & "/" & Rellena_Posiciones("1", 2, "0", objFecha.Month.ToString()) & "/" & objFecha.Year.ToString()
Else
fecha_fin = valor
End If
Else
fecha_fin = valor
End If
Catch ex As Exception
fecha_fin = valor
End Try
Return fecha_fin
End Function
Public Shared Function Quita_Formato_Numero(ByVal formato As String, ByVal valor As String) As String
Select Case formato
Case "1" 'Valor viene en formato 0.000,00
valor = valor.Replace("¢", "").Replace(".", "").Replace(",", ".")
Case "2" 'Valor viene en formato 0,000.00
valor = valor.Replace(",", "")
End Select
If valor.IndexOf("(") <> -1 And valor.IndexOf(")") <> -1 Then
valor = "-" & valor.Replace("(", "").Replace(")", "")
End If
Return valor
End Function
Public Shared Function Rellena_Posiciones(ByVal pos As String, ByVal cant As Integer, ByVal val_rellena As String, ByVal valor As String) As String
Dim i As Integer
Dim longitud As Integer = valor.Trim.Length
For i = 1 To cant - longitud
If pos = "1" Then 'Rellena Izquierda
valor = val_rellena & valor
End If
If pos = "2" Then 'Rellena Derecha
valor = valor & val_rellena
End If
Next
Return valor
End Function
End Class