private void btnBuscaRetorno_Click(object sender, EventArgs e) { frmStatusEnvioNfs objfrmStatus = null; try { if (belPesq.lResultPesquisa != null) { List<belPesquisaNotas> objSelecionadas = belPesq.lResultPesquisa.Where(c => c.bSeleciona).ToList<belPesquisaNotas>(); List<belPesquisaNotas> objSelect = objSelecionadas.Where(c => c.bDenegada == false && c.bCancelado == false).ToList<belPesquisaNotas>(); if (objSelect.Count() == 0) { KryptonMessageBox.Show("Nenhuma nota Válida foi Selecionada", Mensagens.MSG_Aviso, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (objSelect.Count == 1) { if (Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.DSF) { belPesquisaNotas objPesquisa = new belPesquisaNotas(objSelect.FirstOrDefault().sRECIBO_NF); bsNotas.DataSource = objPesquisa.lResultPesquisa; belCarregaDadosRPS objCarregarNotasLote = new belCarregaDadosRPS(objPesquisa.lResultPesquisa, objPesquisa.lResultPesquisa.FirstOrDefault().sRECIBO_NF); belEnviarNFSeWS objEnvio = new belEnviarNFSeWS(objCarregarNotasLote); string sNumeroLote = objCarregarNotasLote.objLoteEnvio.cabec.NumeroLote.ToString(); KryptonMessageBox.Show(objEnvio.BuscaRetorno(sNumeroLote), Mensagens.MSG_Aviso, MessageBoxButtons.OK, MessageBoxIcon.Information); PesquisaNotas(); } else { belPrestador objbelPrestador = new belPrestador(); belRecepcao objBelRecepcao = new belRecepcao(); objBelRecepcao.Protocolo = objBelRecepcao.BuscaNumProtocolo(objSelect[0].sCD_NFSEQ); objfrmStatus = new frmStatusEnvioNfs(); objfrmStatus.Show(); objfrmStatus.Refresh(); string sMsgErro = objBelRecepcao.BuscaRetorno(objbelPrestador.RettcIdentificacaoPrestador(objSelect[0].sCD_NFSEQ), objfrmStatus.lblMsg, objfrmStatus.progressBarStatus); if (objBelRecepcao.sCodigoRetorno.Equals("E4")) { objfrmStatus.Close(); KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine + Environment.NewLine + "IMPORTANTE: Tente Buscar Retorno da NFs-e, pois o serviço do WebService está demorando para responder. ", Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (objBelRecepcao.objListaNfseRetorno.Count > 0) { objfrmStatus.lblMsg.Text = "Alterando Status da Nota..."; objfrmStatus.lblMsg.Refresh(); objBelRecepcao.AlteraStatusDaNota(objBelRecepcao.objListaNfseRetorno); objfrmStatus.Close(); objBelRecepcao.VerificaNotasParaCancelar(objBelRecepcao.objListaNfseRetorno); KryptonMessageBox.Show(null, objBelRecepcao.MontaMsgDeRetornoParaCliente(), Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); //EnviaEmail(objBelRecepcao.objListaNfseRetorno); } else { objBelRecepcao.LimpaRecibo(); objfrmStatus.Close(); KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine, Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); } PesquisaNotas(); VerificaGeneratorLote(); } } else { KryptonMessageBox.Show("Selecione apenas uma Nota para consultar o lote", Mensagens.MSG_Aviso, MessageBoxButtons.OK, MessageBoxIcon.Information); PesquisaNotas(); } } } catch (Exception ex) { if (objfrmStatus != null) { objfrmStatus.Close(); } VerificaGeneratorLote(); new HLPexception(ex); } }
public tcLoteRps BuscaDadosNFes(List<belPesquisaNotas> objListaNotas) { try { tcLoteRps objLoteRps = new tcLoteRps(); objLoteRps.Rps = new List<TcRps>(); foreach (belPesquisaNotas Nota in objListaNotas) { TcRps objTcRps = new TcRps(); #region IdentificacaoRps - TcIdentificacaoRps beltcIdentificacaoRps objbeltcIdentificacaoRps = new beltcIdentificacaoRps(); objTcRps.InfRps = new TcInfRps(); objTcRps.InfRps.DataEmissao = daoUtil.GetDateServidor(); objTcRps.InfRps.Status = 1;//Normal; DataTable dt = BuscaDadosNota(Nota.sCD_NFSEQ); foreach (DataRow dr in dt.Rows) { objTcRps.InfRps.NaturezaOperacao = Convert.ToInt16(dr["cd_natureza_oper_nfse"].ToString()); objTcRps.InfRps.OptanteSimplesNacional = (dr["st_simples"].ToString().Equals("S") ? 1 : 2); objTcRps.InfRps.IncentivadorCultural = (dr["st_insentivador_cultural"].ToString().Equals("S") ? 1 : 2); if (objTcRps.InfRps.OptanteSimplesNacional == 1) { objTcRps.InfRps.RegimeEspecialTributacao = Convert.ToInt16(dr["RegimeEspecialTributacao"].ToString()); } else { objTcRps.InfRps.RegimeEspecialTributacao = 0; } } objTcRps.InfRps.IdentificacaoRps = objbeltcIdentificacaoRps.BuscatcIdentificacaoRps(Nota.sCD_NFSEQ); #endregion #region Servico - TcDadosServico belServico objbelServico = new belServico(); objTcRps.InfRps.Servico = objbelServico.RetornaDadosServico(Nota.sCD_NFSEQ, objTcRps.InfRps.NaturezaOperacao); #endregion #region Prestador - tcIdentificacaoPrestador belPrestador objbelPrestador = new belPrestador(); objTcRps.InfRps.Prestador = objbelPrestador.RettcIdentificacaoPrestador(Nota.sCD_NFSEQ); objLoteRps.Cnpj = objTcRps.InfRps.Prestador.Cnpj; objLoteRps.InscricaoMunicipal = objTcRps.InfRps.Prestador.InscricaoMunicipal; #endregion #region Tomador - TcDadosTomador belTomador objbelTomador = new belTomador(); objTcRps.InfRps.Tomador = objbelTomador.RettcDadosTomador(Nota.sCD_NFSEQ); #endregion #region ConstrucaoCivil - TcDadosContrucaoCivil - Tratado na Visualização da Nota if (Acesso.NM_EMPRESA.Equals("AENGE")) { belConstrucaoCivil objbelConstrucaoCivil = new belConstrucaoCivil(); objTcRps.InfRps.ConstrucaoCivil = objbelConstrucaoCivil.RettcDadosConstrucaoCivil(Nota.sCD_NFSEQ); } #endregion objLoteRps.Rps.Add(objTcRps); } daoUtil objdaoUtil = new daoUtil(); objLoteRps.NumeroLote = objdaoUtil.RetornaProximoValorGenerator("GEN_LOTE_NFES", 15); objLoteRps.QuantidadeRps = objLoteRps.Rps.Count; return objLoteRps; } catch (Exception ex) { throw ex; } }