Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Colaboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #11  
Antiguo 11-07-2024
jlmoli_67 jlmoli_67 is offline
Miembro
 
Registrado: feb 2024
Posts: 125
Poder: 3
jlmoli_67 Va por buen camino
Cita:
Empezado por bmfranky Ver Mensaje
Hola,buenos dias, ¿podrias comentar como haces la comprobacion de nombres y NIF, en el servicio?
Hola, en .net uso la funcion compruebacif() que comprueba la validez de un cof-nif haciendo una llamada a las otras funciones que he pegado. Si esta todo ok entonces hago una peticion soap firmada con los datos que tengo del cliente y me responde si dicho cliente esta censado.

Código:
 Function compruebacif() As Integer
        compruebacif = 0

        Dim esCIF As Boolean = Verificar_CIF(TextBox3.Text)
        If Len(TextBox3.Text) = 0 Then
            MsgBox("El valor introducido no es correcto.Corrija el problema y vuelva a intentarlo", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Atencion")

            Exit Function
        End If

       


        Dim esNIF As Boolean = Verificar_NIF(TextBox3.Text)
        If esCIF = True Or esNIF = True Then
            ' LabelInfo.Text &= vbCrLf & "Es un CIF: " & TextBox10.Text
            compruebacif = 1

        End If
       

       
    End Function


Public Function Verificar_NIF(ByVal valor As String) As Boolean
        Dim aux As String

        valor = valor.ToUpper ' ponemos la letra en mayúscula
        aux = valor.Substring(0, valor.Length - 1) ' quitamos la letra del NIF

        If aux.Length >= 7 AndAlso IsNumeric(aux) Then
            aux = CalculaNIF(aux) ' calculamos la letra del NIF para comparar con la que tenemos
        Else
            Return False
        End If

        If valor <> aux Then ' comparamos las letras
            Return False
        End If

        Return True
    End Function
    Private Function CalculaNIF(ByVal strA As String) As String

        Const cCADENA As String = "TRWAGMYFPDXBNJZSQVHLCKE"
        Const cNUMEROS As String = "0123456789"
        Dim a, b, c, NIF As Integer
        Dim sb As New StringBuilder

        strA = Trim(strA)
        If Len(strA) = 0 Then Return ""

        ' Dejar sólo los números
        For i As Integer = 0 To strA.Length - 1
            If cNUMEROS.IndexOf(strA(i)) > -1 Then
                sb.Append(strA(i))
            End If
        Next

        strA = sb.ToString
        a = 0
        NIF = CInt(Val(strA))
        Do
            b = CInt(Int(NIF / 24))
            c = NIF - (24 * b)
            a = a + c
            NIF = b
        Loop While b <> 0
        b = CInt(Int(a / 23))
        c = a - (23 * b)

        Return strA & Mid(cCADENA, CInt(c + 1), 1)
    End Function



Public Function Verificar_CIF(ByVal valor As String) As Boolean
        Dim strLetra As String, strNumero As String, strDigit As String
        Dim strDigitAux As String
        Dim auxNum As Integer
        Dim i As Integer
        Dim suma As Integer
        Dim letras As String

        letras = "ABCDEFGHJNPQRSUVW"
        'KLM
        valor = UCase(valor)

        If Len(valor) < 9 OrElse Not IsNumeric(Mid(valor, 2, 7)) Then
            Return False
        End If

        strLetra = Mid(valor, 1, 1)     ' letra del CIF
        strNumero = Mid(valor, 2, 7)    ' Código de Control
        strDigit = Mid(valor, 9)        ' CIF menos primera y última posición

        If InStr(letras, strLetra) = 0 Then ' comprobamos la letra del CIF (1ª posición)
            Return False
        End If

        For i = 1 To 7
            If i Mod 2 = 0 Then
                suma = suma + CInt(Mid(strNumero, i, 1))
            Else
                auxNum = CInt(Mid(strNumero, i, 1)) * 2
                suma = suma + (auxNum \ 10) + (auxNum Mod 10)
            End If
        Next
        suma = (10 - (suma Mod 10)) Mod 10

        Select Case strLetra
            Case "K", "P", "Q", "S"
                suma = suma + 64
                strDigitAux = Chr(suma)
            Case "X"
                strDigitAux = Mid(CalculaNIF(strNumero), 8, 1)
            Case Else
                strDigitAux = CStr(suma)
        End Select

        If strDigit = strDigitAux Then
            Return True
        Else
            Return False
        End If
    End Function
ejemplo peticion:
MINIF=reemplazar por cif-nif
MINOMBRE=reemplazar por el nombre o razon social


<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vnif="http://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/burt/jdit/ws/VNifV2Ent.xsd" xmlns:LocalPart="http://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/burt/jdit/ws/VNifV2Ent.xsd">
<soapenv:Header/>
<soapenv:Body>
<vnif:VNifV2Ent>
<vnif:Contribuyente>
<vnif:Nif>MINIF</vnif:Nif>
<vnif:Nombre>MINOMBRE</vnif:Nombre>
</vnif:Contribuyente>
</vnif:VNifV2Ent>
</soapenv:Body>
</soapenv:Envelope>

un saludo

Última edición por Neftali [Germán.Estévez] fecha: 11-07-2024 a las 11:42:19. Razón: Añadir TAGs al código
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Hijo de Informáticos gluglu Humor 3 13-03-2007 11:05:35
Adictos informaticos ... Trigger Humor 2 11-10-2004 12:18:32
Nosotros los Informáticos Trigger Humor 1 10-10-2004 14:58:09
Patrón de los Informáticos. obiwuan Varios 20 10-09-2003 14:44:54
Chistes Informaticos jhonny Humor 2 11-08-2003 21:59:09


La franja horaria es GMT +2. Ahora son las 20:33:24.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi