Example #1
0
        /// <summary>
        /// Busca Retorno do Web Service SCAN
        /// </summary>
        /// <returns></returns>
        public string buscaRetornoSCAN(string UF_Empresa)
        {
            string sCabec = NfeCabecMsg();
            string sDados = consultaNFe();
            AssinaNFeXml bc = new AssinaNFeXml();
            string xret = string.Empty;
            try
            {
                if (_tpamb == 2)
                {
                    HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.NfeConsulta2 ws2 = new HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.NfeConsulta2();
                    HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.nfeCabecMsg cabec = new HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.nfeCabecMsg();

                    cabec.versaoDados = _versaodados;
                    belUF objUf = new belUF();
                    cabec.cUF = objUf.RetornaCUF(UF_Empresa);
                    ws2.nfeCabecMsgValue = cabec;
                    ws2.ClientCertificates.Add(bc.BuscaNome(""));

                    XmlDataDocument xmlConsulta = new XmlDataDocument();
                    xmlConsulta.LoadXml(sDados);
                    XmlNode xNodeConsulta = xmlConsulta.DocumentElement;

                    xret = ws2.nfeConsultaNF2(xNodeConsulta).OuterXml;
                }
                else
                {
                    HLP.WebService.v2_SCAN_Producao_NFeConsulta.NfeConsulta2 ws2 = new HLP.WebService.v2_SCAN_Producao_NFeConsulta.NfeConsulta2();
                    HLP.WebService.v2_SCAN_Producao_NFeConsulta.nfeCabecMsg cabec = new HLP.WebService.v2_SCAN_Producao_NFeConsulta.nfeCabecMsg();

                    cabec.versaoDados = _versaodados;
                    belUF objUf = new belUF();
                    cabec.cUF = objUf.RetornaCUF(UF_Empresa);
                    ws2.nfeCabecMsgValue = cabec;
                    ws2.ClientCertificates.Add(bc.BuscaNome(""));

                    XmlDataDocument xmlConsulta = new XmlDataDocument();
                    xmlConsulta.LoadXml(sDados);
                    XmlNode xNodeConsulta = xmlConsulta.DocumentElement;

                    xret = ws2.nfeConsultaNF2(xNodeConsulta).OuterXml;
                }
                return xret;
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void btnInutilizar_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            try
            {


                if (txtNNFini.Text == "")
                {
                    KryptonMessageBox.Show("Número Inicial Não Preenchido!", "A T E N Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                }
                else if (txtNNFfim.Text == "")
                {
                    KryptonMessageBox.Show("Número Final Não Preenchido!", "A T E N Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (txtXjust.Text == "")
                {
                    KryptonMessageBox.Show("Justificativa Não Preenchido!", "A T E N Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                }
                else if (txtXjust.Text.Length < 15)
                {
                    KryptonMessageBox.Show("Justificativa Não Preenchido!", "A T E N Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    retInfempresa();
                    AssinaNFeXml assina = new AssinaNFeXml();
                    X509Certificate2 cert = assina.BuscaNome("");
                    belNfeInutilizacao objinutilizacao = new belNfeInutilizacao(_tpamp, _cuf, _cnpj, _mod, cbxSerie.Text, txtXjust.Text,
                                                                                txtNNFini.Text, txtNNFfim.Text, cert, _uf_empresa, belStatic.bModoSCAN, belStatic.iStatusAtualSistema);


                    xmldoc.LoadXml(objinutilizacao.RetWs);
                    Globais LeRegWin = new Globais();

                    if (xmldoc.GetElementsByTagName("cStat")[0].InnerText == "102")
                    {
                        KryptonMessageBox.Show(null, "Tipo Ambiente: " + xmldoc.GetElementsByTagName("tpAmb")[0].InnerText + Environment.NewLine +
                                              "Status: " + xmldoc.GetElementsByTagName("cStat")[0].InnerText + Environment.NewLine +
                                              "Descrição: " + xmldoc.GetElementsByTagName("xMotivo")[0].InnerText + Environment.NewLine +
                                              "Ano: " + xmldoc.GetElementsByTagName("ano")[0].InnerText + Environment.NewLine +
                                              "Modelo da NF-e: " + xmldoc.GetElementsByTagName("mod")[0].InnerText + Environment.NewLine +
                                              "Serie da NF-e: " + xmldoc.GetElementsByTagName("serie")[0].InnerText + Environment.NewLine +
                                              "Número Inicial: " + xmldoc.GetElementsByTagName("nNFIni")[0].InnerText + Environment.NewLine +
                                              "Número Final: " + xmldoc.GetElementsByTagName("nNFFin")[0].InnerText + Environment.NewLine +
                                              "Data do Recbto: " + xmldoc.GetElementsByTagName("dhRecbto")[0].InnerText.Replace('T', ' ') + Environment.NewLine +
                                              "Número do Protocolo: " + xmldoc.GetElementsByTagName("nProt")[0].InnerText, "INUTILIZAÇÃO DE NUMERACAO",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Information);
                        xmldoc.Save(belStaticPastas.PROTOCOLOS + "\\" + xmldoc.GetElementsByTagName("nProt")[0].InnerText + "_inu.xml");
                    }
                    else
                    {
                        KryptonMessageBox.Show(null, "Tipo Ambiente: " + xmldoc.GetElementsByTagName("tpAmb")[0].InnerText + Environment.NewLine +
                                              "Status: " + xmldoc.GetElementsByTagName("cStat")[0].InnerText + Environment.NewLine +
                                              "Descrição: " + xmldoc.GetElementsByTagName("xMotivo")[0].InnerText,
                                              "INUTILIZAÇÃO DE NUMERACAO",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Information);
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {

                KryptonMessageBox.Show(ex.Message);
            }

        }
Example #3
0
        private void btnCanc_Click(object sender, EventArgs e)
        {
            Globais pega = new Globais();
            //Danner - o.s. 23851 - 19/11/2009
            AssinaNFeXml bc = new AssinaNFeXml();
            X509Certificate2 cert = new X509Certificate2();
            cert = bc.BuscaNome("");
            //Fim - Danner - o.s. 23851 - 19/11/2009
            try
            {

                if (txtJust.Text.Length < 15)
                {
                    KryptonMessageBox.Show(null, "Justificativa Insuficiente, Mínimo de 15 Caracteres", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    txtJust.Focus();
                }
                else
                {
                    belNfeCancelamento nfecanc = new belNfeCancelamento("1.02", "2", "CANCELAR", txtJust.Text, "1.07", _emp, _snotacanc[0].ToString(), cert, UF_Empresa, belStatic.bModoSCAN, belStatic.iStatusAtualSistema);//Danner - o.s. 23984 - 07/01/2010
                    XmlDocument xmlret = new XmlDocument();
                    xmlret.LoadXml(nfecanc.Sret);
                    string cstat = xmlret.GetElementsByTagName("cStat")[0].InnerText;
                    string xmotivo = xmlret.GetElementsByTagName("xMotivo")[0].InnerText;
                    if (cstat != "101")
                    {
                        throw new Exception("Erro " + cstat + ": " + xmotivo);
                    }
                    else
                    {
                        string nprot = xmlret.GetElementsByTagName("nProt")[0].InnerText;
                        string chnfe = xmlret.GetElementsByTagName("chNFe")[0].InnerText;


                        StringBuilder sSql = new StringBuilder();

                        sSql.Append("update nf ");
                        sSql.Append("set cd_recibocanc = '");
                        sSql.Append(nprot);
                        sSql.Append("' ");
                        sSql.Append("where ");
                        sSql.Append("cd_empresa = '");
                        sSql.Append(_emp);
                        sSql.Append("' ");
                        sSql.Append("and ");
                        sSql.Append("cd_nfseq = '");
                        sSql.Append(_snotacanc[0]);
                        sSql.Append("'");

                        using (FbCommand cmdUpdate = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                        {
                            cx.Open_Conexao();
                            cmdUpdate.ExecuteNonQuery();
                        }

                        geraNFeCanc(chnfe, pega);
                        KryptonMessageBox.Show(null, "Nota Cancelada com Sucesso", "Cancelamento", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception x)
            {
                throw new Exception(x.Message + " - Nota não foi cancelada com sucesso!");
            }
            finally { cx.Close_Conexao(); }

        }
Example #4
0
        private void btnCancelamento_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> sNotacanc = new List<string>();
                frmCancelamentoNfs objfrmCanc = new frmCancelamentoNfs();
                daoCancelamento objdaoCanc = new daoCancelamento();
                belCancelamentoNFse objbelCance = new belCancelamentoNFse();
                cx.Open_Conexao();

                for (int i = 0; i < dgvNF.RowCount; i++)
                {
                    if ((((dgvNF["cd_recibocanc", i].Value.ToString() == "") && (dgvNF["ASSINANF", i].Value != null) && dgvNF["ASSINANF", i].Value.ToString().Equals("True")) && (dgvNF["ST_NFE", i].Value.ToString() != "0")))//&& (dgvNF["CANCELADA", i].Value.ToString() != "0")))
                    {
                        sNotacanc.Add((string)dgvNF["CD_NFSEQ", i].Value);
                    }
                }
                if (sNotacanc.Count == 1)
                {
                    objfrmCanc.ShowDialog();
                    AssinaNFeXml Assinatura = new AssinaNFeXml();
                    X509Certificate2 cert = Assinatura.BuscaNome("");
                    if (!ValidaCertificado(cert))
                    {
                        throw new Exception("Certificado não Selecionado!!");
                    }

                    TcPedidoCancelamento objTcPediCanc = objdaoCanc.BuscaDadosParaCancelamento(cx.get_Conexao(), objfrmCanc.sErro, sNotacanc[0]);
                    string sXmlRet = objbelCance.CancelaNfes(objTcPediCanc, cert); //Cancela a Nota
                    string sMsgRet = objbelCance.ConfiguraMsgRetornoCancelamento(sXmlRet); // Configura Msg e verifica se a nota foi cancelada
                    if (objbelCance.bNotaCancelada)
                    {
                        objdaoCanc.CancelarNFseSistema(objTcPediCanc.InfPedidoCancelamento.IdentificacaoNfse.Numero, cx.get_Conexao()); //Update no cd_recibocanc
                    }
                    KryptonMessageBox.Show(null, sMsgRet, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (sNotacanc.Count > 1)
                {
                    KryptonMessageBox.Show(null, "Não é possível cancelar varias notas de uma só vez.!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    KryptonMessageBox.Show(null, "Nenhuma Nota válida foi selecionada para o Cancelamento.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                KryptonMessageBox.Show(null, string.Format(Msg_Padrao.CException, Environment.NewLine) + (ex.InnerException != null ? ex.InnerException.Message : ex.Message).ToString(), "AVISO ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally { cx.Close_Conexao(); }
        }
Example #5
0
        private void btnBuscaRetorno_Click(object sender, EventArgs e)
        {
            frmStatusEnvioNfs objfrmStatus = null;
            try
            {
                #region Busca Notas Selecionadas na Grid
                string sNfCancelada = string.Empty;
                sListaNotas = new List<string>();
                for (int i = 0; i < dgvNF.RowCount; i++)
                {
                    if (((dgvNF["ASSINANF", i].Value != null) && (dgvNF["ASSINANF", i].Value.ToString().Equals("True"))) && ((dgvNF["CANCELADA", i].Value == null) || (dgvNF["CANCELADA", i].Value.ToString() == "0"))) //Danner - o.s. SEM - 17/12/2009
                    {
                        sListaNotas.Add((string)dgvNF["CD_NFSEQ", i].Value);
                    }
                    if ((dgvNF["CANCELADA", i].Value != null) && (dgvNF["CANCELADA", i].Value.ToString() == "1"))
                    {
                        sNfCancelada += "Nota Fiscal " + dgvNF["CD_NOTAFIS", i].Value.ToString() + " - Esta Cancelada e não é Permitido o Reenvio da mesma Nota!" + Environment.NewLine + Environment.NewLine;
                    }
                }

                if (sListaNotas.Count == 0)
                {
                    KryptonMessageBox.Show("Nenhuma nota Valida foi Selecionada!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (sNfCancelada != "")
                    {
                        KryptonMessageBox.Show(sNfCancelada, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return;
                }

                #endregion

                if (sListaNotas.Count == 1)
                {
                    belRecepcao objBelRecepcao = new belRecepcao();
                    daoPrestador objdaoPrestador = new daoPrestador();
                    daoRecepcao objdaoRecepcao = new daoRecepcao();
                    //Buscar Protocolo no banco
                    objBelRecepcao.Protocolo = objdaoRecepcao.BuscaNumProtocolo(sListaNotas[0]);

                    //Busca Retorno do lote
                    AssinaNFeXml Assinatura = new AssinaNFeXml();
                    X509Certificate2 cert = Assinatura.BuscaNome("");
                    if (!ValidaCertificado(cert))
                    {
                        throw new Exception("Certificado não Selecionado!!");
                    }
                    else
                    {
                        objBelRecepcao.cert = cert;
                    }

                    objfrmStatus = new frmStatusEnvioNfs();
                    objfrmStatus.Show();
                    objfrmStatus.Refresh();
                    string sMsgErro = objBelRecepcao.BuscaRetorno(objdaoPrestador.RettcIdentificacaoPrestador(cx.get_Conexao(), sListaNotas[0]), objfrmStatus.lblMsg, objfrmStatus.progressBarStatus);

                    if (objBelRecepcao.sCodigoRetorno.Equals("E4"))
                    {
                        objfrmStatus.Close();
                        KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine + Environment.NewLine + "IMPORTANTE: Tente Buscar Retorno da NFse pois o serviço do Web service está demorando para responder; ", "MENSAGEM DE RETORNO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (objBelRecepcao.objListaNfseRetorno.Count > 0) //Lote Enviado
                    {
                        objfrmStatus.lblMsg.Text = "Alterando Status da Nota para Enviada!!";
                        objfrmStatus.lblMsg.Refresh();
                        objdaoRecepcao.AlteraStatusDaNota(objBelRecepcao.objListaNfseRetorno);
                        objdaoRecepcao.VerificaNotasParaCancelar(objBelRecepcao.objListaNfseRetorno);
                        for (int i = 0; i < dgvNF.RowCount; i++)
                        {
                            //CD_NFSEQ
                            int ienviado = objBelRecepcao.objListaNfseRetorno.Count(lote => lote.IdentificacaoRps.Nfseq == dgvNF["CD_NFSEQ", i].Value.ToString());
                            if (ienviado > 0)
                            {
                                dgvNF["ST_NFE", i].Value = true;
                            }
                        }
                        KryptonMessageBox.Show(null, objBelRecepcao.MontaMsgDeRetornoParaCliente(), "MENSAGEM DE RETORNO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        EnviaEmail(objBelRecepcao.objListaNfseRetorno);
                    }
                    else
                    {
                        objdaoRecepcao.LimpaRecibo();
                        objfrmStatus.Close();
                        KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine, "MENSAGEM DE RETORNO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    objfrmStatus.Close();
                }
                else
                {
                    throw new Exception("Selecione apenas uma Nota e o lote ref. a éssa nota será consultado!!");
                }
                VerificaGeneratorLote();
                PopulaDataGridView();
            }
            catch (Exception ex)
            {
                if (objfrmStatus != null)
                {
                    objfrmStatus.Close();
                }
                KryptonMessageBox.Show(null, string.Format(Msg_Padrao.CException, Environment.NewLine) + (ex.InnerException != null ? ex.InnerException.Message : ex.Message).ToString(), "AVISO ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally { cx.Close_Conexao(); }
        }
Example #6
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            frmStatusEnvioNfs objfrmStatus = null;
            try
            {
                Globais objGlobais = new Globais();
                if (objGlobais.LeRegConfig("GrupoServico").Equals(""))
                {
                    throw new Exception("Parametrize o Grupo Padrão de Faturamento (Serviço) no Config do Sistema antes de Enviar Notas");
                }

                for (int i = 0; i < dgvNF.RowCount; i++)
                {
                    if (dgvNF["ASSINANF", i].Value != null)
                    {
                        if (dgvNF["ASSINANF", i].Value.ToString().Equals("True"))
                        {
                            if (VerificaCampoReciboPreenchido(belStatic.codEmpresaNFe, dgvNF["CD_NFSEQ", i].Value.ToString()) != "")
                            {
                                throw new Exception("A Nota de Sequencia = " + dgvNF["CD_NFSEQ", i].Value.ToString() + " Já tem um retorno Salvo no Banco de Dados, tente Buscar Retorno");
                            }
                        }
                    }
                }
                #region Busca Notas Selecionadas na Grid
                string sNfCancelada = string.Empty;
                sListaNotas = new List<string>();
                for (int i = 0; i < dgvNF.RowCount; i++)
                {
                    if (((dgvNF["ASSINANF", i].Value != null) && (dgvNF["ASSINANF", i].Value.ToString().Equals("True"))) && ((dgvNF["CANCELADA", i].Value == null) || (dgvNF["CANCELADA", i].Value.ToString() == "0"))) //Danner - o.s. SEM - 17/12/2009
                    {
                        sListaNotas.Add((string)dgvNF["CD_NFSEQ", i].Value);
                    }
                    if ((dgvNF["CANCELADA", i].Value != null) && (dgvNF["CANCELADA", i].Value.ToString() == "1"))
                    {
                        sNfCancelada += "Nota Fiscal " + dgvNF["CD_NOTAFIS", i].Value.ToString() + " - Esta Cancelada e não é Permitido o Reenvio da mesma Nota!" + Environment.NewLine + Environment.NewLine;
                    }
                }

                if (sListaNotas.Count == 0)
                {
                    KryptonMessageBox.Show("Nenhuma nota Valida foi Selecionada!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (sNfCancelada != "")
                    {
                        KryptonMessageBox.Show(sNfCancelada, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return;
                }

                #endregion
                daoLoteRps objdaoLoteRps = new daoLoteRps();

                if (ValidaSeqNoBanco())
                {
                    tcLoteRps objLoteRps = objdaoLoteRps.BuscaDadosNFes(sListaNotas);
                    //Chamar Form para visualizar;
                    frmVisualizaNfs objFrmVisualiza = new frmVisualizaNfs(objLoteRps);
                    objFrmVisualiza.ShowDialog();
                    if (objFrmVisualiza.bCancela)
                    {
                        MessageBoxIcon _msgIcon = MessageBoxIcon.Information;
                        throw new Exception("Envio da(s) Nota(s) Cancelado");
                    }

                    AssinaNFeXml Assinatura = new AssinaNFeXml();
                    X509Certificate2 cert = Assinatura.BuscaNome("");
                    if (!ValidaCertificado(cert))
                    {
                        throw new Exception("Certificado não Selecionado!!");
                    }
                    objfrmStatus = new frmStatusEnvioNfs();
                    objfrmStatus.Show();
                    objfrmStatus.lblMsg.Text = "Montando XML de Acordo com os dados inseridos!!";
                    objfrmStatus.lblMsg.Refresh();
                    objfrmStatus.Refresh();

                    HLP.bel.NFes.belCreateXml objCreateXml = new belCreateXml(cert);
                    objCreateXml.GerarAqruivoXml(objFrmVisualiza.objLoteRpsAlter);

                    objfrmStatus.lblMsg.Text = "Enviando Lote para o Webservice!!";
                    objfrmStatus.lblMsg.Refresh();

                    //Envia Lote
                    belRecepcao objBelRecepcao = new belRecepcao(objCreateXml.sXmlLote, cert, objFrmVisualiza.objLoteRpsAlter);
                    if (objBelRecepcao.sMsgTransmissao != "")
                    {
                        throw new Exception(objBelRecepcao.sMsgTransmissao);
                    }
                    daoRecepcao objdaoRecepcao = new daoRecepcao(objBelRecepcao.Protocolo, objFrmVisualiza.objLoteRpsAlter);
                    objfrmStatus.lblMsg.Text = "Gravando recibo na base de dados!!";
                    objfrmStatus.lblMsg.Refresh();
                    objdaoRecepcao.GravaRecibo();
                    string sMsgErro = objBelRecepcao.BuscaRetorno(objFrmVisualiza.objLoteRpsAlter.Rps[0].InfRps.Prestador, objfrmStatus.lblMsg, objfrmStatus.progressBarStatus);

                    if (objBelRecepcao.sCodigoRetorno.Equals("E4"))
                    {
                        objfrmStatus.Close();
                        KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine + Environment.NewLine + "IMPORTANTE: Tente Buscar Retorno da NFse pois o serviço do Web service está demorando para responder; ", "MENSAGEM DE RETORNO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (objBelRecepcao.objListaNfseRetorno.Count > 0) //Lote Enviado
                    {
                        objfrmStatus.lblMsg.Text = "Alterando Status da Nota para Enviada!!";
                        objfrmStatus.lblMsg.Refresh();
                        objdaoRecepcao.AlteraStatusDaNota(objBelRecepcao.objListaNfseRetorno);
                        objfrmStatus.Close();
                        objdaoRecepcao.VerificaNotasParaCancelar(objBelRecepcao.objListaNfseRetorno);

                        for (int i = 0; i < dgvNF.RowCount; i++)
                        {
                            //CD_NFSEQ
                            int ienviado = objBelRecepcao.objListaNfseRetorno.Count(lote => lote.IdentificacaoRps.Nfseq == dgvNF["CD_NFSEQ", i].Value.ToString());
                            if (ienviado > 0)
                            {
                                dgvNF["ST_NFE", i].Value = true;
                            }
                        }
                        KryptonMessageBox.Show(null, objBelRecepcao.MontaMsgDeRetornoParaCliente(), "MENSAGEM DE RETORNO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        EnviaEmail(objBelRecepcao.objListaNfseRetorno);
                    }
                    else
                    {
                        objdaoRecepcao.LimpaRecibo(objFrmVisualiza.objLoteRpsAlter);
                        objfrmStatus.Close();
                        KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine, "MENSAGEM DE RETORNO", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }
                }

                VerificaGeneratorLote();
                PopulaDataGridView();
            }
            catch (Exception ex)
            {
                if (objfrmStatus != null)
                {
                    objfrmStatus.Close();
                }
                VerificaGeneratorLote();
                KryptonMessageBox.Show(null, string.Format(Msg_Padrao.CException, Environment.NewLine) + (ex.InnerException != null ? ex.InnerException.Message + Environment.NewLine + ex.Message : ex.Message).ToString(), "AVISO ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally { cx.Close_Conexao(); }
        }
Example #7
0
 private void btnEnvio_Click(object sender, EventArgs e)
 {
     try
     {
         AssinaNFeXml objbuscanome = new AssinaNFeXml();
         cert = new X509Certificate2();
         cert = objbuscanome.BuscaNome("");
         belUtil.ValidaCertificado(cert);
         if ((bsGrid.DataSource as List<belPesquisaCCe>).Where(c => c.bSeleciona).Count() > 0)
         {
             belPesquisaCCe objbelPesqEnvio = (bsGrid.DataSource as List<belPesquisaCCe>).FirstOrDefault(c => c.bSeleciona);
             List<belPesquisaCCe> objListaSelect = (bsGrid.DataSource as List<belPesquisaCCe>).Where(c => c.bSeleciona).ToList();
             daoGeraCCe objDaoGeraCCe = new daoGeraCCe(objListaSelect, cert);
             objDaoGeraCCe.GeraXmlEnvio();
             string sRetorno = daoEnviaCCe.TransmiteLoteCCe(objDaoGeraCCe.sXMLfinal, cert);
             string sMessage = objDaoGeraCCe.AnalisaRetornoEnvio(sRetorno);
             hlpMessageBox.ShowAviso(sMessage);
             CarregaGridView();
         }
     }
     catch (Exception ex)
     {
         new HLPexception(ex.Message, ex);
     }
 }
        private void Inicializacao()
        {
            try
            {
                belStatic.bNotaServico = false;
                version = objfrmPrincipal.GetType().Assembly.GetName().Version;
                HabilitaBotoes(true);
                AssinaNFeXml objbuscanome = new AssinaNFeXml();
                cert = new X509Certificate2();
                cert = objbuscanome.BuscaNome("");

                if (belUtil.ValidaCertificado(cert))
                {

                    belStatic.bModoContingencia = Convert.ToBoolean(LeRegWin.LeRegConfig("AtivaModuloContingencia"));
                    belStatic.bModoSCAN = Convert.ToBoolean(LeRegWin.LeRegConfig("AtivaModuloScan"));
                    belStatic.iSerieSCAN = (belStatic.bModoSCAN == true ? Convert.ToInt32(LeRegWin.LeRegConfig("SerieScan")) : 0);

                    DirectoryInfo info = new DirectoryInfo(belStaticPastas.CBARRAS);
                    LimparPasta(info);
                    if (belUtil.VerificaSeEstaNaHLP())
                    {
                        belStatic.bDentroHlp = true;
                        KryptonMessageBox.Show(null, "VOCÊ ESTÁ TRABALHANDO NA HLP, VERIFIQUE O AMBIENTE DO SISTEMA DA NFE", "CUIDADO, ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        belRegras objbelRegras = new belRegras();
                        objbelRegras.AlteraEmpresaParaHomologacao();
                    }
                    nmEmpresa.Text = belStatic.sNomeEmpresa + " - " + belStatic.codEmpresaNFe;
                    nmStatus.Text = (belStatic.TpAmb == 1 ? "Produção" : "Homologação");

                    this.sVersao = LeRegWin.LeRegConfig("Empresa");
                    CarregaConfiguracoesIniciais(belStatic.codEmpresaNFe);
                    string sTipoImpressao = LeRegWin.LeRegConfig("TipoImpressao");
                    cbxFormDanfe.SelectedIndex = 0;
                    if (sTipoImpressao != "")
                    {
                        cbxFormDanfe.Text = sTipoImpressao;
                    }
                    dtpIni.Text = HLP.Util.Util.GetDateServidor().ToString("dd/MM/yyyy");
                    dtpFim.Text = HLP.Util.Util.GetDateServidor().ToString("dd/MM/yyyy");
                    rbtNaoEnviadas.Checked = true;
                    belStatic.iStatusAtualSistema = 0; // Passa o zero para entrar no método novamente!
                    VerificaStatusSefaz();
                    timerWebServices.Enabled = true; // Ativa a Verificação do Web Service do Estado.                
                    if ((belStatic.iStatusAtualSistema == 1))
                    {
                        VerificaNotasPendentesEnvio();
                    }
                }
                else
                {
                    timerInicializacao.Start();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }