/// <summary> /// Percorre tabela em excel referente a carga /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <param name="obj"></param> /// <returns></returns> public void LePlanilhaExcelEInsereDados(string path, string nomePlanilha = "Sheet1") { string nomeArquivo = Path.GetFileName(path); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOPRGCR, path, 0); Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, mapArq.Arquivo, "Inicia processamento de arquivo"); int idArquivo = mapArq.IdArquivo; //using (OleDbConnection conexao = new OleDbConnection(String.Format(ConfigurationManager.AppSettings["ConexaoExcel"], path))) using (OleDbConnection conexao = new OleDbConnection(String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1';", path))) { conexao.Open(); Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, mapArq.Arquivo, "Em processamento de arquivo"); ENLog.TipoLog tpLog = ENLog.TipoLog.Informação; using (OleDbDataAdapter adapter = new OleDbDataAdapter(String.Format("SELECT * FROM [{0}]", String.Format("{0}$", nomePlanilha)), conexao)) { DataSet ds = new DataSet(); int linhas = adapter.Fill(ds); try { InsereCartoes(ds, idArquivo, tpLog, mapArq); } finally { conexao.Close(); } ACSPRGCRBD.InsereNovoServico(idArquivo); } } }
/// <summary> /// Gera o arquivio CRI de carga de cartões. /// </summary> /// <param name="idArquivo"></param> public void GeraArquivoCRIDeCarga(int idArquivo) { try { var lstCriEn = this.GeraListaDeCartoesParaCarga(idArquivo); var sw = CriBaseCN.SerializaDados(lstCriEn); string nomeArquivoCompleto; //Serializo os dados e gero o arquivo string pathOrigem = String.Empty; CriBaseCN.GeraArquivoFisicoCRI(sw.ToString(), out nomeArquivoCompleto); string nomeArquivo = Path.GetFileName(nomeArquivoCompleto); var log = new CNLog.Logging(); log.IdEntidade = 1; log.IdUsuario = 1; this.Log = log; var mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.FISUkArquivoCRIGeracao, nomeArquivoCompleto); log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, nomeArquivoCompleto, "Inicia processamento de arquivo"); //Insere serviço para processamento do arquivo de retorno CriBD.CriFinaliza(idArquivo, pathOrigem, nomeArquivo); this.InsereLog(mapArq); log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoOk, nomeArquivoCompleto, "Finaliza processamento de arquivo"); } catch (Exception e) { if (Base.TS.TraceError) { Trace.TraceWarning("{0}: {1}", new object[] { "CRTCorp.CRI.CRICN", e }); } } }
/// <summary> /// Insere log /// </summary> /// <param name="mapArq"></param> /// <param name="excecao"></param> private void InsereLog(ENLog.MapaArquivos mapArq, string excecao = null) { ENLog.ArquivoLog aLog = this.Log.ObtemArquivoLog(mapArq.IdArquivo, mapArq.Tipo); aLog.NumLinha = 0; aLog.Descricao = String.Format("{0} linhas processadas", 0); this.Log.InsereLog(aLog); }
/// <summary> /// Loga erros retornados da validação dos campos /// </summary> /// <param name="mapArq"></param> /// <param name="linhaAtual"></param> /// <param name="qtdCartoes"></param> /// <param name="lstVr"></param> private void InsereLogErros(ENLog.MapaArquivos mapArq, ENLog.TipoLog tpLog, int linhaAtual, int qtdCartoes, List<ValidationResult> lstVr) { lstVr.ForEach(vr => { string descErro = String.Format("Msg: {0}, Linha: {1}", vr.ErrorMessage, linhaAtual); this.InsereLog(mapArq, qtdCartoes, tpLog, descErro); }); }
/// <summary> /// Insere Log /// </summary> /// <param name="mapArq"></param> /// <param name="linhaAtual"></param> /// <param name="tpLog"></param> /// <param name="descricao"></param> private void InsereLog(ENLog.MapaArquivos mapArq, int linhaAtual, ENLog.TipoLog tpLog, string descricao) { var arqLog = Log.ObtemArquivoLog(mapArq.IdArquivo, mapArq.Tipo); arqLog.NumLinha = linhaAtual; arqLog.TipoLog = tpLog; arqLog.Descricao = descricao; Log.InsereLog(arqLog); }
/// <summary> /// Loga erros retornados da validação dos campos /// </summary> /// <param name="mapArq"></param> /// <param name="linhaAtual"></param> /// <param name="qtdCartoes"></param> /// <param name="lstVr"></param> private void InsereLogErros(ENLog.MapaArquivos mapArq, ENLog.TipoLog tpLog, int linhaAtual, int qtdCartoes, List <ValidationResult> lstVr) { lstVr.ForEach(vr => { string descErro = String.Format("Msg: {0}", vr.ErrorMessage, linhaAtual); string coluna = ((string[])(vr.MemberNames))[0]; this.InsereLog(mapArq, qtdCartoes, tpLog, descErro, coluna); }); }
/// <summary> /// Percorre a tabela de Excel e retorna um tipo de objeto /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <param name="obj"></param> /// <returns></returns> public void LePlanilhaExcelEInsereDados(string path, int idEntidade, string nomePlanilha = "Sheet1") { string nomeArquivo = Path.GetFileName(path); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC, path, 0); Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, String.Empty, "Inicia processamento de arquivo"); int idArquivo = mapArq.IdArquivo; int qtdCartoes = 0; int qtdCartoesErro = 0; using (OleDbConnection conexao = new OleDbConnection(String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1';", path))) { Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, mapArq.Arquivo, "Em processamento de arquivo"); string descErro = String.Empty; conexao.Open(); ENLog.TipoLog tpLog = ENLog.TipoLog.Informação; using (OleDbDataAdapter adapter = new OleDbDataAdapter(String.Format("SELECT * FROM [{0}]", String.Format("{0}$", nomePlanilha)), conexao)) { try { DataSet ds = new DataSet(); int linhas = adapter.Fill(ds); InsereCartoes(ds, idArquivo, tpLog, mapArq, qtdCartoes, qtdCartoesErro); } catch (Exception e) { tpLog = ENLog.TipoLog.Erro; descErro = "Erro ao processar arquivo Identificação Simplificada de Cartões"; this.InsereLog(mapArq, qtdCartoes, tpLog, descErro, string.Empty); throw; } finally { conexao.Close(); } PortadorBD.InsereNovoServico(idArquivo); } } }
public string GeraArquivoRetorno(string path, int idArquivo) { int numLinha = 0; string nomeArquivoFormatado = string.Empty; string nomeArquivo = string.Empty; ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(string.Empty, ENLog.TipoArquivo.ACSOEMIS_R, string.Empty, 0); try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } numLinha++; //Gera cabeçalho var cab = new ACSOEMIS_RCabecalhoEN(); cab.IdArquivo = idArquivo; cab.CompoeACSOEMIS_RCabecalho(cab); cab.NumLinha = numLinha; nomeArquivo = FormataNomeArquivo(cab.CodConvenio); nomeArquivoFormatado = System.IO.Path.Combine(path, nomeArquivo); mapArq = new ENLog.MapaArquivos(nomeArquivoFormatado, ENLog.TipoArquivo.ACSOEMIS_R, path, 0); this.Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, path, "Inicia processamento de arquivo"); int novoIdArquivo = mapArq.IdArquivo; using (var sw = new StreamWriter(nomeArquivoFormatado, false, Encoding.UTF8)) { sw.WriteLine(cab.ToString()); //Gera detalhes numLinha++; var det = new ACSOEMIS_RDetalheEN(); det.IdArquivo = idArquivo; det.NumLinha = numLinha; det.CompoeACSOEMIS_RDetalheENEmissRet(det); sw.WriteLine(det.ToString(TpRetornoDetalhe.RetornoDeEmissão)); var iDetCm = det.ConsultaDetalhe(); int contEmissao = 0; int contErro = 0; foreach (var detalhe in iDetCm) { try { this.Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, String.Empty, "Inicia processamento de arquivo"); contEmissao++; numLinha++; detalhe.numSeq = contEmissao.ToString("000000"); detalhe.Proxy = upSight.Consulta.Base.Sistema.CompletaEspacoDireita(contEmissao, 32); detalhe.NumLinha = numLinha; //gera proxy string prxParcial = String.Concat(detalhe.CodConvenio, contEmissao.ToString("00000000000")); string dv = DigitoVerificador.CalculaDV(prxParcial, DigitoVerificador.TipoDigitoVerificador.Modulo10); detalhe.Proxy = String.Concat(prxParcial, dv); sw.WriteLine(detalhe.ToString(TpRetornoDetalhe.DetalheDosCartões)); } catch (Exception e) { if (BDGeral.TS.TraceError) { Trace.TraceError("{0}: {1}", new object[] { "u.E.L.E.GAE", e }); } contErro++; string descErro = String.Format("Total de linhas com erro: {0}", contErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } } //Gera Rodapé numLinha++; var rdp = ACSOEMIS_RRodapeEN.CompoeACSOEMIS_RRodapeEN(contEmissao, numLinha); sw.WriteLine(rdp.ToString()); } } catch (Exception e) { if (BDGeral.TS.TraceError) { Trace.TraceError("{0}: {1}", new object[] { "u.E.L.E.GAE", e }); } string descErro = "Erro processamento arquivo"; Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoErro, path, descErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } return(nomeArquivo); }
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); }
/// <summary> /// Dado o arquivo ele é realizado o parser e seus dados são salvos nas tabelas correspondentes /// </summary> /// <param name="path"></param> public void ProcessaArquivoIdentificacaoSimpCrt(string path, int idEntidade) { string nomeArquivo = Path.GetFileName(path); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC, path, 0); Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, String.Empty, "Inicia processamento de arquivo"); int idArquivo = mapArq.IdArquivo; int linhaAtual = 0; int qtdCartoes = 0; int qtdCartoesErro = 0; using (StreamReader sr = new StreamReader(path)) { Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, mapArq.Arquivo, "Em processamento de arquivo"); string descErro = String.Empty; string codConvenio = string.Empty; ENLog.TipoLog tpLog = ENLog.TipoLog.Informação; DataSet ds = new DataSet(); DataTable dt = new DataTable(); while (!sr.EndOfStream) { try { linhaAtual++; string linha = sr.ReadLine(); switch (linha.Substring(0, 1)) { case "0": codConvenio = linha.Substring(95, 10).TrimEnd(null); crtACSOIDTSCCabecalhoEN.Mapeia(linha, idArquivo).Insere(); break; case "1": dt.Rows.Add(crtACSOIDTSCDetalheEN.MapeiaTXTDet(linha, idArquivo, codConvenio, idEntidade, dt)); qtdCartoes++; break; case "9": crtACSOIDTSCRodapeEN.Mapeia(linha, idArquivo).Insere(); break; } } catch (Exception e) { tpLog = ENLog.TipoLog.Erro; descErro = "Erro ao processar arquivo Identificação Simplificada de Cartões"; this.InsereLog(mapArq, qtdCartoes, tpLog, descErro, string.Empty); throw; } } ds.Tables.Add(dt); InsereCartoes(ds, idArquivo, tpLog, mapArq, qtdCartoes, qtdCartoesErro); //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); PortadorBD.InsereNovoServico(idArquivo); } }
/// <summary> /// Dado o arquivo ele é realizado o parser e seus dados são salvos nas tabelas correspondentes /// </summary> /// <param name="path"></param> public void ProcessaArquivoCarga(string path, int idEdntidade, int idArquivo = 0) { string nomeArquivo = Path.GetFileName(path); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOPRGCR, path, 0, idArquivo); Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, mapArq.Arquivo, "Inicia processamento de arquivo"); int novoidArquivo = mapArq.IdArquivo; int linhaAtual = 0; int qtdCarga = 0; using (StreamReader sr = new StreamReader(path)) { DataSet ds = new DataSet(); DataTable dt = new DataTable(); ENLog.TipoLog tpLog = ENLog.TipoLog.Informação; Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, mapArq.Arquivo, "Em processamento de arquivo"); string descErro = String.Empty; while (!sr.EndOfStream) { try { linhaAtual++; string linha = sr.ReadLine(); switch (linha.Substring(0, 1)) { case "0": var cab = new ACSOPRGCRCabecalhoEN(novoidArquivo, linha); cab.Insere(); break; case "1": var lot = new ACSOPRGCRLoteEN(novoidArquivo, linha); lot.Insere(); break; case "2": var det = new ACSOPRGCRDetalheEN(novoidArquivo, linha); dt.Rows.Add(ACSOPRGCRDetalheEN.MapeiaTXT(linha, novoidArquivo, dt, idEdntidade)); //det.Insere(); qtdCarga++; break; case "9": var rdp = new ACSOPRGCRRodapeEN(novoidArquivo, linha); rdp.Insere(); break; } } catch (Exception e) { descErro = String.Format("Erro ao processar arquivo de Carga de Cartões. Linha: {0}", linhaAtual); this.InsereLog(mapArq, linhaAtual, ENLog.TipoLog.Alerta, descErro); throw; } } ds.Tables.Add(dt); InsereCartoes(ds, idArquivo, tpLog, mapArq); //Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoOk, mapArq.Arquivo, "Finaliza processamento de arquivo"); //descErro = String.Format("Total de cargas processadas: {0}", qtdCarga); //this.InsereLog(mapArq, linhaAtual, ENLog.TipoLog.Informação, descErro); } ACSPRGCRBD.InsereNovoServico(idArquivo); }
/// <summary> /// Dado o arquivo ele é realizado o parser e seus dados são salvos nas tabelas correspondentes /// </summary> /// <param name="path"></param> public void ProcessaArquivoIdentificacaoSimpCrt(string path, int idEntidade) { string nomeArquivo = Path.GetFileName(path); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC, path, 0); Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, String.Empty, "Inicia processamento de arquivo"); int idArquivo = mapArq.IdArquivo; int linhaAtual = 0; int qtdCartoes = 0; int qtdCartoesErro = 0; using (StreamReader sr = new StreamReader(path)) { Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, mapArq.Arquivo, "Em processamento de arquivo"); string descErro = String.Empty; string codConvenio = string.Empty; ENLog.TipoLog tpLog = ENLog.TipoLog.Informação; DataSet ds = new DataSet(); DataTable dt = new DataTable(); while (!sr.EndOfStream) { try { linhaAtual++; string linha = sr.ReadLine(); switch (linha.Substring(0, 1)) { case "0": codConvenio = linha.Substring(95, 10).TrimEnd(null); crtACSOIDTSCCabecalhoEN.Mapeia(linha, idArquivo).Insere(); break; case "1": dt.Rows.Add(crtACSOIDTSCDetalheEN.MapeiaTXTDet(linha, idArquivo, codConvenio, idEntidade, dt)); qtdCartoes++; break; case "9": crtACSOIDTSCRodapeEN.Mapeia(linha, idArquivo).Insere(); break; } } catch (Exception e) { tpLog = ENLog.TipoLog.Erro; descErro = "Erro ao processar arquivo Identificação Simplificada de Cartões"; this.InsereLog(mapArq, qtdCartoes, tpLog, descErro, string.Empty); throw; } } ds.Tables.Add(dt); InsereCartoes(ds, idArquivo, tpLog, mapArq, qtdCartoes, qtdCartoesErro); //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); PortadorBD.InsereNovoServico(idArquivo); } }
/// <summary> /// Percorre a tabela de Excel e retorna um tipo de objeto /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <param name="obj"></param> /// <returns></returns> public void LePlanilhaExcelEInsereDados(string path, int idEntidade, string nomePlanilha = "Sheet1") { string nomeArquivo = Path.GetFileName(path); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC, path, 0); Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, String.Empty, "Inicia processamento de arquivo"); int idArquivo = mapArq.IdArquivo; int qtdCartoes = 0; int qtdCartoesErro = 0; using (OleDbConnection conexao = new OleDbConnection(String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1';", path))) { Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, mapArq.Arquivo, "Em processamento de arquivo"); string descErro = String.Empty; conexao.Open(); ENLog.TipoLog tpLog = ENLog.TipoLog.Informação; using (OleDbDataAdapter adapter = new OleDbDataAdapter(String.Format("SELECT * FROM [{0}]", String.Format("{0}$", nomePlanilha)), conexao)) { try { DataSet ds = new DataSet(); int linhas = adapter.Fill(ds); InsereCartoes(ds, idArquivo, tpLog,mapArq, qtdCartoes, qtdCartoesErro); } catch (Exception e) { tpLog = ENLog.TipoLog.Erro; descErro = "Erro ao processar arquivo Identificação Simplificada de Cartões"; this.InsereLog(mapArq, qtdCartoes, tpLog, descErro,string.Empty); throw; } finally { conexao.Close(); } PortadorBD.InsereNovoServico(idArquivo); } } }
/// <summary> /// Insere cartões de arquivos XLS e TXT. /// </summary> /// <param name="ds"></param> /// <param name="idArquivo"></param> /// <param name="tpLog"></param> /// <param name="mapArq"></param> private void InsereCartoes(DataSet ds, int idArquivo, ENLog.TipoLog tpLog, ENLog.MapaArquivos mapArq) { int qtdCgr = 0; try { var acsCrgDetEn = new ACSOPRGCRDetalheEN(); var crgCn = new CargaCN(); List<ValidationResult> lstVr = null; int numLinha = 0; foreach (DataRow dr in ds.Tables[0].Rows) { try { if (!String.IsNullOrEmpty(dr["Identificacao"].ToString())) { numLinha++; lstVr = acsCrgDetEn.Mapeia(dr, crgCn.CriaMapaColuna(dr)); if (lstVr.Count == 0) { lstVr = crgCn.Valida(acsCrgDetEn); if (lstVr.Count == 0) { acsCrgDetEn.NumLinha = numLinha; acsCrgDetEn.IdArquivo = idArquivo; acsCrgDetEn.Insere(); qtdCgr++; } else { tpLog = ENLog.TipoLog.Informação; this.InsereLogErros(mapArq, tpLog, qtdCgr, numLinha, lstVr); } } else { tpLog = ENLog.TipoLog.Informação; this.InsereLogErros(mapArq, tpLog, qtdCgr, numLinha, lstVr); } } } catch (Exception e) { tpLog = ENLog.TipoLog.Alerta; string descErro = String.Format("Erro ao processar arquivo de Programação de Carga de Cartões. Linha: {0}", numLinha); this.InsereLog(mapArq, qtdCgr, tpLog, descErro); } } } catch (Exception e) { tpLog = ENLog.TipoLog.Erro; string descErro = "Erro ao processar arquivo de Programação de Carga de Cartões"; this.InsereLog(mapArq, qtdCgr, tpLog, descErro); throw; } 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; } string desc = String.Format("Total de cargas realizadas: {0}", qtdCgr); this.InsereLog(mapArq, qtdCgr, ENLog.TipoLog.Informação, desc); }
/// <summary> /// Processa os dados retornados no arquivo de retorno de carga /// </summary> /// <param name="idArquivo"></param> /// <returns></returns> public void ProcessaDadosParaGerarArquivoRetornoCarga(int idArquivo, string pathArquivoOrigem, string codConvenio = "ACSO") { //using (StringWriter sw = new StringWriter(new System.Globalization.CultureInfo("pt-BR"))) //{ DateTime dtAgora = DateTime.Now; string pathDestino = ConfigurationManager.AppSettings["ACSOIDTSC_R.CRI.DiretotioDestino"]; string nomeArquivo = this.FormataNomeArquivo(codConvenio, dtAgora); string pathCompleto = Path.Combine(pathDestino, nomeArquivo); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC_R, pathArquivoOrigem, 0); Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, pathCompleto, "Inicia processamento de arquivo"); mapArq.IdArquivo = idArquivo; int novoIdArquivo = mapArq.IdArquivo; int numLinha = 0; EnumRetornoBase.StatusProcessamento statusProc = EnumRetornoBase.StatusProcessamento.Sucesso; try { //Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, pathDestino, "Inicia processamento de arquivo"); numLinha++; //Gero Cabeçalho var cab = this.MontaCabecalho(novoIdArquivo, dtAgora, nomeArquivo, "ACSO", "ACESSO", numLinha); cab.Insere(); //sw.WriteLine(cab.ToString()); //Busco os detalhes var detalhe = new ACSOPRGCR_RDetalheEN(); detalhe.IdArquivo = novoIdArquivo; var detalhesRetorno = DetalheRetornoBaseBD.ConsultaDetalheCarga(idArquivo); //Totalizadores var cargaRejet = detalhesRetorno.Where(crgRej => !String.IsNullOrEmpty(crgRej.Retorno)); int totalRejeitadas = (cargaRejet != null) ? cargaRejet.Count() : 0; int totalCarga = detalhesRetorno.Count() - totalRejeitadas; decimal vlrTotalCrgRej = cargaRejet.Sum(vlrCrgRejet => vlrCrgRejet.Valor); decimal vlrTotalCrg = detalhesRetorno.Sum(vlrCrg => vlrCrg.Valor) - vlrTotalCrgRej; //Se houve rejeições mudo o status do processamento if (totalRejeitadas > 0) statusProc = EnumRetornoBase.StatusProcessamento.ErroGenérico; //Gero Lote this.MontaLote(novoIdArquivo, "01", totalRejeitadas, totalCarga, numLinha, statusProc).Insere(); //sw.WriteLine(this.MontaLote(novoIdArquivo, "", totalRejeitadas, totalCarga, numLinha, statusProc).ToString()); int contErro = 0; //Gero Detalhe detalhesRetorno.ForEach(delegate(CargaRetornoDetalheEN crgdet) { try { numLinha++; this.CompoeDetalhe(crgdet, detalhe, codConvenio, numLinha); detalhe.Insere(); //sw.WriteLine(detalhe.ToString()); } catch (Exception) { contErro++; string descErro = String.Format("Total de linhas com erro: {0}", contErro); //this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, contErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Alerta, descErro); } } ); numLinha++; //Gero Rodapé var rdp = this.MontaRodape(novoIdArquivo, totalCarga, totalCarga, vlrTotalCrg, totalRejeitadas, vlrTotalCrg, numLinha); rdp.Insere(); //sw.WriteLine(rdp.ToString()); } catch (Exception) { string descErro = "Erro processamento arquivo"; Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoErro, pathCompleto, descErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } //} }
/// <summary> /// Processo o arquivo de retorno relacionado a identificação /// </summary> /// <param name="idArquivo"></param> /// <returns></returns> public void ProcessaDadosParaGerarArquivoRetornoIdentif(int idArquivo, string pathArquivoOrigem, string codConvenio = "ACSO") { // using (StringWriter sw = new StringWriter(new System.Globalization.CultureInfo("pt-BR"))) // { DateTime dtAgora = DateTime.Now; string pathDestino = ConfigurationManager.AppSettings["ACSOIDTSC_R.CRI.DiretotioDestino"]; string nomeArquivo = this.FormataNomeArquivo(codConvenio, dtAgora); string pathCompleto = Path.Combine(pathDestino, nomeArquivo); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC_R, pathArquivoOrigem, 0); this.Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, pathArquivoOrigem, "Inicia processamento de arquivo"); int novoIdArquivo = mapArq.IdArquivo; int numLinha = 0; try { this.Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, String.Empty, "Inicia processamento de arquivo"); numLinha++; //Gero Cabeçalho var cab = this.MontaCabecalho(novoIdArquivo, dtAgora, nomeArquivo, "ACSO", "ACESSO", numLinha); cab.Insere(); //sw.WriteLine(cab.ToString()); //Gero Detalhe var detalhe = new Identificacao.ACSOIDTSC_R.ACSOIDTSC_RDetalheEN(); detalhe.DataProc = dtAgora; detalhe.IdArquivo = novoIdArquivo; var detalhesRetorno = DetalheRetornoBaseBD.ConsultaDetalheIdentificacao(idArquivo); int contTotalRetorno = 0; int contErro = 0; foreach (var detalheRet in detalhesRetorno) { try { numLinha++; contTotalRetorno++; this.CompoeDetalhe(detalheRet, detalhe, numLinha); detalhe.Insere(); //sw.WriteLine(detalhe.ToString()); } catch (Exception) { contErro++; string descErro = String.Format("Total de linhas com erro: {0}", contErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } } numLinha++; //Gero Rodapé var rdp = this.MontaRodape(novoIdArquivo, numLinha, contTotalRetorno); rdp.Insere(); //sw.WriteLine(rdp.ToString()); } catch (Exception) { string descErro = "Erro processamento arquivo"; Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoErro, pathCompleto, descErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } //} }
/// <summary> /// Gera o arquivio CRI de carga de cartões. /// </summary> /// <param name="idArquivo"></param> public void GeraArquivoCRIDeCarga(int idArquivo) { try { var lstCriEn = this.GeraListaDeCartoesParaCarga(idArquivo); var sw = CriBaseCN.SerializaDados(lstCriEn); string nomeArquivoCompleto; //Serializo os dados e gero o arquivo string pathOrigem = String.Empty; CriBaseCN.GeraArquivoFisicoCRI(sw.ToString(), out nomeArquivoCompleto); string nomeArquivo = Path.GetFileName(nomeArquivoCompleto); var log = new CNLog.Logging(); log.IdEntidade = 1; log.IdUsuario = 1; this.Log = log; var mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.FISUkArquivoCRIGeracao, nomeArquivoCompleto); log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, nomeArquivoCompleto, "Inicia processamento de arquivo"); //Insere serviço para processamento do arquivo de retorno CriBD.CriFinaliza(idArquivo, pathOrigem, nomeArquivo); this.InsereLog(mapArq); log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoOk, nomeArquivoCompleto, "Finaliza processamento de arquivo"); } catch (Exception e) { if (Base.TS.TraceError) Trace.TraceWarning("{0}: {1}", new object[] { "CRTCorp.CRI.CRICN", e }); } }
/// <summary> /// Processa os dados retornados no arquivo de retorno de carga /// </summary> /// <param name="idArquivo"></param> /// <returns></returns> public void ProcessaDadosParaGerarArquivoRetornoCarga(int idArquivo, string pathArquivoOrigem, string codConvenio = "ACSO") { //using (StringWriter sw = new StringWriter(new System.Globalization.CultureInfo("pt-BR"))) //{ DateTime dtAgora = DateTime.Now; string pathDestino = ConfigurationManager.AppSettings["ACSOIDTSC_R.CRI.DiretotioDestino"]; string nomeArquivo = this.FormataNomeArquivo(codConvenio, dtAgora); string pathCompleto = Path.Combine(pathDestino, nomeArquivo); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC_R, pathArquivoOrigem, 0); Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, pathCompleto, "Inicia processamento de arquivo"); mapArq.IdArquivo = idArquivo; int novoIdArquivo = mapArq.IdArquivo; int numLinha = 0; EnumRetornoBase.StatusProcessamento statusProc = EnumRetornoBase.StatusProcessamento.Sucesso; try { //Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, pathDestino, "Inicia processamento de arquivo"); numLinha++; //Gero Cabeçalho var cab = this.MontaCabecalho(novoIdArquivo, dtAgora, nomeArquivo, "ACSO", "ACESSO", numLinha); cab.Insere(); //sw.WriteLine(cab.ToString()); //Busco os detalhes var detalhe = new ACSOPRGCR_RDetalheEN(); detalhe.IdArquivo = novoIdArquivo; var detalhesRetorno = DetalheRetornoBaseBD.ConsultaDetalheCarga(idArquivo); //Totalizadores var cargaRejet = detalhesRetorno.Where(crgRej => !String.IsNullOrEmpty(crgRej.Retorno)); int totalRejeitadas = (cargaRejet != null) ? cargaRejet.Count() : 0; int totalCarga = detalhesRetorno.Count() - totalRejeitadas; decimal vlrTotalCrgRej = cargaRejet.Sum(vlrCrgRejet => vlrCrgRejet.Valor); decimal vlrTotalCrg = detalhesRetorno.Sum(vlrCrg => vlrCrg.Valor) - vlrTotalCrgRej; //Se houve rejeições mudo o status do processamento if (totalRejeitadas > 0) { statusProc = EnumRetornoBase.StatusProcessamento.ErroGenérico; } //Gero Lote this.MontaLote(novoIdArquivo, "01", totalRejeitadas, totalCarga, numLinha, statusProc).Insere(); //sw.WriteLine(this.MontaLote(novoIdArquivo, "", totalRejeitadas, totalCarga, numLinha, statusProc).ToString()); int contErro = 0; //Gero Detalhe detalhesRetorno.ForEach(delegate(CargaRetornoDetalheEN crgdet) { try { numLinha++; this.CompoeDetalhe(crgdet, detalhe, codConvenio, numLinha); detalhe.Insere(); //sw.WriteLine(detalhe.ToString()); } catch (Exception) { contErro++; string descErro = String.Format("Total de linhas com erro: {0}", contErro); //this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, contErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Alerta, descErro); } } ); numLinha++; //Gero Rodapé var rdp = this.MontaRodape(novoIdArquivo, totalCarga, totalCarga, vlrTotalCrg, totalRejeitadas, vlrTotalCrg, numLinha); rdp.Insere(); //sw.WriteLine(rdp.ToString()); } catch (Exception) { string descErro = "Erro processamento arquivo"; Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoErro, pathCompleto, descErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } //} }
/// <summary> /// Processo o arquivo de retorno relacionado a identificação /// </summary> /// <param name="idArquivo"></param> /// <returns></returns> public void ProcessaDadosParaGerarArquivoRetornoIdentif(int idArquivo, string pathArquivoOrigem, string codConvenio = "ACSO") { // using (StringWriter sw = new StringWriter(new System.Globalization.CultureInfo("pt-BR"))) // { DateTime dtAgora = DateTime.Now; string pathDestino = ConfigurationManager.AppSettings["ACSOIDTSC_R.CRI.DiretotioDestino"]; string nomeArquivo = this.FormataNomeArquivo(codConvenio, dtAgora); string pathCompleto = Path.Combine(pathDestino, nomeArquivo); ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(nomeArquivo, ENLog.TipoArquivo.ACSOIDTSC_R, pathArquivoOrigem, 0); this.Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, pathArquivoOrigem, "Inicia processamento de arquivo"); int novoIdArquivo = mapArq.IdArquivo; int numLinha = 0; try { this.Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, String.Empty, "Inicia processamento de arquivo"); numLinha++; //Gero Cabeçalho var cab = this.MontaCabecalho(novoIdArquivo, dtAgora, nomeArquivo, "ACSO", "ACESSO", numLinha); cab.Insere(); //sw.WriteLine(cab.ToString()); //Gero Detalhe var detalhe = new Identificacao.ACSOIDTSC_R.ACSOIDTSC_RDetalheEN(); detalhe.DataProc = dtAgora; detalhe.IdArquivo = novoIdArquivo; var detalhesRetorno = DetalheRetornoBaseBD.ConsultaDetalheIdentificacao(idArquivo); int contTotalRetorno = 0; int contErro = 0; foreach (var detalheRet in detalhesRetorno) { try { numLinha++; contTotalRetorno++; this.CompoeDetalhe(detalheRet, detalhe, numLinha); detalhe.Insere(); //sw.WriteLine(detalhe.ToString()); } catch (Exception) { contErro++; string descErro = String.Format("Total de linhas com erro: {0}", contErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } } numLinha++; //Gero Rodapé var rdp = this.MontaRodape(novoIdArquivo, numLinha, contTotalRetorno); rdp.Insere(); //sw.WriteLine(rdp.ToString()); } catch (Exception) { string descErro = "Erro processamento arquivo"; Log.AtualizaArquivo <ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoErro, pathCompleto, descErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } //} }
public string GeraArquivoRetorno(string path, int idArquivo) { int numLinha = 0; string nomeArquivoFormatado = string.Empty; string nomeArquivo = string.Empty; ENLog.MapaArquivos mapArq = new ENLog.MapaArquivos(string.Empty,ENLog.TipoArquivo.ACSOEMIS_R,string.Empty,0); try { if (!Directory.Exists(path)) Directory.CreateDirectory(path); numLinha++; //Gera cabeçalho var cab = new ACSOEMIS_RCabecalhoEN(); cab.IdArquivo = idArquivo; cab.CompoeACSOEMIS_RCabecalho(cab); cab.NumLinha = numLinha; nomeArquivo = FormataNomeArquivo(cab.CodConvenio); nomeArquivoFormatado = System.IO.Path.Combine(path, nomeArquivo); mapArq = new ENLog.MapaArquivos(nomeArquivoFormatado, ENLog.TipoArquivo.ACSOEMIS_R, path, 0); this.Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.NaoProcessado, path, "Inicia processamento de arquivo"); int novoIdArquivo = mapArq.IdArquivo; using (var sw = new StreamWriter(nomeArquivoFormatado, false, Encoding.UTF8)) { sw.WriteLine(cab.ToString()); //Gera detalhes numLinha++; var det = new ACSOEMIS_RDetalheEN(); det.IdArquivo = idArquivo; det.NumLinha = numLinha; det.CompoeACSOEMIS_RDetalheENEmissRet(det); sw.WriteLine(det.ToString(TpRetornoDetalhe.RetornoDeEmissão)); var iDetCm = det.ConsultaDetalhe(); int contEmissao = 0; int contErro = 0; foreach (var detalhe in iDetCm) { try { this.Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.EmProcessamento, String.Empty, "Inicia processamento de arquivo"); contEmissao++; numLinha++; detalhe.numSeq = contEmissao.ToString("000000"); detalhe.Proxy = upSight.Consulta.Base.Sistema.CompletaEspacoDireita(contEmissao, 32); detalhe.NumLinha = numLinha; //gera proxy string prxParcial = String.Concat(detalhe.CodConvenio, contEmissao.ToString("00000000000")); string dv = DigitoVerificador.CalculaDV(prxParcial, DigitoVerificador.TipoDigitoVerificador.Modulo10); detalhe.Proxy = String.Concat(prxParcial, dv); sw.WriteLine(detalhe.ToString(TpRetornoDetalhe.DetalheDosCartões)); } catch (Exception e) { if (BDGeral.TS.TraceError) Trace.TraceError("{0}: {1}", new object[] { "u.E.L.E.GAE", e }); contErro++; string descErro = String.Format("Total de linhas com erro: {0}", contErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } } //Gera Rodapé numLinha++; var rdp = ACSOEMIS_RRodapeEN.CompoeACSOEMIS_RRodapeEN(contEmissao, numLinha); sw.WriteLine(rdp.ToString()); } } catch (Exception e) { if (BDGeral.TS.TraceError) Trace.TraceError("{0}: {1}", new object[] { "u.E.L.E.GAE", e }); string descErro = "Erro processamento arquivo"; Log.AtualizaArquivo<ENLog.MapaArquivos>(mapArq, ENLog.StatusProcessamentoArquivo.ProcessadoErro, path, descErro); this.InsereLog(mapArq, numLinha, ENLog.TipoLog.Informação, descErro); } return nomeArquivo; }