/// <summary> /// Valida PAN(1) ou Proxy(2) /// </summary> /// <param name="tpIdentif"></param> /// <param name="Identificacao"></param> /// <returns></returns> private void ValidaPanProxy(Portador ptr, List <ValidationResult> lstVr) { try { this._Rgx = new Regex(this._ExpRglrNaoNumerico); if (!this._Rgx.Match(ptr.Identificacao).Success) { if (this.ValidaExistenciaPanProxy(ptr)) { switch (ptr.TpIdentif) { case "1": if (!ptr.Identificacao.Length.Equals(16)) { lstVr.Add(new ValidationResult(String.Concat("Identificacao com quantidade de caracteres divergentes a 16: ", ptr.Identificacao), new[] { "Identificacao" })); } break; case "2": if (ptr.Identificacao.Length < 8 || ptr.Identificacao.Length > 32) { lstVr.Add(new ValidationResult(String.Concat("Identificacao com quantidade de caracteres divergentes( menor que 8 ou maior que 32): ", ptr.Identificacao), new[] { "Identificacao" })); } break; } } else { lstVr.Add(new ValidationResult(String.Concat("PanProx inexistente ou convenio não compatível. ", ptr.Identificacao), new[] { "Identificacao" })); } } else { lstVr.Add(new ValidationResult(String.Concat("Identificacao com caracteres alfa-numéricos: ", ptr.Identificacao), new[] { "Identificacao" })); } } catch (Exception e) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) { Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrCN", e }); } throw; } }
public static void Insere(this Portador ptr, int idArquivo, int numLinha) { using (SqlConnection cnx = new SqlConnection(ConfigurationManager.ConnectionStrings["Global"].ConnectionString)) { try { string query = "[crtCargaDetalheIdentificacao]"; using (SqlCommand cmd = new SqlCommand(query, cnx)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("IdArquivo", SqlDbType.Int).Value = idArquivo; cmd.Parameters.Add("TpRegistro", SqlDbType.Char, 1).Value = ptr.TpRegistro; cmd.Parameters.Add("TpPanProxy", SqlDbType.Char, 1).Value = ptr.TpIdentif; cmd.Parameters.Add("PanProxy", SqlDbType.VarChar, 32).Value = ptr.Identificacao.TrimEnd(null); cmd.Parameters.Add("CPF", SqlDbType.VarChar, 11).Value = ptr.CPF.TrimEnd(null); cmd.Parameters.Add("Nome", SqlDbType.VarChar, 50).Value = ptr.Nome.TrimEnd(null); cmd.Parameters.Add("NomeFacial", SqlDbType.VarChar, 25).Value = BDGeral.BDObtemValor(ptr.NomeFacial.TrimEnd(null)); cmd.Parameters.Add("DtNascimento", SqlDbType.Date).Value = BDGeral.BDObtemValor <DateTime>(ptr.DtNascimento); cmd.Parameters.Add("Sexo", SqlDbType.Char, 1).Value = BDGeral.BDObtemValor(ptr.Sexo); cmd.Parameters.Add("CnpjFilial", SqlDbType.VarChar, 14).Value = BDGeral.BDObtemValor(ptr.CnpjFilial.TrimEnd(null)); cmd.Parameters.Add("Grupo", SqlDbType.VarChar, 20).Value = BDGeral.BDObtemValor(ptr.Grupo.TrimEnd(null)); cmd.Parameters.Add("Email", SqlDbType.VarChar, 30).Value = BDGeral.BDObtemValor(ptr.Email.TrimEnd(null)); cmd.Parameters.Add("DDDCel", SqlDbType.VarChar, 2).Value = BDGeral.BDObtemValor(ptr.DDDCel.TrimEnd(null)); cmd.Parameters.Add("Celular", SqlDbType.VarChar, 9).Value = BDGeral.BDObtemValor(ptr.Celular.TrimEnd(null)); cmd.Parameters.Add("NomeMae", SqlDbType.VarChar, 50).Value = BDGeral.BDObtemValor(ptr.NomeMae.TrimEnd(null)); cmd.Parameters.Add("IdRegistro", SqlDbType.VarChar, 10).Value = BDGeral.BDObtemValor(ptr.IdRegistro); cmd.Parameters.Add("NumLinha", SqlDbType.Int).Value = numLinha; cnx.Open(); cmd.ExecuteNonQuery(); } } catch (Exception sqlExc) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) { Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrBD", sqlExc }); } throw; } } }
private bool ValidaExistenciaPanProxy(Portador ptr) { bool vExist = false; try { vExist = PortadorBD.ConsultaCartoes(ptr); } catch (Exception e) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) { Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrCN", e }); } throw; } return(vExist); }
public static bool ConsultaCartoes(Portador ptr) { using (SqlConnection cnx = new SqlConnection(upSight.Consulta.Base.BD.Conexao.StringConexaoBDGlobal)) { bool bRetorno = false; try { string query = "[crpConsultaCartaoCarga]"; using (SqlCommand cmd = new SqlCommand(query, cnx)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Identificacao", SqlDbType.VarChar, 32).Value = ptr.Identificacao.TrimEnd(null); cmd.Parameters.Add("@idEntidade", SqlDbType.VarChar, 32).Value = ptr.IdEntidade; cmd.Parameters.Add("@codConvenio", SqlDbType.VarChar, 32).Value = ptr.CodConvenio; cnx.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleResult); while (dr.Read()) { bRetorno = true; break; } } } catch (SqlException sql) { throw sql; } catch (Exception e) { throw e; } return bRetorno; } }
public static bool ConsultaCartoes(Portador ptr) { using (SqlConnection cnx = new SqlConnection(upSight.Consulta.Base.BD.Conexao.StringConexaoBDGlobal)) { bool bRetorno = false; try { string query = "[crpConsultaCartaoCarga]"; using (SqlCommand cmd = new SqlCommand(query, cnx)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Identificacao", SqlDbType.VarChar, 32).Value = ptr.Identificacao.TrimEnd(null); cmd.Parameters.Add("@idEntidade", SqlDbType.VarChar, 32).Value = ptr.IdEntidade; cmd.Parameters.Add("@codConvenio", SqlDbType.VarChar, 32).Value = ptr.CodConvenio; cnx.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleResult); while (dr.Read()) { bRetorno = true; break; } } } catch (SqlException sql) { throw sql; } catch (Exception e) { throw e; } return(bRetorno); } }
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; } }
/// <summary> /// Mapeia a partir da leitura Excel /// </summary> /// <param name="port"></param> /// <param name="dr"></param> public static List <ValidationResult> Mapeia(this Portador port, DataRow dr, MapaColunaPortador mapa) { List <ValidationResult> resultValid = new List <ValidationResult>(); try { const string tpRegistro = "1"; port.TpRegistro = tpRegistro; //tpPanProxy if (mapa.TpIdentif > -1) { port.TpIdentif = dr[mapa.TpIdentif].ToString(); } else { port.TpIdentif = tpRegistro; } //Obrigatórios //PanProxy if (mapa.Identificacao > -1) { port.Identificacao = dr[mapa.Identificacao].ToString(); } else { resultValid.Add(new ValidationResult("Identificação deve ser preenchida.", new[] { "Identificacao" })); } if (mapa.CPF > -1) { port.CPF = dr[mapa.CPF].ToString().Replace(".", "").Replace("-", "").PadLeft(11, '0'); } else { resultValid.Add(new ValidationResult("CPF deve ser preenchido.", new[] { "CPF" })); } if (mapa.Nome > -1) { port.Nome = dr[mapa.Nome].ToString().Replace(".", ""); } else { resultValid.Add(new ValidationResult("Nome deve ser preenchido.", new[] { "Nome" })); } port.NomeFacial = dr["NomeFacial"].ToString(); string dtNasc = String.IsNullOrEmpty(dr["DtNascimento"].ToString()) ? string.Empty : dr["DtNascimento"].ToString().Replace("/", "").Substring(0, 8); DateTime deliveredDate; if (Data.TentaParseEstendido(dtNasc, Data.FormatoData.AAAAMMDD, out deliveredDate)) { port.DtNascimento = String.IsNullOrEmpty(dtNasc) ? (DateTime?)null : Data.ParseEstendido(dtNasc, Data.FormatoData.AAAAMMDD); } else { resultValid.Add(new ValidationResult(String.Concat("Formato de data inválida:", dtNasc), new[] { "DtNascimento" })); } port.Sexo = dr["Sexo"].ToString(); port.CnpjFilial = dr["CnpjFilial"].ToString().Replace(".", "").Replace("/", "").Replace("-", ""); port.Grupo = dr["Grupo"].ToString(); port.Email = dr["Email"].ToString(); port.DDDCel = dr["DDDCel"].ToString().Replace("(", "").Replace(")", ""); port.Celular = dr["Celular"].ToString().Replace("-", "").Replace(" ", ""); port.NomeMae = dr["NomeMae"].ToString().Replace(".", ""); string idRegistro = dr["IdRegistro"].ToString(); port.IdRegistro = String.IsNullOrEmpty(idRegistro) ? (int?)null : Convert.ToInt32(idRegistro); port.CodConvenio = dr["codConvenio"].ToString(); port.IdEntidade = Convert.ToInt32(dr["idEntidade"]); } catch (Exception e) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) { Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrCN", e }); } throw; } return(resultValid); }
private void InsereCartoes(DataSet ds, int idArquivo, ENLog.TipoLog tpLog, ENLog.MapaArquivos mapArq, int qtdCartoes, int qtdCartoesErro) { List<ValidationResult> lstVr = null; var ptr = new Portador(); var ptrCn = new PortadorCN(); int numLinha = 0; string descErro = string.Empty; foreach (DataRow dr in ds.Tables[0].Rows) { try { if (!String.IsNullOrEmpty(dr["CPF"].ToString())) { lstVr = ptr.Mapeia(dr, ptrCn.CriaMapaColuna(dr)); numLinha++; if (lstVr.Count == 0) { lstVr = ptrCn.Valida(ptr); if (lstVr.Count == 0) { qtdCartoes++; ptr.Insere(idArquivo, numLinha); } else { qtdCartoesErro++; tpLog = ENLog.TipoLog.Erro; this.InsereLogErros(mapArq, tpLog, qtdCartoes, numLinha, lstVr); } } else { tpLog = ENLog.TipoLog.Erro; this.InsereLogErros(mapArq, tpLog, qtdCartoes, numLinha, lstVr); } } } catch (Exception) { tpLog = ENLog.TipoLog.Erro; descErro = "Erro ao processar arquivo de Identificação Simplificada de Cartões"; this.InsereLog(mapArq, qtdCartoes, tpLog, descErro, string.Empty); } } switch (tpLog) { case upSight.Global.Log.EN.TipoLog.Erro: Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, mapArq.Arquivo, "Finaliza processamento de arquivo"); break; default: Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoOk, mapArq.Arquivo, "Finaliza processamento de arquivo"); break; } if (qtdCartoesErro > 0) { qtdCartoes = qtdCartoes - qtdCartoesErro; descErro = String.Format("Total de cartões com erro: {0}", qtdCartoesErro); this.InsereLog(mapArq, qtdCartoes, ENLog.TipoLog.Informação, descErro, string.Empty); } descErro = String.Format("Total de cartões identificados: {0}", qtdCartoes); this.InsereLog(mapArq, qtdCartoes, ENLog.TipoLog.Informação, descErro, string.Empty); }
private void InsereCartoes(DataSet ds, int idArquivo, ENLog.TipoLog tpLog, ENLog.MapaArquivos mapArq, int qtdCartoes, int qtdCartoesErro) { List <ValidationResult> lstVr = null; var ptr = new Portador(); var ptrCn = new PortadorCN(); int numLinha = 0; string descErro = string.Empty; foreach (DataRow dr in ds.Tables[0].Rows) { try { if (!String.IsNullOrEmpty(dr["CPF"].ToString())) { lstVr = ptr.Mapeia(dr, ptrCn.CriaMapaColuna(dr)); numLinha++; if (lstVr.Count == 0) { lstVr = ptrCn.Valida(ptr); if (lstVr.Count == 0) { qtdCartoes++; ptr.Insere(idArquivo, numLinha); } else { qtdCartoesErro++; tpLog = ENLog.TipoLog.Erro; this.InsereLogErros(mapArq, tpLog, qtdCartoes, numLinha, lstVr); } } else { tpLog = ENLog.TipoLog.Erro; this.InsereLogErros(mapArq, tpLog, qtdCartoes, numLinha, lstVr); } } } catch (Exception) { tpLog = ENLog.TipoLog.Erro; descErro = "Erro ao processar arquivo de Identificação Simplificada de Cartões"; this.InsereLog(mapArq, qtdCartoes, tpLog, descErro, string.Empty); } } switch (tpLog) { case upSight.Global.Log.EN.TipoLog.Erro: Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, mapArq.Arquivo, "Finaliza processamento de arquivo"); break; default: Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoOk, mapArq.Arquivo, "Finaliza processamento de arquivo"); break; } if (qtdCartoesErro > 0) { qtdCartoes = qtdCartoes - qtdCartoesErro; descErro = String.Format("Total de cartões com erro: {0}", qtdCartoesErro); this.InsereLog(mapArq, qtdCartoes, ENLog.TipoLog.Informação, descErro, string.Empty); } descErro = String.Format("Total de cartões identificados: {0}", qtdCartoes); this.InsereLog(mapArq, qtdCartoes, ENLog.TipoLog.Informação, descErro, string.Empty); }
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; } }
/// <summary> /// Valida PAN(1) ou Proxy(2) /// </summary> /// <param name="tpIdentif"></param> /// <param name="Identificacao"></param> /// <returns></returns> private void ValidaPanProxy(Portador ptr , List<ValidationResult> lstVr) { try { this._Rgx = new Regex(this._ExpRglrNaoNumerico); if (!this._Rgx.Match(ptr.Identificacao).Success) { if (this.ValidaExistenciaPanProxy(ptr)) { switch (ptr.TpIdentif) { case "1": if (!ptr.Identificacao.Length.Equals(16)) lstVr.Add(new ValidationResult(String.Concat("Identificacao com quantidade de caracteres divergentes a 16: ", ptr.Identificacao), new[] { "Identificacao" })); break; case "2": if (ptr.Identificacao.Length < 8 || ptr.Identificacao.Length > 32) lstVr.Add(new ValidationResult(String.Concat("Identificacao com quantidade de caracteres divergentes( menor que 8 ou maior que 32): ", ptr.Identificacao), new[] { "Identificacao" })); break; } } else { lstVr.Add(new ValidationResult(String.Concat("PanProx inexistente ou convenio não compatível. ", ptr.Identificacao), new[] { "Identificacao" })); } } else lstVr.Add(new ValidationResult(String.Concat("Identificacao com caracteres alfa-numéricos: ", ptr.Identificacao), new[] { "Identificacao" })); } catch (Exception e) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrCN", e }); throw; } }
private bool ValidaExistenciaPanProxy(Portador ptr) { bool vExist = false; try { vExist = PortadorBD.ConsultaCartoes(ptr); } catch (Exception e) { if (upSight.Consulta.Base.BD.Geral.TS.TraceError) Trace.TraceError("{0}: {1}", new object[] { "u.CrtCorp.ACSOIDTS.PtrCN", e }); throw; } return vExist; }