void GeraXMLtoPDF(HLP.GeraXml.bel.NFe.ClassesSerializadas.NFe_HLP nf)
        {
            try
            {
                NFe_Report objnfReport;
                string     sFilePath = Pastas.Temp + "NFeToReportPDF_{0}.xml";
                sFilePath = string.Format(sFilePath, nf.ide_nNF);

                this.Invoke(new MethodInvoker(delegate()
                {
                    try
                    {
                        if (File.Exists(sFilePath))
                        {
                            File.Delete(sFilePath);
                        }

                        objnfReport = new NFe_Report();
                        objnfReport.Notas.Add(nf);
                        SerializeClassToXml.SerializeClasse <List <NFe_HLP> >(objnfReport.Notas, sFilePath);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public string AnalisaRetornoEnvioCCeCTe(HLP.GeraXml.bel.CTe.Evento.TRetEvento ret, string sNotaFis)
        {
            try
            {
                //string sNota = "";
                if (ret.infEvento.cStat == "135")
                {
                    //sNota = objlItensPesquisa.FirstOrDefault(c => c.CHNFE == ret.infEvento.chCTe).CD_NOTAFIS;
                    int    iQT_ENVIO = objlItensPesquisa.FirstOrDefault(c => c.CHNFE == ret.infEvento.chCTe).QT_ENVIO;
                    string sNR_LANC  = objlItensPesquisa.FirstOrDefault(c => c.CHNFE == ret.infEvento.chCTe).CD_NRLANC;
                    AtualizaContadorCCe(sNR_LANC, iQT_ENVIO);
                    string        sPath      = Pastas.CCe + "\\" + ret.infEvento.chCTe.Substring(2, 4);
                    DirectoryInfo dPastaData = new DirectoryInfo(sPath);
                    if (!dPastaData.Exists)
                    {
                        dPastaData.Create();
                    }
                    sPath = sPath + "\\35140614920065000160570010000011721000029623" + "_ret-cce.xml";
                    SerializeClassToXml.SerializeClasse <HLP.GeraXml.bel.CTe.Evento.TRetEvento>(ret, sPath);
                }

                return(string.Format("CCe do CTe: {0} - '{1}'{2}", sNotaFis, ret.infEvento.xMotivo, Environment.NewLine));
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        public void Salvar(Conexao conexao)
        {
            if (conexao.PROPRIEDADES["dbname"].Split(':')[1] != "")
            {
                string sPath = Util.GetPastaConfiguracao();
                if (sPath == "")
                {
                    throw new Exception("Configure um diretório na rede para salvar as conexões.");
                }
                sPath += "\\SpedConfig.xml";
                ItemConn conn = null;
                if (ConfigConn == null)
                {
                    ConfigConn          = new ModelConexao();
                    ConfigConn.CONEXOES = new List <ItemConn>();
                    conn = new ItemConn();
                    ConfigConn.CONEXOES.Add(conn);
                }
                else
                {
                    if (ConfigConn.CONEXOES.Where(c => c.NAME == conexao.NOME).Count() > 0)
                    {
                        conn = ConfigConn.CONEXOES.FirstOrDefault(c => c.NAME == conexao.NOME);
                    }
                    else
                    {
                        conn = new ItemConn();
                        ConfigConn.CONEXOES.Add(conn);
                    }
                }
                conn.NAME            = conexao.NOME;
                ConfigConn.bCOMPLETO = conexao.bCOMPLETO;
                conn.PATH            = conexao.PROPRIEDADES["dbname"];

                SerializeClassToXml.SerializeClasse <ModelConexao>(ConfigConn, sPath);


                //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                //config.ConnectionStrings.ConnectionStrings[conexao.NOME].ConnectionString =
                //    this.GetConnectionString(conexao);
                //if (conexao.NOME == "DBArquivoSpedFiscal" || conexao.NOME == "DBArquivoSpedContabil")
                //{
                //    config.AppSettings.Settings.Remove("ActiveRecordDialect");
                //    config.AppSettings.Settings.Add("ActiveRecordDialect", "NHibernate.Dialect.FirebirdDialect");
                //}
                //config.Save(ConfigurationSaveMode.Modified, false);
                //ConfigurationManager.RefreshSection("connectionStrings");
            }
        }
Пример #4
0
        public void RemoveConexao(Conexao conexao)
        {
            string sPath = Util.GetPastaConfiguracao();

            if (sPath == "")
            {
                throw new Exception("Configure um diretório na rede para salvar as conexões.");
            }
            sPath     += "\\SpedConfig.xml";
            ConfigConn = GetConfigConexoes();

            if (ConfigConn != null)
            {
                if (ConfigConn.CONEXOES.Where(c => c.NAME == conexao.NOME).Count() > 0)
                {
                    ConfigConn.CONEXOES.Remove(ConfigConn.CONEXOES.FirstOrDefault(c => c.NAME == conexao.NOME));
                }
                SerializeClassToXml.SerializeClasse <ModelConexao>(ConfigConn, sPath);
            }
        }
Пример #5
0
        public belBuscaRetornoMDFe(PesquisaManifestosModel objPesquisa)
        {
            this.objPesquisa = objPesquisa;
            TConsReciMDFe objconsulta = new TConsReciMDFe();

            objconsulta.versao = Acesso.versaoMDFe;
            objconsulta.tpAmb  = Acesso.TP_AMB == 1 ? TAmb.Item1 : TAmb.Item2;
            objconsulta.nRec   = this.objPesquisa.recibo;
            string sPathSave = Pastas.PROTOCOLOS + "Rec_" + this.objPesquisa.numero + ".xml";

            if (File.Exists(sPathSave))
            {
                File.Delete(sPathSave);
            }
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add("", "http://www.portalfiscal.inf.br/mdfe");
            SerializeClassToXml.SerializeClasse <TConsReciMDFe>(objconsulta, sPathSave, ns);
            xmlConsulta = new XmlDocument();
            xmlConsulta.PreserveWhitespace = false;
            xmlConsulta.Load(sPathSave);
        }
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            NFe_HLP objNFe     = null;
            nfeProc objNfeProc = null;
            infNFe  nfe        = null;
            int     i          = 0;
            string  slblInfo   = "{0} de {1} Arquivo(s)...";

            foreach (HLP.GeraXml.UI.NFe.frmGeraArquivoNFe.DadosImpressao dados in objDadosImp)
            {
                CarregaDadosNFe(ref objNFe, ref objNfeProc, ref nfe, dados);
                if (dados.tipo == frmGeraArquivoNFe.TipoPDF.CANCELADO)
                {
                    objNFe.xCANC = "NFe CANCELADA";
                }
                GeraXMLtoPDF(objNFe);
                dados.xStatus = "Dados carregados em memória...";
                this.Invoke(new MethodInvoker(delegate()
                {
                    dgvNotas.CurrentCell = dgvNotas.Rows[i].Cells[2];
                    dgvNotas.CurrentRow.DefaultCellStyle.BackColor = Color.Aquamarine;
                    lblInfo.Text = string.Format(slblInfo, (i + 1).ToString(), objNFeToReport.Count());
                    dgvNotas.Refresh();
                    lblInfo.Refresh();
                }));
                i++;
            }

            string sFileSave = Pastas.Temp + "NFeToReport.xml";

            if (File.Exists(sFileSave))
            {
                File.Delete(sFileSave);
            }
            SerializeClassToXml.SerializeClasse <List <NFe_HLP> >(objNFeToReport, sFileSave);
        }
Пример #7
0
        /// <summary>
        /// Gera Xml de consulta do status
        /// </summary>
        /// <param name="classe"></param>
        /// <returns></returns>
        public XmlNode GeraXml()
        {
            TConsStatServ           classe = new TConsStatServ();
            string                  sPath  = Pastas.PROTOCOLOS + "\\" + DateTime.Now.ToString("ddMMyyyyHHmmSS") + "“-ped-sta.xml";
            XmlSerializerNamespaces ns     = new XmlSerializerNamespaces();

            ns.Add("", "http://www.portalfiscal.inf.br/mdfe");
            SerializeClassToXml.SerializeClasse <TConsStatServ>(classe: classe, sPathSave: sPath, namespac: ns);
            try
            {
                belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/mdfe", Pastas.SCHEMA_MDFe + "\\consStatServMDFe_v1.00.xsd", sPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            XmlDocument xmlRet = new XmlDocument();

            xmlRet.Load(sPath);

            XmlNode node = xmlRet.DocumentElement;

            return(node);
        }
Пример #8
0
        private void CarregaItensEventoCartaCorrecao(belPesquisaCCe objbelPesquisa)
        {
            try
            {
                if (Acesso.NM_RAMO != Acesso.BancoDados.TRANSPORTE)
                {
                    objEnvEvento        = new belEnvEvento();
                    objEnvEvento.versao = this._VERSAO;
                    objEnvEvento.id     = objbelPesquisa.CD_NRLANC;
                    belEvento objEvento = new belEvento();
                    objEvento.versao              = _VERSAO;
                    objEvento.infEvento           = new _infEvento();
                    objEvento.infEvento.CNPJ      = objbelPesquisa.CNPJ;
                    objEvento.infEvento.CPF       = objbelPesquisa.CPF;
                    objEvento.infEvento.dhEvento  = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss" + Acesso.FUSO);
                    objEvento.infEvento.verEvento = _VERSAO;
                    objEvento.infEvento.tpAmb     = Acesso.TP_AMB;
                    objEvento.infEvento.chNFe     = objbelPesquisa.CHNFE;
                    objEvento.infEvento.cOrgao    = Acesso.cUF.ToString();
                    objEvento.infEvento.detEvento = new _detEvento
                    {
                        versao = _VERSAO
                    };
                    objEvento.infEvento.detEvento.xCorrecao = BuscaCorrecoes(objbelPesquisa.CD_NRLANC);
                    objEvento.infEvento.nSeqEvento          = objbelPesquisa.QT_ENVIO + 1;
                    objEvento.idLote = "ID" + objEvento.infEvento.tpEvento + objEvento.infEvento.chNFe + objEvento.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    objEnvEvento.evento.Add(objEvento);
                }
                else
                {
                    objEvCCeCTe = new TEvento();

                    objEvCCeCTe.versao               = Acesso.versaoCTe;
                    objEvCCeCTe.infEvento            = new  TEventoInfEvento();
                    objEvCCeCTe.infEvento.tpEvento   = "110110";
                    objEvCCeCTe.infEvento.nSeqEvento = (objbelPesquisa.QT_ENVIO + 1).ToString();// numero de evento
                    objEvCCeCTe.infEvento.Id         = "ID" + objEvCCeCTe.infEvento.tpEvento + objlItensPesquisa.FirstOrDefault().CHNFE + objEvCCeCTe.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    //objEvCCeCTe.infEvento.Id = "ID" + objlItensPesquisa.FirstOrDefault().CHNFE;
                    objEvCCeCTe.infEvento.cOrgao    = Convert.ToByte(Acesso.cUF);
                    objEvCCeCTe.infEvento.tpAmb     = Acesso.TP_AMB == 1 ? TAmb.Item1 : TAmb.Item2;
                    objEvCCeCTe.infEvento.CNPJ      = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
                    objEvCCeCTe.infEvento.chCTe     = objbelPesquisa.CHNFE;
                    objEvCCeCTe.infEvento.dhEvento  = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss");
                    objEvCCeCTe.infEvento.detEvento = new TEventoInfEventoDetEvento();
                    objEvCCeCTe.infEvento.detEvento.versaoEvento = Acesso.versaoCTe;

                    evCCeCTe objEvCanc = new evCCeCTe();
                    objEvCanc.descEvento  = evCCeCTeDescEvento.CartadeCorrecao;
                    objEvCanc.infCorrecao = new List <evCCeCTeInfCorrecao>();
                    objEvCanc.CD_NRLANC   = objbelPesquisa.CD_NRLANC;
                    foreach (DataRow item in BuscaCorrecoesCTe(objbelPesquisa.CD_NRLANC).Rows)
                    {
                        objEvCanc.infCorrecao.Add(new evCCeCTeInfCorrecao
                        {
                            grupoAlterado   = item["grupoAlterado"].ToString(),
                            campoAlterado   = item["campoAlterado"].ToString(),
                            valorAlterado   = item["valorAlterado"].ToString(),
                            nroItemAlterado = item["nroItemAlterado"].ToString(),
                        });
                    }
                    objEvCanc.xCondUso = evCCeCTeXCondUso.ACartadeCorreçãoédisciplinadapeloArt58BdoCONVÊNIOSINIEF0689FicapermitidaautilizaçãodecartadecorreçãopararegularizaçãodeerroocorridonaemissãodedocumentosfiscaisrelativosàprestaçãodeserviçodetransportedesdequeoerronãoestejarelacionadocomIasvariáveisquedeterminamovalordoimpostotaiscomobasedecálculoalíquotadiferençadepreçoquantidadevalordaprestaçãoIIacorreçãodedadoscadastraisqueimpliquemudançadoemitentetomadorremetenteoudodestinatárioIIIadatadeemissãooudesaída;
                    string xFile = Pastas.CCe + "\\" + objEvCanc.CD_NRLANC + "_prevalida.xml";
                    SerializeClassToXml.SerializeClasse <evCCeCTe>(objEvCanc, xFile);
                    XmlDocument xml = new XmlDocument();
                    xml.Load(xFile);
                    objEvCCeCTe.infEvento.detEvento.Any = (System.Xml.XmlElement)xml.DocumentElement;


                    XmlSerializer xs      = new XmlSerializer(typeof(TEvento));
                    MemoryStream  memory  = new MemoryStream();
                    XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);
                    xs.Serialize(xmltext, objEvCCeCTe);
                    UTF8Encoding encoding = new UTF8Encoding();
                    this.sXMLfinal = encoding.GetString(memory.ToArray());
                    this.sXMLfinal = this.sXMLfinal.Substring(1);

                    belAssinaXml Assinatura = new belAssinaXml();
                    this.sXMLfinal = Assinatura.ConfigurarArquivo(this.sXMLfinal, "infEvento", Acesso.cert_CTe);

                    xml = new XmlDocument();
                    xml.LoadXml(this.sXMLfinal);
                    string sPath = Pastas.PROTOCOLOS + "\\" + objbelPesquisa.CHNFE + "_ped-cce.xml";
                    if (File.Exists(sPath))
                    {
                        File.Delete(sPath);
                    }
                    xml.Save(sPath);
                    try
                    {
                        belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/cte", Pastas.SCHEMA_CTE + "\\eventoCTe_v2.00.xsd", sPath);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #9
0
        public string Enviar()
        {
            tempo.Tick += new EventHandler(tempo_Tick);
            try
            {
                if (Acesso.TP_AMB_SERV == 1)
                {
                    lt.ClientCertificates.Add(Acesso.cert_NFs);
                }
                string x = "";
                for (int i = 5; ((i != 0) && (x == "")); i--)
                {
                    try
                    {
                        tempo.Start();
                        if (Acesso.TP_AMB_SERV == 1)
                        {
                            x = lt.enviar(dadosRPS.xmlLote.InnerXml.ToString());
                        }
                        else
                        {
                            x = lt.testeEnviar(dadosRPS.xmlLote.InnerXml.ToString());
                        }
                        tempo.Stop();
                    }
                    catch (Exception ex)
                    {
                        if (i == 0)
                        {
                            throw ex;
                        }
                    }
                }
                //Deserializa o retorno do webservice.
                XmlSerializer       deserializer = new XmlSerializer(typeof(RetornoEnvioLoteRPS));
                RetornoEnvioLoteRPS ret;
                byte[]       bytearray   = Encoding.ASCII.GetBytes(x);
                MemoryStream valorStream = new MemoryStream(bytearray);
                ret = (RetornoEnvioLoteRPS)deserializer.Deserialize(valorStream);

                //Salva protocolo de retorno.
                StreamWriter sw = new StreamWriter(Pastas.PROTOCOLOS + "\\NFSE_LOTE_" + ret.cabec.NumeroLote + ".xml");
                sw.Write(x);
                sw.Close();

                string sMessageRetorno = "Método enviado Sincronamente";

                if (ret.cabec.Assincrono == "S")
                {
                    ReqConsultaLote consultaLote = new ReqConsultaLote();

                    consultaLote.cabec                  = new belConsultaLote();
                    consultaLote.cabec.CodCidade        = ret.cabec.CodCidade;
                    consultaLote.cabec.CPFCNPJRemetente = ret.cabec.CPFCNPJRemetente;
                    consultaLote.cabec.NumeroLote       = ret.cabec.NumeroLote;
                    consultaLote.cabec.Versao           = ret.cabec.Versao.ToString();

                    //hora de salvar o numero do Lote nos RPS contidos no lote.
                    foreach (LoteRPS rps in this.dadosRPS.objLoteEnvio.lote.RPS)
                    {
                        base.SalvarRecibo(consultaLote.cabec.NumeroLote, rps.CD_NFSEQ);
                    }


                    string sPath = Pastas.PROTOCOLOS + "\\CONSULTA_LOTE_" + ret.cabec.NumeroLote + ".xml";

                    if (File.Exists(sPath))
                    {
                        File.Delete(sPath);
                    }

                    XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
                    nameSpaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                    nameSpaces.Add("tipos", "http://localhost:8080/WsNFe2/tp");
                    nameSpaces.Add("ns1", "http://localhost:8080/WsNFe2/lote");

                    SerializeClassToXml.SerializeClasse <ReqConsultaLote>(consultaLote, sPath, nameSpaces);
                    sMessageRetorno = BuscaRetorno(ret.cabec.NumeroLote);
                }
                else if (ret.erros.Erro.Count() > 0)
                {
                    sMessageRetorno = "Erros:" + Environment.NewLine;
                    foreach (ErrosErro err in ret.erros.Erro)
                    {
                        sMessageRetorno += string.Format("Codigo:{0} - Descrição:{1}{2}", err.Codigo, err.Descricao, Environment.NewLine);
                    }
                    foreach (LoteRPS rps in this.dadosRPS.objLoteEnvio.lote.RPS)
                    {
                        base.LimpaCampoRecibo(rps.CD_NFSEQ);
                    }
                }
                else if (ret.alertas.alert.Count() > 0)
                {
                    sMessageRetorno = "Alertas:" + Environment.NewLine;
                    foreach (Alerta_retlote alert in ret.alertas.alert)
                    {
                        sMessageRetorno += string.Format("Codigo:{0} - Descrição:{1}{2}", alert.Codigo, alert.Descricao, Environment.NewLine);
                    }
                }

                return(sMessageRetorno);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #10
0
        private void Serialize()
        {
            try
            {
                string sPathXml = GetFilePathLoteServico();
                if (File.Exists(sPathXml))
                {
                    File.Delete(sPathXml);
                }

                XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
                nameSpaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                nameSpaces.Add("tipos", "http://localhost:8080/WsNFe2/tp");
                nameSpaces.Add("ns1", "http://localhost:8080/WsNFe2/lote");

                //XmlTextWriter xmlTextWriter = new
                //XmlTextWriter(sPathXml, Encoding.UTF8);
                //xmlTextWriter.Formatting = Formatting.Indented;
                //XmlSerializer xs = new XmlSerializer(typeof(ReqEnvioLoteRPS));
                //xs.Serialize(xmlTextWriter, objLoteEnvio, nameSpaces);
                //xmlTextWriter.Close();

                foreach (LoteRPS item in objLoteEnvio.lote.RPS)
                {
                    item.bSerialize = true;
                }

                String        XmlizedString = null;
                XmlSerializer x             = new XmlSerializer(objLoteEnvio.GetType());
                MemoryStream  memoryStream  = new MemoryStream();
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
                x.Serialize(xmlTextWriter, objLoteEnvio, nameSpaces);
                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                UTF8Encoding encoding = new UTF8Encoding();
                XmlizedString = encoding.GetString(memoryStream.ToArray());
                XmlizedString = XmlizedString.Substring(1);
                if (Acesso.TP_AMB_SERV == 1)
                {
                    belAssinaXml Assinatura = new belAssinaXml();
                    XmlizedString = Assinatura.ConfigurarArquivo(XmlizedString, "Lote", Acesso.cert_NFs);
                }

                this.xmlLote = new XmlDocument();
                this.xmlLote.LoadXml(XmlizedString);
                this.xmlLote.Save(sPathXml);
                this.ValidaXml(sPathXml);

                foreach (LoteRPS lot in objLoteEnvio.lote.RPS)
                {
                    sPathXml = GetFilePathMonthServico(false, lot.NumeroRPS);
                    if (File.Exists(sPathXml))
                    {
                        LoteRPS lotExistente = SerializeClassToXml.DeserializeClasse <LoteRPS>(sPathXml);

                        string sCD_NFSEQ = daoUtil.GetNFSEQbyNumeroRPS(lotExistente.NumeroRPS);

                        if (lot.CD_NFSEQ == sCD_NFSEQ)
                        {
                            File.Delete(sPathXml);
                        }
                        else
                        {
                            throw new Exception(string.Format("A Nota de sequencia '{0}' já esta utilizando o RPS de numero '{1}', é necessário envia-la para que o RPS possa ser incrementado.", sCD_NFSEQ, lotExistente.NumeroRPS));
                        }
                    }


                    SerializeClassToXml.SerializeClasse <LoteRPS>(lot, sPathXml);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }