Ejemplo n.º 1
0
        private bool IsValidNIF(ref TipoNIF tipo, ref string nif, ref string dc)
        {
            if (string.IsNullOrEmpty(nif))
            {
                this.InvalidMessage = "No se ha introducido ningún N.I.F.";
                dc = "";
                return(false);
            }

            //Debe tener una longitud igual a 9 caracteres;
            if (nif.Length != 9)
            {
                //TODO: AÑADIR CEROS DELANTE
                this.InvalidMessage = "Un N.I.F. debe tener 9 caracteres en total incluyendo números y letras. ¿Quiere añadir céros hasta completar los 9 caracteres?";
                dc = "";
                return(false);
            }

            switch (tipo)
            {
            case TipoNIF.DNI:
                return(IsValid_DNI(ref nif, ref dc));

            case TipoNIF.NIE:
                return(IsValid_NIE(ref nif, ref dc));

            case TipoNIF.CIF:
                return(IsValid_CIF(ref nif, ref dc));

            default:
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Force the class to set an invalid NIF by explicit user request.
 /// </summary>
 /// <param name="NIF"></param>
 public void ForceInvalidNIF(ref string NIF)
 {
     this._NIF           = NIF;
     this._IsValid       = false;
     this._tipoNIF       = TipoNIF.NULL;
     this._DC            = null;
     this.InvalidMessage = "N.I.F. invalido forzado por el usuario.";
 }
Ejemplo n.º 3
0
        private void SetTipoNif(ref TipoNIF tipo, ref string nif)
        {
            char firstChar = nif.Substring(0, 1).ToUpper().ToCharArray()[0];

            if (char.IsDigit(firstChar))
            {
                tipo = TipoNIF.DNI;
            }
            //Si la primera letra es x, y ó z, es NIE
            else if (firstChar > 0x57 && firstChar < 0x5B)
            {
                tipo = TipoNIF.NIE;
            }
            else
            {
                tipo = TipoNIF.CIF;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Instead of setting the NIF number by the property, try to set it and return a string with an invalid message
        /// if the number is invalid, and null if the number is valid.
        /// </summary>
        /// <param name="nif"></param>
        /// <returns>Invalid message if number is invalid, null if number is valid.</returns>
        public string TryModifyNIF(ref string nif)
        {
            TipoNIF tipo   = new TipoNIF();
            string  dc     = "";
            string  newNif = nif.Trim().ToUpper();

            SetTipoNif(ref tipo, ref newNif);

            if (IsValidNIF(ref tipo, ref newNif, ref dc))
            {
                this._NIF     = nif;
                this._DC      = dc;
                this._IsValid = true;
                return(null);
            }
            else
            {
                return(this.InvalidMessage);
            }
        }