public bool ValidarRUC(string RUC) { if (string.IsNullOrWhiteSpace(RUC)) { throw new Exception("El RUC esta Vacio"); } else { long s; if (long.TryParse(RUC, out s)) { if (RUC.Length == 13) { if (ValidarProvincia(int.Parse(RUC.Substring(0, 2)))) { if (ValidarTercerDigito(int.Parse(RUC.Substring(2, 1)))) { int index = (this.TipoRUC == TipoRUC.PUBLICO)? 8 : 9; if (ValidarEstablecimiento(int.Parse(RUC.Substring(index + 1)))) { var Generador = new CodigoDeControl(); if (Generador.ValidarDigitoVerificador(RUC.Substring(0, index), int.Parse(RUC.Substring(index, 1)), (this.TipoRUC == TipoRUC.NATURAL? Algoritmo.Modulo10 : Algoritmo.Modulo11))) { Estado = $"RUC {RUC} Válido"; return(true); } else { Estado = $"El Dígito de control en el RUC {RUC} no corresponde {Generador.DigitoVerificador}"; } } } else { Estado = $"RUC {RUC} Inválido"; } } else { Estado = $"El código de Provincia en el RUC {RUC} no es correcto"; } } else { Estado = $"El RUC {RUC} debe contener 13 digitos"; } } else { throw new Exception($"El RUC ({RUC}) no es numérico en su totalidad."); } } return(false); }
public bool ValidarCedula(string Cedula) { if (string.IsNullOrWhiteSpace(Cedula)) { throw new Exception("La Cédula esta Vacia"); } else { if (Cedula.Length == 10) { long s; if (long.TryParse(Cedula, out s)) { if (ValidarProvincia(int.Parse(Cedula.Substring(0, 2)))) { if (ValidarTercerDigito(int.Parse(Cedula.Substring(2, 1)))) { var Generador = new CodigoDeControl(Cedula.Substring(0, 9)); if (Generador.ValidarDigitoVerificador(int.Parse(Cedula.Substring(9)), Algoritmo.Modulo10)) { Estado = $"Cédula {Cedula} Correcta"; return(true); } else { Estado = $"Útimo dígito de la Cédula {Cedula} Incorrecto"; } } else { Estado = $"Cédula {Cedula} Incorrecta"; } } else { Estado = $"El código de Provincia en la Cédula {Cedula} no es correcto"; } } else { throw new Exception($"La Cédula ({Cedula}) no es numérica en su totalidad."); } } else { Estado = $"La Cédula {Cedula} debe contener 10 digitos"; } return(false); } }