public ActionResult importar(HttpPostedFileBase arquivoExcel)
        {
            var lista = new List <ImportacaoFinanceiroDTO>();

            string extensao            = UTIL.Upload.UploadConfig.getExtension(arquivoExcel);
            string pathExcelTemporario = Path.Combine(UtilConfig.pathAbsTempFiles, string.Concat(UtilString.onlyNumber(DateTime.Now.ToString()), extensao));

            arquivoExcel.SaveAs(pathExcelTemporario);

            using (FileStream stream = System.IO.File.Open(pathExcelTemporario, FileMode.Open, FileAccess.Read)) {
                IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                excelReader.IsFirstRowAsColumnNames = true;
                DataSet result = excelReader.AsDataSet();

                foreach (DataTable table in result.Tables)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        var OImportacao = new ImportacaoFinanceiroDTO();

                        OImportacao.ano         = getCampo(table, i, 0);
                        OImportacao.mes         = getCampo(table, i, 1);
                        OImportacao.dia         = getCampo(table, i, 2);
                        OImportacao.flagFixa    = getCampo(table, i, 3);
                        OImportacao.descricao   = getCampo(table, i, 4);
                        OImportacao.centroCusto = getCampo(table, i, 5);
                        //  OImportacao.CentroCusto = getCampo(table, i, 6);
                        OImportacao.categoria               = getCampo(table, i, 7);
                        OImportacao.tipoCategoria           = getCampo(table, i, 8);
                        OImportacao.detalheCategoria        = getCampo(table, i, 9);
                        OImportacao.qtdeParcela             = getCampo(table, i, 10);
                        OImportacao.formaPagamento          = getCampo(table, i, 11);
                        OImportacao.descricaoFormaPagamento = getCampo(table, i, 12);
                        OImportacao.valor = getCampo(table, i, 13);

                        lista.Add(OImportacao);
                    }
                }
            }

            if (lista.Count > 0)
            {
                foreach (var item in lista)
                {
                    if (!String.IsNullOrEmpty(item.ano))
                    {
                        var OTituloDespesaBL = new ContasAPagarBL();

                        var dtPagamento            = new DateTime(UtilNumber.toInt32(item.ano), UtilNumber.toInt32(item.mes), UtilNumber.toInt32(item.dia));
                        var idCategoria            = this.getCategoria(item.categoria);
                        var idTipoCategoria        = this.getTipoCategoria(item.tipoCategoria);
                        var idDetalheTipoCategoria = this.getDetalheCategoria(item.detalheCategoria);
                        var idCentroCusto          = this.getCentroCusto(item.centroCusto);
                        var idFormaPagamento       = this.getFormaPagamento(item.formaPagamento);

                        TituloDespesa OTituloDespesa = new TituloDespesa();
                        OTituloDespesa.descricao              = item.descricao;
                        OTituloDespesa.idDespesa              = 0;
                        OTituloDespesa.idCategoria            = idCategoria;
                        OTituloDespesa.idTipoCategoria        = idTipoCategoria;
                        OTituloDespesa.idDetalheTipoCategoria = idDetalheTipoCategoria;
                        OTituloDespesa.idCentroCusto          = idCentroCusto;
                        OTituloDespesa.idPeriodoRepeticao     = 1;
                        OTituloDespesa.idAgrupador            = 0;
                        OTituloDespesa.nroDocumento           = "";
                        OTituloDespesa.qtdeRepeticao          = 4;
                        OTituloDespesa.valorTotal             = Convert.ToDecimal(item.valor);
                        OTituloDespesa.qtdeRepeticao          = 1;
                        OTituloDespesa.dtQuitacao             = dtPagamento;

                        TituloDespesaPagamento OTituloDespesaPagamento = new TituloDespesaPagamento();
                        OTituloDespesaPagamento.dtPagamento      = dtPagamento;
                        OTituloDespesaPagamento.idFormaPagamento = idFormaPagamento;
                        //OTituloDespesaPagamento.descricao = OTituloDespesa.descricao;
                        OTituloDespesaPagamento.descParcela   = item.descricaoFormaPagamento;
                        OTituloDespesaPagamento.dtVencimento  = dtPagamento;
                        OTituloDespesaPagamento.flagPago      = "S";
                        OTituloDespesaPagamento.valorOriginal = OTituloDespesa.valorTotal.Value;
                        OTituloDespesaPagamento.valorPago     = OTituloDespesa.valorTotal.Value;

                        OTituloDespesa.listaTituloDespesaPagamento = new List <TituloDespesaPagamento>();
                        OTituloDespesa.listaTituloDespesaPagamento.Add(OTituloDespesaPagamento);

                        //if (!OTituloDespesaBL.exists(x => x.dtQuitacao == OTituloDespesa.dtQuitacao
                        //                                  && x.descricao == OTituloDespesa.descricao
                        //                                  && x.valorTotal == OTituloDespesa.valorTotal))
                        //{
                        // OTituloDespesaBL.salvar(OTituloDespesa);
                        //}
                    }
                }
            }

            return(View());
        }
        public ActionResult importarDespesaAtualizar(HttpPostedFileBase arquivoExcel)
        {
            var lista = new List <ImportacaoFinanceiroDTO>();

            string extensao            = UTIL.Upload.UploadConfig.getExtension(arquivoExcel);
            string pathExcelTemporario = Path.Combine(UtilConfig.pathAbsTempFiles, string.Concat(UtilString.onlyNumber(DateTime.Now.ToString()), extensao));

            arquivoExcel.SaveAs(pathExcelTemporario);

            using (FileStream stream = System.IO.File.Open(pathExcelTemporario, FileMode.Open, FileAccess.Read)) {
                IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                excelReader.IsFirstRowAsColumnNames = true;
                DataSet result = excelReader.AsDataSet();

                foreach (DataTable table in result.Tables)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        var OImportacao = new ImportacaoFinanceiroDTO();

                        OImportacao.ano         = getCampo(table, i, 0);
                        OImportacao.mes         = getCampo(table, i, 1);
                        OImportacao.dia         = getCampo(table, i, 2);
                        OImportacao.flagFixa    = getCampo(table, i, 3);
                        OImportacao.descricao   = getCampo(table, i, 4);
                        OImportacao.centroCusto = getCampo(table, i, 5);
                        //OImportacao.CentroCusto = getCampo(table, i, 6);
                        OImportacao.categoria               = getCampo(table, i, 7);
                        OImportacao.tipoCategoria           = getCampo(table, i, 8);
                        OImportacao.detalheCategoria        = getCampo(table, i, 9);
                        OImportacao.qtdeParcela             = getCampo(table, i, 10);
                        OImportacao.formaPagamento          = getCampo(table, i, 11);
                        OImportacao.descricaoFormaPagamento = getCampo(table, i, 12);
                        OImportacao.valor = getCampo(table, i, 13);

                        lista.Add(OImportacao);
                    }
                }
            }

            if (lista.Count > 0)
            {
                foreach (var item in lista)
                {
                    if (!String.IsNullOrEmpty(item.ano) && item.flagFixa != "V")
                    {
                        var OTituloDespesaBL = new ContasAPagarBL();

                        var idCentroCusto = 1;//this.getCentroCusto(item.CentroCusto);

                        var valorTotal = Decimal.Round(UtilNumber.toDecimal(item.valor), 2);

                        var listOTituloDespesa = OTituloDespesaBL.listar("").Where(x => x.idCentroCusto == idCentroCusto && x.descricao == item.descricao && x.valorTotal == valorTotal).ToList();

                        if (listOTituloDespesa.Count > 0)
                        {
                            foreach (var OTituloDespesa in listOTituloDespesa)
                            {
                                OTituloDespesaBL.atualizar(OTituloDespesa.id, "flagFixa", (item.flagFixa != "V") ? "S" : "N");
                            }
                        }
                    }
                }
            }

            return(View());
        }