Exemplo n.º 1
0
        public void Consultar_Situacao_NFe(IList <Dados_Arquivo_NFe> ilNotas)
        {
            foreach (Dados_Arquivo_NFe daNFe in ilNotas)
            {
                //-- Busca informações no WebService
                CompSoft.NFe.TrataWebService.NFeWebService wb_NFe = new CompSoft.NFe.TrataWebService.NFeWebService();
                XmlDocument doc             = wb_NFe.Consulta_NFe(daNFe);
                string      sStatus_Retorno = doc.GetElementsByTagName("cStat")[0].InnerText;

                StringBuilder sb = new StringBuilder();
                sb.Append("update notas_fiscais_lotes set ");
                sb.AppendFormat("   codigo_mensagem_retorno_nfe = {0}", sStatus_Retorno);
                if (sStatus_Retorno == "100" || sStatus_Retorno == "101" || sStatus_Retorno == "110")
                {
                    //-- Atualiza flag de NF-e Exportada.
                    SQL.Execute(string.Format("update notas_fiscais set exportacao_Nfe = 1, nfe_protocolo = '{1}', nfe_protocolo_data = '{2}' where nota_fiscal = {0}"
                                              , daNFe.Nota_Fiscal
                                              , doc.GetElementsByTagName("nProt")[0].InnerText
                                              , doc.GetElementsByTagName("dhRecbto")[0].InnerText.Replace("T", " ").Replace("-", "").Substring(0, 17)));
                }
                sb.AppendFormat("   where nota_fiscal_lote = {0}", daNFe.Cod_Nota_Fiscal_Lote);

                SQL.ExecuteNonQuery(sb.ToString());
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //-- Envia nota para o ambiente de homologação
            CompSoft.NFe.TrataWebService.NFeWebService f = new CompSoft.NFe.TrataWebService.NFeWebService();

            /*
             * IList<int> iNFe = new List<int>();
             * //iNFe.Add(4083);
             * iNFe.Add(4085);
             * iNFe.Add(4090);
             *
             * //-- Gera dados da NF-e
             * ERP.NFe.GerarDadosNFe dados = new ERP.NFe.GerarDadosNFe();
             * dados.Gerar_Dados_NFe(iNFe);
             *
             * //-- Gera arquivo XML das notas selecionadas.
             * ERP.NFe.XML_NFe nfe = new ERP.NFe.XML_NFe(@"c:\temp", dados.DataSet_NFe);
             * nfe.Gerar_XML_NFe();
             *
             * CompSoft.NFe.ValidadorXMLClass v = new CompSoft.NFe.ValidadorXMLClass();
             *
             * foreach (string sFile in nfe.Arquivos_Gerados)
             * {
             *  CompSoft.NFe.AssinaXML a = new CompSoft.NFe.AssinaXML();
             *  if (a.AssinarArquivoXML(sFile, "infNFe"))
             *  {
             *      //-- Valida XML
             *      v.ValidarXML(sFile, @"F:\NFe\Schemas\nfe_v1.10.xsd");
             *      if (v.Retorno != CompSoft.NFe.ValidadorXMLClass.Tipo_Retorno_Validacao.Sucesso)
             *          MessageBox.Show(v.RetornoString);
             *  }
             *  else
             *      MessageBox.Show("Impossivel assinar");
             * }
             *
             * //-- Gera lote.
             * //nfe.Gerar_XML_Lote_NFe();
             *
             * //-- Consulta Status
             * MessageBox.Show(f.Status_WebService("SP").ToString());
             *
             * System.Xml.XmlDocument xml = f.Enviar_LoteNFe("SP", nfe.Arquivos_Gerados[0]);
             *
             * System.Xml.XmlDocument xml_Ret = f.Resultado_Processamento_NFe("SP", xml.GetElementsByTagName("nRec")[0].InnerText);
             *
             * f.Salva_XML_Envio_Cliente(nfe.Arquivos_Gerados[0], xml_Ret);
             * MessageBox.Show("fim");
             */
            //f.Consulta_NFe("35090602640575000285550000000003220000040854", CompSoft.NFe.Ambientes.Homologacao, "SP");

            //f.Consulta_Cadastro_Cliente("SP", "SP", "114776266112", "62461140000117");

            /*
             * ERP.Reports.rDanfe r = new ERP.Reports.rDanfe(dados.DataSet_NFe);
             * r.ShowPreviewDialog();
             */
        }
Exemplo n.º 3
0
        public void Cancelar_NFe(IList <Dados_Arquivo_NFe> ilNotas)
        {
            CompSoft.Tools.frmWait f = new CompSoft.Tools.frmWait("Aguarde, cancelando NF-e no SEFAZ.", true, ilNotas.Count);

            foreach (Dados_Arquivo_NFe daNFe in ilNotas)
            {
                //-- Busca informações no WebService
                CompSoft.NFe.TrataWebService.NFeWebService wb_NFe = new CompSoft.NFe.TrataWebService.NFeWebService();
                XmlDocument doc = wb_NFe.Cancelar_NFe(daNFe);

                StringBuilder sb = new StringBuilder(300);

                //-- Verifica se a mensagem é de confirmação do cancelamento da NF-e
                if (Convert.ToInt32(doc.GetElementsByTagName("cStat")[0].InnerText) == 101)
                {
                    sb.Append("update notas_fiscais_lotes set ");
                    sb.AppendFormat("     codigo_mensagem_retorno_nfe = {0}", doc.GetElementsByTagName("cStat")[0].InnerText);
                    sb.AppendFormat("   , protocolo_cancelamento_nfe = '{0}'", doc.GetElementsByTagName("nProt")[0].InnerText);
                    sb.AppendFormat("   , data_cancelamento_Nfe = '{0}'", doc.GetElementsByTagName("dhRecbto")[0].InnerText.Replace("T", " ").Replace("-", "").Substring(0, 17));
                    sb.AppendFormat("   where nota_fiscal_lote = {0}", daNFe.Cod_Nota_Fiscal_Lote);
                    SQL.ExecuteNonQuery(sb.ToString());

                    sb.Clear();
                    sb.AppendFormat("update notas_fiscais set cancelada = 1 where nota_fiscal = {0}", daNFe.Nota_Fiscal);
                    SQL.ExecuteNonQuery(sb.ToString());

                    ERP.NFe.Enviar_XML_Email envMail_Nfe;
                    envMail_Nfe.Cancelar_NF(daNFe, doc.GetElementsByTagName("nProt")[0].InnerText);
                }
                else
                {
                    int iStatusExiste = Convert.ToInt32(SQL.ExecuteScalar(string.Format("SELECT COUNT(*) FROM MENSAGENS_RETORNO_NFE WHERE CODIGO_MENSAGEM_RETORNO = {0}", doc.GetElementsByTagName("cStat")[1].InnerText)));

                    if (iStatusExiste == 0)
                    {
                        string sQuery = string.Format(@"insert MENSAGENS_RETORNO_NFE values({0}, '{1}')"
                                                      , doc.GetElementsByTagName("cStat")[1].InnerText
                                                      , doc.GetElementsByTagName("xMotivo")[1].InnerText.Replace("'", " "));

                        SQL.ExecuteNonQuery(sQuery);
                    }

                    sb.Append("update notas_fiscais_lotes set ");
                    sb.AppendFormat("     codigo_mensagem_retorno_nfe = {0}", doc.GetElementsByTagName("cStat")[1].InnerText);
                    sb.AppendFormat("   where nota_fiscal_lote = {0}", daNFe.Cod_Nota_Fiscal_Lote);
                    SQL.ExecuteNonQuery(sb.ToString());
                }

                f.Atual_Progresso++;
            }

            f.Close();
            f.Dispose();
        }