public List <ValidationResult> Valida(Portador ptr) { try { List <ValidationResult> lstVr = lstVr = new List <ValidationResult>(); //Validação PAN e Proxy this.ValidaPanProxy(ptr, lstVr); //Validação CPF var vldCpf = new upSight.Negocio.Calculo.ValidacaoCpf(ptr.CPF); if (!vldCpf.EhValido()) { lstVr.Add(new ValidationResult(String.Concat("CPF inválido: ", ptr.CPF), new[] { "CPF" })); } //Valida CNPJ if (!String.IsNullOrEmpty(ptr.CnpjFilial)) { var vldCnpj = new upSight.Negocio.Calculo.ValidacaoCnpj(ptr.CnpjFilial); if (!vldCnpj.EhValido()) { lstVr.Add(new ValidationResult(String.Concat("CnPj inválido: ", ptr.CnpjFilial), new[] { "CNPJ" })); } } //Validação Data de Nascimento if (ptr.DtNascimento.HasValue) { if (ptr.DtNascimento.Value.Year < DateTime.Now.AddYears(-12).Year /*Validação para maiores de 12 anos*/ || ptr.DtNascimento > DateTime.Now) { lstVr.Add(new ValidationResult(String.Concat("Data de nascimento inválida: ", ptr.DtNascimento), new[] { "DtNascimento" })); } } //Validação email if (!String.IsNullOrEmpty(ptr.Email)) { this._Rgx = new Regex(this._ExpRglrEmail); if (!this._Rgx.Match(ptr.Email).Success) { lstVr.Add(new ValidationResult(String.Concat("Email inválido: ", ptr.Email), new[] { "Email" })); } } //Validação sexo if (!String.IsNullOrEmpty(ptr.Sexo)) { if (!ptr.Sexo.ToUpper().Substring(0, 1).Equals("M") && !ptr.Sexo.ToUpper().Substring(0, 1).Equals("F")) { lstVr.Add(new ValidationResult(String.Concat("Sexo inválido: ", ptr.Sexo), new[] { "Sexo" })); } } //Validação grupo if (!String.IsNullOrEmpty(ptr.Grupo)) { this._Rgx = new Regex(this._ExprRglrGrupo); if (!this._Rgx.Match(ptr.Grupo).Success) { if (ptr.Grupo.Length > 20) { lstVr.Add(new ValidationResult(String.Concat("Grupo contém quantidade de caracteres maior que 20: ", ptr.Grupo), new[] { "Grupo" })); } } else { lstVr.Add(new ValidationResult(String.Concat("Grupo contém caracteres inválidos: ", ptr.Grupo), new[] { "Grupo" })); } } //Valida nome e nome da mãe this.ValidaNomes(ptr.Nome, ptr.NomeMae, lstVr); //Valida telefone celular this.ValidaTelefone(ptr.DDDCel, ptr.Celular, lstVr); return(lstVr); } catch (Exception e) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) { Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrCN", e }); } throw; } }
public List<ValidationResult> Valida(Portador ptr) { try { List<ValidationResult> lstVr = lstVr = new List<ValidationResult>(); //Validação PAN e Proxy this.ValidaPanProxy(ptr, lstVr); //Validação CPF var vldCpf = new upSight.Negocio.Calculo.ValidacaoCpf(ptr.CPF); if (!vldCpf.EhValido()) lstVr.Add(new ValidationResult(String.Concat("CPF inválido: ", ptr.CPF), new[] { "CPF" })); //Valida CNPJ if (!String.IsNullOrEmpty(ptr.CnpjFilial)) { var vldCnpj = new upSight.Negocio.Calculo.ValidacaoCnpj(ptr.CnpjFilial); if (!vldCnpj.EhValido()) lstVr.Add(new ValidationResult(String.Concat("CnPj inválido: ", ptr.CnpjFilial), new[] { "CNPJ" })); } //Validação Data de Nascimento if (ptr.DtNascimento.HasValue) if (ptr.DtNascimento.Value.Year < DateTime.Now.AddYears(-12).Year /*Validação para maiores de 12 anos*/ || ptr.DtNascimento > DateTime.Now) lstVr.Add(new ValidationResult(String.Concat("Data de nascimento inválida: ", ptr.DtNascimento), new[] { "DtNascimento" })); //Validação email if (!String.IsNullOrEmpty(ptr.Email)) { this._Rgx = new Regex(this._ExpRglrEmail); if (!this._Rgx.Match(ptr.Email).Success) lstVr.Add(new ValidationResult(String.Concat("Email inválido: ", ptr.Email), new[] { "Email" })); } //Validação sexo if (!String.IsNullOrEmpty(ptr.Sexo)) { if (!ptr.Sexo.ToUpper().Substring(0, 1).Equals("M") && !ptr.Sexo.ToUpper().Substring(0, 1).Equals("F")) lstVr.Add(new ValidationResult(String.Concat("Sexo inválido: ", ptr.Sexo), new[] { "Sexo" })); } //Validação grupo if (!String.IsNullOrEmpty(ptr.Grupo)) { this._Rgx = new Regex(this._ExprRglrGrupo); if (!this._Rgx.Match(ptr.Grupo).Success) { if (ptr.Grupo.Length > 20) lstVr.Add(new ValidationResult(String.Concat("Grupo contém quantidade de caracteres maior que 20: ", ptr.Grupo), new[] { "Grupo" })); } else lstVr.Add(new ValidationResult(String.Concat("Grupo contém caracteres inválidos: ", ptr.Grupo), new[] { "Grupo" })); } //Valida nome e nome da mãe this.ValidaNomes(ptr.Nome, ptr.NomeMae, lstVr); //Valida telefone celular this.ValidaTelefone(ptr.DDDCel, ptr.Celular, lstVr); return lstVr; } catch (Exception e) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrCN", e }); throw; } }