private void VerificaStatusSefaz() { try { InternetCS objVerificaInternet = new InternetCS(); if (objVerificaInternet.Conexao()) { objnfeStatusServicoNF = new belnfeStatusServicoNF("2.00", this.cd_ufnor, cert, Uf_Empresa); string sTempo = string.Empty; if (objnfeStatusServicoNF.Tmed > 1) { sTempo = "Segundos"; } else { sTempo = "Segundo"; } string sMenssagem = string.Format("Status do servidor: {0} - {1} " + " - Layout: {2}", objnfeStatusServicoNF.Cstat, objnfeStatusServicoNF.Xmotivo, objnfeStatusServicoNF.Versao ); if ((objnfeStatusServicoNF.Cstat == 108) || (objnfeStatusServicoNF.Cstat == 109) || (objnfeStatusServicoNF.iTentativasWebServices == 1)) // Serviço do Estado Inoperante { #region Tratamento SCAN if (belStatic.iStatusAtualSistema != 3) { belStatic.iStatusAtualSistema = 3; if (belStatic.bModoSCAN) { KryptonMessageBox.Show(null, "Ocorreu uma Excessão com o Serviço do SEFAZ." + Environment.NewLine + sMenssagem + Environment.NewLine + Environment.NewLine + "O Sistema já está configurado para Enviar Notas no Modo Contingencia SCAN" + Environment.NewLine + Environment.NewLine + "Série SCAN : " + belStatic.iSerieSCAN.ToString(), "I N F O R M A Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information); lblStatusContingencia.Text = "Série SCAN: " + belStatic.iSerieSCAN.ToString(); objfrmPrincipal.sStatusSefaz = "Sistema em Modo de Contingência ( SCAN )"; } else { KryptonMessageBox.Show(null, "Ocorreu uma Excessão com o Serviço do SEFAZ." + Environment.NewLine + sMenssagem + Environment.NewLine + Environment.NewLine + "O Sistema não está Configurado Para Enviar Notas no Modo Contingência SCAN " + Environment.NewLine + "E O GeraXML não será Inicializado!" + Environment.NewLine, "I N F O R M A Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Error); timerWebServices.Enabled = false; frmConfiguracao objfrm = new frmConfiguracao(4); objfrm.ShowDialog(); Inicializacao(); Object sender = new object(); EventArgs e = new EventArgs(); this.frmArquivosXml_Load(sender, e); } } #endregion } else if ((objnfeStatusServicoNF.Cstat == 107)) { if (belStatic.iStatusAtualSistema != 1) { if (belStatic.bModoSCAN == false) { string sMensg = string.Format("Verificação Web Service: {0}{1}" + "Status do servidor: {2}{3}Motivo: {4}", Environment.NewLine, Environment.NewLine, objnfeStatusServicoNF.Cstat, Environment.NewLine, objnfeStatusServicoNF.Xmotivo); KryptonMessageBox.Show(null, sMensg + Environment.NewLine, "I N F O R M A Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information); if (belStatic.iStatusAtualSistema != 0) { Inicializacao(); Object sender = new object(); EventArgs e = new EventArgs(); this.frmArquivosXml_Load(sender, e); } this.objfrmPrincipal.sStatusSefaz = sMenssagem; lblStatusContingencia.Text = ""; VerificaNotasPendentesEnvio(); belStatic.iStatusAtualSistema = 1; } else { belStatic.iStatusAtualSistema = 3; sFormaEmissao = "3"; string sMensg = string.Format("Verificação Web Service. :{0}{1}" + "Status do servidor: {2}{3}Motivo: {4}", Environment.NewLine, Environment.NewLine, objnfeStatusServicoNF.Cstat, Environment.NewLine, objnfeStatusServicoNF.Xmotivo + Environment.NewLine + Environment.NewLine + "Sistema configurado para Emitir NF-e em Contingência SCAN !"); KryptonMessageBox.Show(null, sMensg, "I N F O R M A Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information); this.objfrmPrincipal.sStatusSefaz = sMenssagem; lblStatusContingencia.Text = ""; } } } } else { throw new Exception("A internet parece estar indisponível !"); } } catch (HLPexception hlp) { } catch (Exception ex) { FalhaInternet(ex); } }
/// <summary> /// Utilizado na Classe belGeraXML. /// </summary> /// <param name="sEmp"></param> /// <param name="sSeqs"></param> /// <param name="sNfes"></param> /// <param name="tp_amb"></param> /// <param name="cd_ufnro"></param> /// <param name="sRecibo"></param> /// <param name="xCert"></param> /// <param name="glob"></param> /// <param name="pf"></param> public belBusRetFazenda(string sEmp, List<string> sSeqs, List<string> sNfes, int tp_amb, string cd_ufnro, string sRecibo, X509Certificate2 xCert, Globais glob, string UF_Empresa, bool bModoSCAN) { XNamespace pf = "http://www.portalfiscal.inf.br/nfe"; this.bModoSCAN = bModoSCAN; _emp = sEmp; _seqs = sSeqs; _nfes = sNfes; string qtdeTentativas = glob.LeRegConfig("QtdeTentativas").ToString(); bool parar = false; //Retorno da fazenda com Status de cada NFe do lote. belNfeRetRecepcao objnferetrecepcao = new belNfeRetRecepcao("1.02", tp_amb, sRecibo, "2.00", xCert, bModoSCAN); XmlDocument xret = new XmlDocument(); //Variavel pra sabe se alguma nota possui erro XmlNodeList nodescStat; XmlNodeList nodesxMotivo; //contador de tentativas int countTentativas = 0; for (; ; ) { xret = objnferetrecepcao.Retornaxml(UF_Empresa); nodescStat = xret.GetElementsByTagName("cStat"); nodesxMotivo = xret.GetElementsByTagName("xMotivo"); if (nodescStat[0].InnerText == "105") { //Verifica o status do serviço e faz o calculo de tempo médio para a próxima tentativa do recebimento do retorno da fazenda belnfeStatusServicoNF objstausserv = new belnfeStatusServicoNF("2.00", tp_amb, cd_ufnro, xCert, UF_Empresa); System.Threading.Thread.Sleep((objstausserv.Tmed * 1000) + 3000); //Compara se a quantidade de tentativas dadas é igual ao limite estipuládo na configuração do sistema. if (qtdeTentativas == countTentativas.ToString()) { throw new Exception("Quantidade de Tentativas de Conexão com a secretaria da Fazenta Excedidas " + Environment.NewLine + "Lote foi enviado a fazenda, porem esta em processamento" + Environment.NewLine + "Espere alguns segundos antes de tentar buscar o retorno novamente"); } //Conta tentativa countTentativas++; continue; } else if (nodescStat[0].InnerText != "104") { throw new Exception("Erro " + nodescStat[0].InnerText + " - " + nodesxMotivo[0].InnerText); } else { for (int i = 0; i < sNfes.Count ; i++) { //Variavel que gera a mensagem de resposta _loteres = _loteres + "Nota de número de sequência: " + sSeqs[i] + " - " + nodesxMotivo[i + 1].InnerText + " Cod. " + nodescStat[i + 1].InnerText + Environment.NewLine; if (nodescStat[i + 1].InnerText == "100") { _nfeautorizadas.Add(sSeqs[i]); XmlNode xRetUni = xret.GetElementsByTagName("infProt")[i]; // Diego OS_24777 //Método responsavel por gravar o nProt e chNfe no banco e gerar o xml protocolado. geraProcNFe(sEmp, sSeqs[i], sNfes[i], xret.GetElementsByTagName("chNFe")[i].InnerText, xRetUni["nProt"].InnerText, xret.GetElementsByTagName("protNFe")[i], glob, pf); xret.Save(glob.LeRegConfig("PastaProtocolos").ToString() + "\\" + sRecibo + "-pro-rec.xml"); } else { if (nodescStat[i + 1].InnerText != "105") { LimpaCampoRecibo(_emp, sSeqs[i]); } } parar = true; } } if (parar == true) break; } }
private void btnConsultaServico_Click(object sender, EventArgs e) { try { belnfeStatusServicoNF objnfeStatusServicoNF = new belnfeStatusServicoNF("2.00", this.cd_ufnor, cert, Uf_Empresa); string sTempo = string.Empty; if (objnfeStatusServicoNF.Tmed > 1) { sTempo = "Segundos"; } else { sTempo = "Segundo"; } string sMenssagem = string.Format("Status do Servidor: {0}{1}Descrição: {2}{3}Tempo Médio de Resposta: {4} {5}", objnfeStatusServicoNF.Cstat, Environment.NewLine, objnfeStatusServicoNF.Xmotivo, Environment.NewLine, objnfeStatusServicoNF.Tmed, sTempo); if ((objnfeStatusServicoNF.Cstat == 107)) { KryptonMessageBox.Show(null, sMenssagem, "Status do Servidor da Secretaria da Fazenda", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string sMensagemScan = Environment.NewLine + Environment.NewLine + "Detalhes: " + Environment.NewLine + "O Serviço da Sefaz do Estado de " + Uf_Empresa + " Está Inoperante no momento" + Environment.NewLine + "Para o Envio da NFe." + Environment.NewLine + "O Sistema deverá acessar o Servidor Federal (SCAN)." + Environment.NewLine + "Para que isso seja Possível, será necessário Ativar o Ambiente de SCAN nas Configurações e " + "escolher uma série para a NFe no Intervalo de 900 a 999;" + Environment.NewLine + Environment.NewLine + "Para Ativar o Ambiente de SCAN agora, pressione 'SIM'. Caso contrário, o sistema irá " + "verificar e informar no rodapé do Menu Principal quando o Servidor do Estado já estiver Online"; if (KryptonMessageBox.Show(null, sMenssagem + sMensagemScan, "Status do Servidor da Secretaria da Fazenda", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { frmConfiguracao objfrm = new frmConfiguracao(4); objfrm.MdiParent = objfrmPrincipal; objfrm.Show(); this.Close(); } } } catch (Exception ex) { new HLPexception(ex.Message + Environment.NewLine + "O Teste de Conexão com a Internet Falhou!! " + Environment.NewLine + Environment.NewLine + "O Sistema já está Configurado para Imprimir DANFE em Modo de Contingência." + Environment.NewLine, ex); } }