/// <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>
 /// 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}, Linha: {1}", vr.ErrorMessage, linhaAtual);
         this.InsereLog(mapArq, qtdCartoes, tpLog, descErro);
     });
 }
Beispiel #4
0
 /// <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);
     });
 }
Beispiel #5
0
        /// <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>
        /// 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>
        /// 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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        /// <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);
            }
        }