public string TrataRetornoManifestacao(string sTipoRegistro) { try { if (this.sXMLretorno != "") { objRet = SerializeClassToXml.DeserializeClasseString <belRetEventoCancelamento>(this.sXMLretorno); if (objRet.cStat == "128") { if (objRet.retEvento.infEvento.cStat == "135") { daoUtil.SetStatusManifestacao(this.xChaveNFe, sTipoRegistro); this.stManifesto = sTipoRegistro; } } return(string.Format("NFe: {0} - Status: {1} - Motivo: {2}{3}", this.xNumero, objRet.cStat, objRet.retEvento != null? objRet.retEvento.infEvento.xMotivo: objRet.xMotivo, Environment.NewLine)); } else { return("Nenhum evento registrado."); } } catch (Exception ex) { throw ex; } }
private void ConsultaLote(HLP.GeraXml.WebService.NFSE_Campinas.LoteRpsService _lt, string sXmlConsulta, string num_lote, out RetornoConsultaLote objretorno) { string sRetornoLote = ""; for (int i = 5; ((i != 0) && (sRetornoLote == "")); i--) { try { tempo.Start(); sRetornoLote = _lt.consultarLote(sXmlConsulta); tempo.Stop(); } catch (Exception ex) { if (i == 0) { throw ex; } } } sRetornoLote = _lt.consultarLote(sXmlConsulta); string sPathRetConsultaLote = Pastas.PROTOCOLOS + "\\Ret_Consulta_Lote_" + num_lote + ".xml"; try { XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(sRetornoLote); xDoc.Save(sPathRetConsultaLote); } catch (Exception ex) { throw new Exception("Falha ao converter o retorno do webservice do método consultarLote" + Environment.NewLine + "MSG:" + sRetornoLote.ToString() + Environment.NewLine + ex.Message); } objretorno = SerializeClassToXml.DeserializeClasse <RetornoConsultaLote>(sPathRetConsultaLote); }
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; } }
private void btnFindFiles_Click(object sender, EventArgs e) { try { OpenFileDialog f = new OpenFileDialog(); f.Filter = "XML Files|*.xml"; f.Multiselect = true; objPesquisa.lresult = new List <belManifestacaoPesquisa>(); if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { belManifestacaoPesquisa obj = null; nfeProc nfe = null; foreach (string path in f.FileNames) { nfe = SerializeClassToXml.DeserializeClasse <nfeProc>(path); obj = new belManifestacaoPesquisa(nfe); objPesquisa.lresult.AddRange(obj.lresult); } bsPesquisa.DataSource = objPesquisa.lresult; ColoriGrid(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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; } }
public string Cancelar() { try { XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces(); nameSpaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); nameSpaces.Add("tipos", "http://*****:*****@"D:\Ret_CANC_LOTE_2805131157.xml"; RetornoCancelamentoNFSe objretorno = SerializeClassToXml.DeserializeClasse <RetornoCancelamentoNFSe>(sPathRetConsultaCanc); string sMessageRetorno = TrataRetornoCancelamento(objretorno); return(sMessageRetorno); } catch (Exception ex) { throw ex; } }
public ModelConexao GetConfigConexoes() { ModelConexao objRet = null; string sPath = Util.GetPastaConfiguracao() + "\\SpedConfig.xml"; if (sPath != "") { if (File.Exists(sPath)) { objRet = SerializeClassToXml.DeserializeClasse <ModelConexao>(sPath); } } return(objRet); }
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"); } }
public HLP.GeraXml.bel.CTe.Evento.TRetEvento TransmiteLoteCCeCTe() { string sRetorno = ""; XmlDocument _xmlxelem = new XmlDocument(); _xmlxelem.PreserveWhitespace = true; _xmlxelem.LoadXml(this.sXMLfinal); XmlNode xNelem = null; xNelem = _xmlxelem.DocumentElement; try { //Homologação if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.CTe_Homologacao_cteCancelamento.cteCabecMsg objCabecCancelamento = new HLP.GeraXml.WebService.CTe_Homologacao_cteCancelamento.cteCabecMsg(); objCabecCancelamento.cUF = Acesso.cUF.ToString(); objCabecCancelamento.versaoDados = Acesso.versaoCTe; HLP.GeraXml.WebService.CTe_Homologacao_cteCancelamento.CteCancelamento objCancelamento = new HLP.GeraXml.WebService.CTe_Homologacao_cteCancelamento.CteCancelamento(); objCancelamento.cteCabecMsgValue = objCabecCancelamento; objCancelamento.ClientCertificates.Add(Acesso.cert_CTe); sRetorno = objCancelamento.cteCancelamentoCT(xNelem).OuterXml; } //Produção else if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.CTe_Producao_evento.cteCabecMsg cabec = new WebService.CTe_Producao_evento.cteCabecMsg(); HLP.GeraXml.WebService.CTe_Producao_evento.CteRecepcaoEvento objCancelamento = new WebService.CTe_Producao_evento.CteRecepcaoEvento(); cabec.cUF = Acesso.cUF.ToString(); cabec.versaoDados = Acesso.versaoCTe; objCancelamento.cteCabecMsgValue = cabec; objCancelamento.ClientCertificates.Add(Acesso.cert_CTe); sRetorno = objCancelamento.cteRecepcaoEvento(xNelem).OuterXml; } XDocument xRet = XDocument.Parse(sRetorno); string sPath = Pastas.PROTOCOLOS + "\\" + this.objlItensPesquisa.FirstOrDefault().CHNFE + "_ret-cce.xml"; xRet.Save(sPath); HLP.GeraXml.bel.CTe.Evento.TRetEvento retorno = SerializeClassToXml.DeserializeClasse <HLP.GeraXml.bel.CTe.Evento.TRetEvento>(sPath); return(retorno); } catch (Exception ex) { throw ex; } }
public string TransmitirLote() { XmlNode xNelem = xml.DocumentElement; string sRet = string.Empty; if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.MDFe_Producao_Recepcao.mdfeCabecMsg cabec = new WebService.MDFe_Producao_Recepcao.mdfeCabecMsg(); HLP.GeraXml.WebService.MDFe_Producao_Recepcao.MDFeRecepcao servico = new WebService.MDFe_Producao_Recepcao.MDFeRecepcao(); cabec.cUF = Acesso.cUF.ToString(); cabec.versaoDados = Acesso.versaoMDFe; servico.mdfeCabecMsgValue = cabec; servico.ClientCertificates.Add(Acesso.cert_CTe); sRet = servico.mdfeRecepcaoLote(xNelem).OuterXml; } else { HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_Recepcao.mdfeCabecMsg cabec = new WebServiceHomologacao.MDFe_Homologacao_Recepcao.mdfeCabecMsg(); HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_Recepcao.MDFeRecepcao servico = new WebServiceHomologacao.MDFe_Homologacao_Recepcao.MDFeRecepcao(); cabec.cUF = Acesso.cUF.ToString(); cabec.versaoDados = Acesso.versaoMDFe; servico.mdfeCabecMsgValue = cabec; servico.ClientCertificates.Add(Acesso.cert_CTe); sRet = servico.mdfeRecepcaoLote(xNelem).OuterXml; } if (sRet != string.Empty) { sRet = sRet.Replace(" xmlns=\"http://www.portalfiscal.inf.br/mdfe\" versao=\"1.00\"", ""); string sPathRecibo = Pastas.PROTOCOLOS + enviMDFe.idLote + "-rec.xml"; if (System.IO.File.Exists(sPathRecibo)) { System.IO.File.Delete(sPathRecibo); } XmlDocument x = new XmlDocument(); x.LoadXml(sRet); x.Save(sPathRecibo); recibo = SerializeClassToXml.DeserializeClasse <retEnviMDFe>(sPathRecibo); daoManifesto.gravaRecibo(recibo.infRec.nRec, Convert.ToInt32(enviMDFe.MDFe.infMDFe.ide.cMDF).ToString().PadLeft(7, '0')); daoManifesto.gravaChave(enviMDFe.MDFe.infMDFe.Id.Replace("MDFe", ""), Convert.ToInt32(enviMDFe.MDFe.infMDFe.ide.cMDF).ToString().PadLeft(7, '0')); return(recibo.infRec.nRec); } else { return(null); } }
private void btnPesquisar_Click(object sender, EventArgs e) { try { string sCaminho = Pastas.PASTA_XML_CONFIG + "\\" + cbxArquivos.cbx.SelectedItem.ToString(); belConfiguracao objConfig = SerializeClassToXml.DeserializeClasse <belConfiguracao>(sCaminho); sPastaProtocolos = objConfig.CAMINHO_PADRAO + "\\Protocolos\\"; PopulaGridCancelados(); PopulaGridInutilizados(); } catch (Exception ex) { throw ex; } }
public TRetConsStatServ ExecuteConsulta() { TRetConsStatServ ret = null; try { string sReturn = string.Empty; if (Acesso.TP_AMB == 1) // Producao { HLP.GeraXml.WebService.MDFe_Producao_StatusServico.MDFeStatusServico servico = new WebService.MDFe_Producao_StatusServico.MDFeStatusServico(); HLP.GeraXml.WebService.MDFe_Producao_StatusServico.mdfeCabecMsg cabec = new WebService.MDFe_Producao_StatusServico.mdfeCabecMsg(); cabec.cUF = Acesso.cUF.ToString(); cabec.versaoDados = Acesso.versaoMDFe.ToString(); servico.mdfeCabecMsgValue = cabec; servico.ClientCertificates.Add(Acesso.cert_CTe); sReturn = servico.mdfeStatusServicoMDF(this.GeraXml()).OuterXml; } else { HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_StatusServico.MDFeStatusServico servico = new HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_StatusServico.MDFeStatusServico(); HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_StatusServico.mdfeCabecMsg cabec = new HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_StatusServico.mdfeCabecMsg(); cabec.cUF = Acesso.cUF.ToString(); cabec.versaoDados = Acesso.versaoMDFe.ToString(); servico.mdfeCabecMsgValue = cabec; servico.ClientCertificates.Add(Acesso.cert_CTe); sReturn = servico.mdfeStatusServicoMDF(this.GeraXml()).OuterXml; } if (sReturn != string.Empty) { string sPath = Pastas.PROTOCOLOS + "\\" + DateTime.Now.ToString("ddMMyyyyHHmmSS") + "“-ret-sta.xml"; XmlDocument xmlRet = new XmlDocument(); xmlRet.LoadXml(sReturn); xmlRet.Save(sPath); ret = SerializeClassToXml.DeserializeClasse <TRetConsStatServ>(sPath); } else { throw new Exception("Nenhum resultado obtido."); } } catch (System.Exception ex) { throw ex; } return(ret); }
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); } }
private void PopulaTabVisualizacao(object obj) { try { if (Acesso.NM_RAMO != Acesso.BancoDados.TRANSPORTE) { belEvento objEvento = obj as belEvento; txtNotaFis.Text = (bsGrid.DataSource as List <belPesquisaCCe>).FirstOrDefault(c => c.CHNFE == objEvento.infEvento.chNFe).CD_NOTAFIS; txtChaveNFe.Text = objEvento.infEvento.chNFe; txtRazaoSocial.Text = (bsGrid.DataSource as List <belPesquisaCCe>).FirstOrDefault(c => c.CHNFE == objEvento.infEvento.chNFe).NM_CLIFOR; txtCondUso.Text = objEvento.infEvento.detEvento.xCondUso; txtAjustes.Text = objEvento.infEvento.detEvento.xCorrecao.Replace("|", Environment.NewLine); } else { TEvento objEvCCeCTe = obj as TEvento; txtNotaFis.Text = (bsGrid.DataSource as List <belPesquisaCCe>).FirstOrDefault(c => c.CHNFE == objEvCCeCTe.infEvento.chCTe).CD_NOTAFIS; txtChaveNFe.Text = objEvCCeCTe.infEvento.chCTe; txtRazaoSocial.Text = (bsGrid.DataSource as List <belPesquisaCCe>).FirstOrDefault(c => c.CHNFE == objEvCCeCTe.infEvento.chCTe).NM_CLIFOR; string xFile = Pastas.CCe + "\\" + (bsGrid.DataSource as List <belPesquisaCCe>).FirstOrDefault(c => c.CHNFE == objEvCCeCTe.infEvento.chCTe).CD_NRLANC + "_prevalida.xml"; evCCeCTe objEvCanc = SerializeClassToXml.DeserializeClasse <evCCeCTe>(xFile); txtCondUso.Text = objEvCanc.xCondUso.ToString(); txtAjustes.Text = ""; foreach (var item in objEvCanc.infCorrecao) { txtAjustes.Text += string.Format("GRUPO: {0} - CAMPO: {1} - CORREÇÃO:{2} - {3}{4}" + Environment.NewLine, item.grupoAlterado.ToString().ToUpper().Trim(), item.campoAlterado.ToString().ToUpper().Trim(), item.valorAlterado.ToString().ToUpper().Trim(), (item.nroItemAlterado != null ? "INDEX:" : ""), (item.nroItemAlterado != null ? item.nroItemAlterado.ToString() : "")); } } } catch (Exception ex) { throw ex; } }
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); }
/// <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); }
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); }
private void PopulaGridCancelados() { try { DirectoryInfo diretorio = new DirectoryInfo(sPastaProtocolos); FileSystemInfo[] itens = diretorio.GetFileSystemInfos("*.xml"); int irow = 0; dgvCancelamentos.Rows.Clear(); Evento eventoCanc = null; foreach (FileSystemInfo item in itens) { if (item.Name.Contains("ped-can")) { eventoCanc = null; try { eventoCanc = SerializeClassToXml.DeserializeClasse <Evento>(item.FullName); dgvCancelamentos.Rows.Add(); dgvCancelamentos[0, irow].Value = eventoCanc.infEvento.tpAmb == 2 ? "Homologação" : "Produção"; // (xml.GetElementsByTagName("infCanc").Item(0).FirstChild.InnerText == "2" ? "Homologação" : "Produção"); dgvCancelamentos[1, irow].Value = eventoCanc.infEvento.chNFe.Substring(25, 9); // (xml.GetElementsByTagName("chNFe").Item(0).InnerText.Equals("") ? "S/Nota" : xml.GetElementsByTagName("chNFe").Item(0).InnerText.Substring(25, 9)); dgvCancelamentos[2, irow].Value = eventoCanc.infEvento.chNFe.Substring(34, 9); // (xml.GetElementsByTagName("chNFe").Item(0).InnerText.Equals("") ? "S/Sequencia" : xml.GetElementsByTagName("chNFe").Item(0).InnerText.Substring(34, 9)); dgvCancelamentos[3, irow].Value = eventoCanc.infEvento.detEvento.nProt; // (xml.GetElementsByTagName("nProt").Item(0).InnerText.Equals("") ? "S/Protocolo" : xml.GetElementsByTagName("nProt").Item(0).InnerText); dgvCancelamentos[5, irow].Value = item.Name; irow++; } catch (Exception) { } } } } catch (Exception ex) { throw ex; } }
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; } }
void CarregaDadosNFe(ref NFe_HLP objNFe, ref nfeProc objNfeProc, ref infNFe nfe, HLP.GeraXml.UI.NFe.frmGeraArquivoNFe.DadosImpressao dados) { //"C:\\GeraXml\\Arquivos\\VIVABEM\\Contingencia\\\\35130947853981000183550010000001872000000665-nfe.xml" if (dados.tipo == frmGeraArquivoNFe.TipoPDF.CONTINGENCIA) { objNfeProc = new nfeProc(); objNfeProc.lNfe = new List <bel.NFe.ClassesSerializadas.NFe>(); objNfeProc.lNfe.Add(SerializeClassToXml.DeserializeClasse <HLP.GeraXml.bel.NFe.ClassesSerializadas.NFe>(dados.sCaminhoXml)); } else { objNfeProc = SerializeClassToXml.DeserializeClasse <nfeProc>(dados.sCaminhoXml); } if (objNfeProc != null) { nfe = objNfeProc.lNfe.FirstOrDefault().lInfNfe.FirstOrDefault(); objNFe = new NFe_HLP(); objNFe.Id = nfe.Id.ToUpper().Replace("NFE", "").Trim(); objNFe.tpEmis = nfe.ideField.tpEmis.ToString().Replace("Item", "").Trim(); objNFe.tipoPDF = dados.tipo.ToString(); rowImg = dsImg.Imagens.NewImagensRow(); if (objNfeProc.protNFeField != null) { objNFe.infprot_nprot = objNfeProc.protNFeField.FirstOrDefault().infProtField.FirstOrDefault().nProt; } objNFe.ide_nNF = nfe.ideField.nNF; objNFe.natOP = nfe.ideField.natOp; objNFe.ide_serie = nfe.ideField.serie; objNFe.ide_tpNF = nfe.ideField.tpNF; if (nfe.ideField.dEmi != "") { objNFe.ide_dEmi = nfe.ideField.dEmi.ToDateTime().ToShortDateString(); } if (Convert.ToBoolean(Acesso.VISUALIZA_DATA_DANFE)) { if (nfe.ideField.dSaiEnt != "") { objNFe.ide_dSaiEnt = nfe.ideField.dSaiEnt.ToDateTime().ToShortDateString(); } } objNFe.emit_xNome = nfe.emitField.xNome; objNFe.emit_xFant = nfe.emitField.xFant; objNFe.emit_CPF_CNPJ = nfe.emitField.Item; objNFe.emit_IE = nfe.emitField.IE; objNFe.emit_IEST = nfe.emitField.IEST; objNFe.enderEmit_xLgr = nfe.emitField.enderEmit.xLgr; objNFe.enderEmit_nro = nfe.emitField.enderEmit.nro; objNFe.enderEmit_xCpl = nfe.emitField.enderEmit.xCpl; objNFe.enderEmit_xBairro = nfe.emitField.enderEmit.xBairro; objNFe.enderEmit_cMun = nfe.emitField.enderEmit.cMun; objNFe.enderEmit_xMun = nfe.emitField.enderEmit.xMun; objNFe.enderEmit_UF = nfe.emitField.enderEmit.UF; objNFe.enderEmit_CEP = nfe.emitField.enderEmit.CEP; objNFe.enderEmit_fone = nfe.emitField.enderEmit.fone; objNFe.dest_xNome = nfe.destField.xNome; objNFe.dest_CPF_CNPJ = nfe.destField.Item; // Verificar objNFe.dest_IE = nfe.destField.IE; objNFe.enderDest_xLgr = nfe.destField.enderDest.xLgr; objNFe.enderDest_nro = nfe.destField.enderDest.nro; objNFe.enderDest_xCpl = nfe.destField.enderDest.xCpl; objNFe.enderDest_xBairro = nfe.destField.enderDest.xBairro; objNFe.enderDest_cMun = nfe.destField.enderDest.cMun; objNFe.enderDest_xMun = nfe.destField.enderDest.xMun; objNFe.enderDest_UF = nfe.destField.enderDest.UF; objNFe.enderDest_CEP = nfe.destField.enderDest.CEP; objNFe.enderDest_fone = nfe.destField.enderDest.fone; if (nfe.transpField != null) { if (nfe.transpField.transporta != null) { objNFe.transp_xNome = nfe.transpField.transporta.xNome; objNFe.transp_modFrete = nfe.transpField.modFrete; objNFe.transp_CFP_CNPJ = nfe.transpField.transporta.Item; objNFe.transp_xEnder = nfe.transpField.transporta.xEnder; objNFe.transp_xMun = nfe.transpField.transporta.xMun; objNFe.transp_UF = nfe.transpField.transporta.UF; objNFe.transp_IE = nfe.transpField.transporta.IE; if (nfe.transpField.Items != null) { TVeiculo veic = nfe.transpField.Items.FirstOrDefault(c => c.GetType() == typeof(TVeiculo)) as TVeiculo; if (veic != null) { objNFe.transp_RNTCVeic = veic.RNTC; objNFe.transp_placaVeic = veic.placa; objNFe.transp_UFVeic = veic.UF.ToString(); } } if (nfe.transpField.vol != null) { objNFe.transp_qVol = nfe.transpField.vol.FirstOrDefault().qVol; objNFe.transp_esp = nfe.transpField.vol.FirstOrDefault().esp; objNFe.transp_marca = nfe.transpField.vol.FirstOrDefault().marca; objNFe.transp_nVol = nfe.transpField.vol.FirstOrDefault().nVol; objNFe.transp_PesoB = nfe.transpField.vol.FirstOrDefault().pesoB; objNFe.transp_PesoL = nfe.transpField.vol.FirstOrDefault().pesoL; } } } objNFe.ICMSTot_vBC = nfe.totalField.ICMSTot.vBC.Replace('.', ','); objNFe.ICMSTot_vICMS = nfe.totalField.ICMSTot.vICMS.Replace('.', ','); objNFe.ICMSTot_vBCST = nfe.totalField.ICMSTot.vBCST.Replace('.', ','); objNFe.ICMSTot_vST = nfe.totalField.ICMSTot.vST.Replace('.', ','); objNFe.ICMSTot_vProd = nfe.totalField.ICMSTot.vProd.Replace('.', ','); objNFe.ICMSTot_vFrete = nfe.totalField.ICMSTot.vFrete.Replace('.', ','); objNFe.ICMSTot_vSeg = nfe.totalField.ICMSTot.vSeg.Replace('.', ','); objNFe.ICMSTot_vDesc = nfe.totalField.ICMSTot.vDesc.Replace('.', ','); objNFe.ICMSTot_vII = nfe.totalField.ICMSTot.vII.Replace('.', ','); objNFe.ICMSTot_vIPI = nfe.totalField.ICMSTot.vIPI.Replace('.', ','); objNFe.ICMSTot_vPIS = nfe.totalField.ICMSTot.vPIS.Replace('.', ','); objNFe.ICMSTot_vCOFINS = nfe.totalField.ICMSTot.vCOFINS.Replace('.', ','); objNFe.ICMSTot_vOutro = nfe.totalField.ICMSTot.vOutro.Replace('.', ','); objNFe.ICMSTot_vNF = nfe.totalField.ICMSTot.vNF.Replace('.', ','); objNFe.ICMSTot_vTotTrib = nfe.totalField.ICMSTot.vTotTrib.Replace('.', ','); if (nfe.infAdicField.infCpl != null) { objNFe.xObs = nfe.infAdicField.infCpl.Replace(";", "." + Environment.NewLine); } if (nfe.totalField.ISSQNtot != null) { objNFe.ISSQNtot_vBC = nfe.totalField.ISSQNtot.vBC.Replace('.', ','); objNFe.ISSQNtot_vServ = nfe.totalField.ISSQNtot.vServ.Replace('.', ','); objNFe.ISSQNtot_vISS = nfe.totalField.ISSQNtot.vISS.Replace('.', ','); } int iCount = 1; // if (Acesso.IMPRIMI_FATURA) { if (nfe.cobrField != null) { string sDupl = "Nº:{0}-{1}-R${2}"; objNFe.xDuplicatas = ""; string sDup = ""; foreach (TNFeInfNFeCobrDup dupli in nfe.cobrField.dup) { if (Acesso.NM_EMPRESA.Equals("GIWA")) { sDup = dupli.nDup.ToString().Insert(dupli.nDup.Count() - 1, "-"); } else { sDup = dupli.nDup.ToString(); } objNFe.xDuplicatas += string.Format(sDupl, sDup, Convert.ToDateTime(dupli.dVenc).ToString("dd/MM/yy"), Convert.ToDecimal(dupli.vDup.Replace(".", ",")).ToString("#0.00").Replace(".", ",")).PadRight(33, ' ') + "|"; if (iCount == 3) { objNFe.xDuplicatas += Environment.NewLine; } iCount++; if (iCount > 3) { iCount = 1; } } } } objNFe.xDupli = objNFe.xDuplicatas; objNFe.Produtos = new List <Produto>(); Produto prod = null; iCount = 1; foreach (det item in nfe.lDet) { prod = new Produto(); prod.count = iCount; iCount++; prod.ide_nNF = objNFe.ide_nNF; prod.cProd = item.prodField.cProd.ToString().Trim(); prod.xProd = item.prodField.xProd; prod.ncm = item.prodField.NCM; prod.cfop = item.prodField.CFOP; prod.uCom = item.prodField.uCom; prod.qCom = PopulaDs.FormataQtdeComercial(item.prodField.qCom.ToString().Replace('.', ',')); prod.vProd = item.prodField.vProd.Replace('.', ','); prod.vUnCom = item.prodField.vUnCom.Replace('.', ','); prod.cEAN = item.prodField.cEAN; prod.xObs = item.infAdProd == null ? "" : item.infAdProd; object icms = item.impostoField.Items.FirstOrDefault(c => c.GetType() == typeof(TNFeInfNFeDetImpostoICMS)); if (icms != null) { try { prod.vBC = (icms as TNFeInfNFeDetImpostoICMS).Item.GetPropertyValue("vBC").ToString().Replace('.', ',');; } catch (Exception) { } try { prod.vICMS = (icms as TNFeInfNFeDetImpostoICMS).Item.GetPropertyValue("vICMS").ToString().Replace('.', ',');; } catch (Exception) { } try { prod.pICMS = (icms as TNFeInfNFeDetImpostoICMS).Item.GetPropertyValue("pICMS").ToString().Replace('.', ','); } catch (Exception) { } string cst = ""; try { cst = (icms as TNFeInfNFeDetImpostoICMS).Item.GetPropertyValue("CST").ToString(); } catch (Exception) { cst = (icms as TNFeInfNFeDetImpostoICMS).Item.GetPropertyValue("CSOSN").ToString(); } cst = (icms as TNFeInfNFeDetImpostoICMS).Item.GetPropertyValue("orig").ToString() + cst; prod.cst = cst; } object ipi = item.impostoField.Items.FirstOrDefault(c => c.GetType() == typeof(TNFeInfNFeDetImpostoIPI)); if (ipi != null) { try { prod.vIPI = (ipi as TNFeInfNFeDetImpostoIPI).Item.GetPropertyValue("vIPI").ToString().Replace('.', ','); } catch (Exception) { } try { prod.pIPI = (ipi as TNFeInfNFeDetImpostoIPI).Item.GetPropertyValue("pIPI").ToString().Replace('.', ','); } catch (Exception) { } } objNFe.Produtos.Add(prod); } Byte[] bimagem = SalvaCodBarras(objNFe.Id); rowImg.cod_barras = bimagem; rowImg.LogoTipo = Util.CarregaLogoEmpresa(); rowImg.id = objNFe.Id; if (Convert.ToBoolean(Acesso.VISUALIZA_HORA_DANFE)) { rowImg.hora_impressao = DateTime.Now.ToString("HH:mm"); } if (objNFe.tpEmis == "2") { objNFe.dadosNFe = this.GeraChaveDadosNFe(objNFe); Byte[] bImagemDadosNfe = SalvaCodBarras(objNFe.dadosNFe); rowImg.cod_barras_contingencia = bImagemDadosNfe; } dsImg.Imagens.Rows.Add(rowImg); objNFeToReport.Add(objNFe); } }
public bool ExecuteEvento() { try { XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces(); nameSpaces.Add("", ""); nameSpaces.Add("", "http://www.portalfiscal.inf.br/mdfe"); XmlSerializer xs = new XmlSerializer(typeof(TEvento)); MemoryStream memory = new MemoryStream(); XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8); xs.Serialize(xmltext, evento, nameSpaces); UTF8Encoding encoding = new UTF8Encoding(); string sEvento = encoding.GetString(memory.ToArray()); sEvento = sEvento.Substring(1); belAssinaXml Assinatura = new belAssinaXml(); sEvento = Assinatura.ConfigurarArquivo(sEvento, "infEvento", Acesso.cert_CTe); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(sEvento); string sPath = Pastas.PROTOCOLOS + "\\" + objPesquisa.chaveMDFe + "_ped-can-mdfe.xml"; if (File.Exists(sPath)) { File.Delete(sPath); } xDoc.Save(sPath); try { belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/mdfe", Pastas.SCHEMA_MDFe + "\\eventoMDFe_v1.00.xsd", sPath); } catch (Exception ex) { throw ex; } #region Cancelar Cte XmlDocument doc = new XmlDocument(); doc.Load(sPath); string sRetorno = Execute(doc); XDocument xRet = XDocument.Parse(sRetorno); xRet.Save(sPath); retorno = SerializeClassToXml.DeserializeClasse <TRetEvento>(sPath); if (retorno.infEvento.cStat != "135") { File.Delete(sPath); } sMessage = string.Format("Codigo do Retorno: {0}{1}Motivo: {2}{1}Chave: {3}{1}Protocolo: {4}{1}", retorno.infEvento.cStat, Environment.NewLine, retorno.infEvento.xMotivo, retorno.infEvento.chMDFe, retorno.infEvento.nProt); if (retorno.infEvento.cStat == "135") { return(true); } else { return(false); } #endregion } catch (Exception ex) { throw ex; } }
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; } }
public string GetSequenciaNota(string sIMPrestador, string sCD_NFSEQ) { try { int iSeqRetorno = 0; ConsultaSeqRps consulta = new ConsultaSeqRps(); consulta.Cabecalho = new CabecalhoSeq(); consulta.Cabecalho.CodCid = daoUtil.GetCodigoSiafiByNome(Acesso.CIDADE_EMPRESA); consulta.Cabecalho.CPFCNPJRemetente = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA.ToString()); consulta.Cabecalho.IMPrestador = sIMPrestador; consulta.Cabecalho.SeriePrestacao = "99"; consulta.Cabecalho.Versao = "1"; string sPath = Pastas.PROTOCOLOS + "\\Busca_SeqNFSe_Camp_" + sCD_NFSEQ + ".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"); String sXML = null; XmlSerializer x = new XmlSerializer(consulta.GetType()); MemoryStream memoryStream = new MemoryStream(); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); x.Serialize(xmlTextWriter, consulta, nameSpaces); memoryStream = (MemoryStream)xmlTextWriter.BaseStream; UTF8Encoding encoding = new UTF8Encoding(); sXML = encoding.GetString(memoryStream.ToArray()); sXML = sXML.Substring(1); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(sXML); xDoc.Save(sPath); if (Acesso.TP_AMB_SERV == 1) { lt.ClientCertificates.Add(Acesso.cert_NFs); } string sXmlRet = lt.consultarSequencialRps(sXML); if (!string.IsNullOrEmpty(sXmlRet)) { sPath = Pastas.PROTOCOLOS + "\\Retorno_SeqNFSe_Camp_" + sCD_NFSEQ + ".xml"; xDoc = new XmlDocument(); xDoc.LoadXml(sXmlRet); xDoc.Save(sPath); //Deserializa o retorno do webservice. XmlSerializer deserializer = new XmlSerializer(typeof(RetornoEnvioLoteRPS)); RetornoConsultaSeqRps ret = SerializeClassToXml.DeserializeClasse <RetornoConsultaSeqRps>(sPath); iSeqRetorno = Convert.ToInt32(ret.Cabecalho.NroUltimoRps) + 1; } return(iSeqRetorno.ToString()); } catch (Exception ex) { throw ex; } }
public DadosRetorno buscaRetorno() { string sDados = consultaNFe(); XmlDocument xmlConsulta = new XmlDocument(); XmlDocument xret = new XmlDocument(); try { if (Acesso.TP_EMIS == 1) { switch (Acesso.xUFtoWS) { case "SP": { if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_SP.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_SP.NfeConsulta2(); HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_SP.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_SP.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } else { HLP.GeraXml.WebService.v2_Producao_NFeConsulta_SP.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Producao_NFeConsulta_SP.NfeConsulta2(); HLP.GeraXml.WebService.v2_Producao_NFeConsulta_SP.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_NFeConsulta_SP.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } } break; case "RS": { if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_RS.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_RS.NfeConsulta2(); HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_RS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_RS.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } else { HLP.GeraXml.WebService.v2_Producao_NFeConsulta_RS.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Producao_NFeConsulta_RS.NfeConsulta2(); HLP.GeraXml.WebService.v2_Producao_NFeConsulta_RS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_NFeConsulta_RS.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } } break; case "MS": { if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_MS.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_MS.NfeConsulta2(); HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_MS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeConsulta_MS.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } else { HLP.GeraXml.WebService.v2_Producao_NFeConsulta_MS.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Producao_NFeConsulta_MS.NfeConsulta2(); HLP.GeraXml.WebService.v2_Producao_NFeConsulta_MS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_NFeConsulta_MS.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } } break; case "SVRS": { if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.V2_Homologacao_Consulta_SVRS.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.V2_Homologacao_Consulta_SVRS.NfeConsulta2(); HLP.GeraXml.WebService.V2_Homologacao_Consulta_SVRS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.V2_Homologacao_Consulta_SVRS.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } else { HLP.GeraXml.WebService.V2_Producao_Consulta_SVRS.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.V2_Producao_Consulta_SVRS.NfeConsulta2(); HLP.GeraXml.WebService.V2_Producao_Consulta_SVRS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.V2_Producao_Consulta_SVRS.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } } break; case "MG": { if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_Homologacao_NfeConsultaProtocolo_MG.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NfeConsultaProtocolo_MG.NfeConsulta2(); HLP.GeraXml.WebService.v2_Homologacao_NfeConsultaProtocolo_MG.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NfeConsultaProtocolo_MG.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } else { HLP.GeraXml.WebService.v2_Producao_NfeConsultaProtocolo_MG.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_Producao_NfeConsultaProtocolo_MG.NfeConsulta2(); HLP.GeraXml.WebService.v2_Producao_NfeConsultaProtocolo_MG.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_NfeConsultaProtocolo_MG.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } } break; } } else if (Acesso.TP_EMIS == 3) { if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeConsulta.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeConsulta.NfeConsulta2(); HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeConsulta.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeConsulta.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } else { HLP.GeraXml.WebService.v2_SCAN_Producao_NFeConsulta.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeConsulta.NfeConsulta2(); HLP.GeraXml.WebService.v2_SCAN_Producao_NFeConsulta.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeConsulta.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } } else if (Acesso.TP_EMIS == 6) { if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_SVC_Homologacao_NfeConsultaProtocolo.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_SVC_Homologacao_NfeConsultaProtocolo.NfeConsulta2(); HLP.GeraXml.WebService.v2_SVC_Homologacao_NfeConsultaProtocolo.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SVC_Homologacao_NfeConsultaProtocolo.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } else { HLP.GeraXml.WebService.v2_SVC_Producao_NfeConsultaProtocolo.NfeConsulta2 ws2 = new HLP.GeraXml.WebService.v2_SVC_Producao_NfeConsultaProtocolo.NfeConsulta2(); HLP.GeraXml.WebService.v2_SVC_Producao_NfeConsultaProtocolo.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SVC_Producao_NfeConsultaProtocolo.nfeCabecMsg(); cabec.versaoDados = sversaoLayoutCons; belUF objUf = new belUF(); cabec.cUF = objUf.RetornaCUF(Acesso.xUF); ws2.nfeCabecMsgValue = cabec; ws2.ClientCertificates.Add(Acesso.cert_NFe); xmlConsulta.LoadXml(sDados); XmlNode xNodeConsulta = xmlConsulta.DocumentElement; xmlConsulta.LoadXml(ws2.nfeConsultaNF2(xNodeConsulta).OuterXml); } } string sPathCons = Pastas.PROTOCOLOS + "\\ConsultaNFe_" + objPesquisa.sCD_NFSEQ + ".xml"; xmlConsulta.Save(sPathCons); retConsSitNFe objConsulta = SerializeClassToXml.DeserializeClasse <retConsSitNFe>(sPathCons); return(CarregaDadosRetorno(objConsulta)); } catch (Exception) { throw; } }
public void EfetuaCancelamento(belPesquisaNotas _objPesquisa, string sJust, int iNumEvento) { this.objPesquisa = _objPesquisa; string sDados = NFeDadosMsg2(_objPesquisa, sJust, iNumEvento); XmlDocument xRet = new XmlDocument(); if (Acesso.TP_EMIS == 1) { switch (Acesso.xUFtoWS) { case "SP": { #region Regiao_SP if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_SP.RecepcaoEvento ws2 = new WebService.v2_Producao_NFeRecepcaoEvento_SP.RecepcaoEvento(); HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_SP.nfeCabecMsg cabec = new WebService.v2_Producao_NFeRecepcaoEvento_SP.nfeCabecMsg(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.nfeCabecMsg(); HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.RecepcaoEvento(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } #endregion } break; case "RS": { #region Regiao_RS if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_RS.RecepcaoEvento ws2 = new WebService.v2_Producao_NFeRecepcaoEvento_RS.RecepcaoEvento(); HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_RS.nfeCabecMsg cabec = new WebService.v2_Producao_NFeRecepcaoEvento_RS.nfeCabecMsg(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.nfeCabecMsg(); HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.RecepcaoEvento(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } #endregion } break; case "MS": { #region Regiao_SP if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.nfeCabecMsg(); HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.RecepcaoEvento(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } if (Acesso.TP_AMB == 2) { throw new Exception("Não implementado"); } #endregion } break; case "SVRS": { #region Regiao_SP if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.nfeCabecMsg(); HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.RecepcaoEvento(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } if (Acesso.TP_AMB == 2) { throw new Exception("Não implementado para o RJ em modo de homologação."); } #endregion } break; case "MG": { #region Regiao_MG if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.nfeCabecMsg(); HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.RecepcaoEvento(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.nfeCabecMsg(); HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.RecepcaoEvento(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } #endregion } break; } } else if (Acesso.TP_EMIS == 3) { #region SCAN if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.NfeCancelamento2 ws2 = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.NfeCancelamento2(); HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.nfeCabecMsg(); cabec.versaoDados = Acesso.versaoNFe; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; xRet.LoadXml(ws2.nfeCancelamentoNF2(xNodeCanc).OuterXml); } if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.NfeCancelamento2 ws2 = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.NfeCancelamento2(); HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.nfeCabecMsg(); cabec.versaoDados = Acesso.versaoNFe; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; xRet.LoadXml(ws2.nfeCancelamentoNF2(xNodeCanc).OuterXml); } #endregion } else if (Acesso.TP_EMIS == 6) { #region SCAN if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.v2_SVC_Producao_RecepcaoEvento.RecepcaoEvento ws2 = new WebService.v2_SVC_Producao_RecepcaoEvento.RecepcaoEvento(); HLP.GeraXml.WebService.v2_SVC_Producao_RecepcaoEvento.nfeCabecMsg cabec = new WebService.v2_SVC_Producao_RecepcaoEvento.nfeCabecMsg(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } if (Acesso.TP_AMB == 2) { HLP.GeraXml.WebService.v2_SVC_Homologacao_RecepcaoEvento.RecepcaoEvento ws2 = new WebService.v2_SVC_Homologacao_RecepcaoEvento.RecepcaoEvento(); HLP.GeraXml.WebService.v2_SVC_Homologacao_RecepcaoEvento.nfeCabecMsg cabec = new WebService.v2_SVC_Homologacao_RecepcaoEvento.nfeCabecMsg(); cabec.versaoDados = "1.00"; cabec.cUF = Acesso.cUF.ToString(); ws2.ClientCertificates.Add(Acesso.cert_NFe); ws2.nfeCabecMsgValue = cabec; XmlDocument xmlCanc = new XmlDocument(); xmlCanc.LoadXml(sDados); XmlNode xNodeCanc = xmlCanc.DocumentElement; string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml; xRet.LoadXml(sRet); } #endregion } string sPath = Pastas.PROTOCOLOS + "\\" + objPesquisa.sCD_NFSEQ + "_Ret_Pedcan" + DateTime.Now.ToString("ddMMyyHHmmss") + ".xml"; xRet.Save(sPath); belRetEventoCancelamento objRet = SerializeClassToXml.DeserializeClasse <belRetEventoCancelamento>(sPath); if (objRet.retEvento.infEvento.cStat == "573") { objRetorno = new DadosRetorno(); iNumEvento = iNumEvento + 1; EfetuaCancelamento(_objPesquisa, sJust, iNumEvento); } else { objRetorno = CarregaDadosRetorno(objRet); } }
private void btnImpressao_Click(object sender, EventArgs e) { try { List <PesquisaManifestosModel> objSelect = this.objPesquisa.resultado.Where(c => c.bEnviado == true && c.recibo != "" && c.bSeleciona && c.protocolo != "" ).ToList(); dsMdfe = new dsMDFe(); foreach (PesquisaManifestosModel item in objSelect) { rowMdfe = dsMdfe.MDFe.NewMDFeRow(); Byte[] bimagem = SalvaCodBarras(item.chaveMDFe); rowMdfe.barras = bimagem; rowMdfe.logotipo = Util.CarregaLogoEmpresa(); string sPath = ""; if (item.bCancelado) { sPath = Util.BuscaCaminhoArquivoXml(item.chaveMDFe, 2, true); } else { sPath = Util.BuscaCaminhoArquivoXml(item.chaveMDFe, 2); } XmlDocument xml = new XmlDocument(); xml.Load(sPath); XmlNodeList node = xml.GetElementsByTagName("infModal"); mdfeProc objEnvi = SerializeClassToXml.DeserializeClasse <mdfeProc>(sPath); rodo objRodo = SerializeClassToXml.DeserializeClasseString <rodo>(node[0].InnerXml.ToString()); rowMdfe.xEmpresa = string.Format("{0}{10}CNPJ:{1} - IE:{2}, RNTRC:{3} - Logradouro:{4}, nº{5} - Bairro:{6}, {7}/{8} Cep:{9}", objEnvi.enviMDFe.MDFe.infMDFe.emit.xNome, objEnvi.enviMDFe.MDFe.infMDFe.emit.CNPJ, objEnvi.enviMDFe.MDFe.infMDFe.emit.IE, objRodo.RNTRC, objEnvi.enviMDFe.MDFe.infMDFe.emit.enderEmit.xLgr, objEnvi.enviMDFe.MDFe.infMDFe.emit.enderEmit.nro, objEnvi.enviMDFe.MDFe.infMDFe.emit.enderEmit.xBairro, objEnvi.enviMDFe.MDFe.infMDFe.emit.enderEmit.UF, objEnvi.enviMDFe.MDFe.infMDFe.emit.enderEmit.xMun, objEnvi.enviMDFe.MDFe.infMDFe.emit.enderEmit.CEP, Environment.NewLine); rowMdfe.ufCarreg = objEnvi.enviMDFe.MDFe.infMDFe.ide.UFIni; rowMdfe.numero = item.numero; rowMdfe.chave = item.chaveMDFe; rowMdfe.protocolo = item.protocolo; rowMdfe.serie = objEnvi.enviMDFe.MDFe.infMDFe.ide.serie; rowMdfe.dataEmissao = Convert.ToDateTime(objEnvi.enviMDFe.MDFe.infMDFe.ide.dhEmi).ToShortDateString(); rowMdfe.CIOT = objRodo.CIOT; rowMdfe.qtdeCT = objEnvi.enviMDFe.MDFe.infMDFe.tot.qCT == null ? "0" : objEnvi.enviMDFe.MDFe.infMDFe.tot.qCT.ToString(); rowMdfe.qtdeCTE = objEnvi.enviMDFe.MDFe.infMDFe.tot.qCTe == null ? "0" : objEnvi.enviMDFe.MDFe.infMDFe.tot.qCTe; rowMdfe.qtdeNF = objEnvi.enviMDFe.MDFe.infMDFe.tot.qNF == null ? "0" : objEnvi.enviMDFe.MDFe.infMDFe.tot.qNF; rowMdfe.qtdeNFe = objEnvi.enviMDFe.MDFe.infMDFe.tot.qNFe == null ? "0" : objEnvi.enviMDFe.MDFe.infMDFe.tot.qNFe; rowMdfe.pesoTotal = objEnvi.enviMDFe.MDFe.infMDFe.tot.qCarga; rowMdfe.veicPlaca = objRodo.veicTracao.placa + Environment.NewLine; foreach (var v in objRodo.veicReboque) { rowMdfe.veicPlaca += v.placa + Environment.NewLine; } if (objRodo.veicTracao.prop != null) { rowMdfe.veicRNTRC = objRodo.veicTracao.prop.RNTRC + Environment.NewLine; } foreach (var v in objRodo.veicReboque) { if (v.prop != null) { rowMdfe.veicRNTRC += v.prop.RNTRC + Environment.NewLine; } } if (objRodo.veicTracao.condutor != null) { foreach (var cond in objRodo.veicTracao.condutor) { rowMdfe.Condutor_cpf += cond.CPF + Environment.NewLine; rowMdfe.Condutor_Nome += cond.xNome + Environment.NewLine; } } if (objRodo.valePed != null) { foreach (var vale in objRodo.valePed) { rowMdfe.Pedagio_Resp_cnp += vale.CNPJPg + Environment.NewLine; rowMdfe.Pedagio_Forn_cnpj += vale.CNPJForn + Environment.NewLine; rowMdfe.Pedagio_comprovante += vale.nCompra + Environment.NewLine; } } string sDocEletronico = "{0} - Chave: {1}{2}"; rowMdfe.documentos_Fiscais = ""; foreach (var doc in objEnvi.enviMDFe.MDFe.infMDFe.infDoc) { if (doc.infCTe != null) { foreach (var cte in doc.infCTe) { rowMdfe.documentos_Fiscais += string.Format(sDocEletronico, "CTe", cte.chCTe, Environment.NewLine); } } if (doc.infNFe != null) { foreach (var nfe in doc.infNFe) { rowMdfe.documentos_Fiscais += string.Format(sDocEletronico, "NFe", nfe.chNFe, Environment.NewLine); } } if (doc.infNF != null) { foreach (var nf in doc.infNF) { rowMdfe.documentos_Fiscais += string.Format("{0} - CNPJ{1} - Serie:{2} - Nº {3}{4}", "NF", nf.CNPJ, nf.serie, nf.nNF, Environment.NewLine); } } if (doc.infCT != null) { foreach (var ct in doc.infCT) { rowMdfe.documentos_Fiscais += string.Format("{0} - Serie:{1} - Nº {2}{3}", "CT", ct.serie, ct.nCT, Environment.NewLine); } } } if (objEnvi.enviMDFe.MDFe.infMDFe.infAdic != null) { rowMdfe.observacao = objEnvi.enviMDFe.MDFe.infMDFe.infAdic.infCpl; } if (item.bCancelado) { rowMdfe.observacao = "***** CONHECIMENTO CANCELADO *****" + Environment.NewLine + rowMdfe.observacao; } // objPrint.ldados.Add(obj); dsMdfe.MDFe.Rows.Add(rowMdfe); } Print(); } catch (Exception ex) { throw new HLPexception(ex); } }
public void BuscarRetorno() { daoManifesto.AlteraUltimoRetorno(objPesquisa.sequencia); string sRetorno = string.Empty; XmlNode xNodeRet = xmlConsulta.DocumentElement; if (Acesso.TP_AMB == 1) { HLP.GeraXml.WebService.MDFe_Producao_RetRecepcao.mdfeCabecMsg cabec = new WebService.MDFe_Producao_RetRecepcao.mdfeCabecMsg(); HLP.GeraXml.WebService.MDFe_Producao_RetRecepcao.MDFeRetRecepcao ws = new WebService.MDFe_Producao_RetRecepcao.MDFeRetRecepcao(); cabec.cUF = Acesso.cUF.ToString(); cabec.versaoDados = Acesso.versaoMDFe; ws.mdfeCabecMsgValue = cabec; ws.ClientCertificates.Add(Acesso.cert_CTe); sRetorno = ws.mdfeRetRecepcao(xNodeRet).OuterXml; } else { HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.mdfeCabecMsg cabec = new WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.mdfeCabecMsg(); HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.MDFeRetRecepcao ws = new WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.MDFeRetRecepcao(); cabec.cUF = Acesso.cUF.ToString(); cabec.versaoDados = Acesso.versaoMDFe; ws.mdfeCabecMsgValue = cabec; ws.ClientCertificates.Add(Acesso.cert_CTe); sRetorno = ws.mdfeRetRecepcao(xNodeRet).OuterXml; } if (sRetorno != "") { string sPath = Pastas.PROTOCOLOS + Convert.ToInt32(objPesquisa.numero) + "-pro-rec.xml"; if (File.Exists(sPath)) { File.Delete(sPath); } xmlRetorno = new XmlDocument(); xmlRetorno.LoadXml(sRetorno); xmlRetorno.Save(sPath); TRetConsReciMDFe recepacao = SerializeClassToXml.DeserializeClasse <TRetConsReciMDFe>(sPath); sMessage = string.Format("Sequencia: {0}{4}Numero: {1}{4}Motivo: {2}{4}Status: {3}{4}", objPesquisa.sequencia, objPesquisa.numero, recepacao.protMDFe != null ? recepacao.protMDFe.infProt.xMotivo : recepacao.xMotivo, recepacao.cStat, Environment.NewLine); if (recepacao.cStat != "104") { daoManifesto.LimpaRecibo(objPesquisa.sequencia); } else { if (recepacao.protMDFe != null) { //if (recepacao.cStat == "104") //{ // string sRec = recepacao.protMDFe.infProt.xMotivo.Substring(recepacao.protMDFe.infProt.xMotivo.IndexOf("nRec:"), 20).Replace("nRec:", ""); // daoManifesto.gravaRecibo(sRec, objPesquisa.sequencia); // daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S"); // daoManifesto.AlteraUltimoRetornoNULL(objPesquisa.sequencia); // //IncluiTagInfProc(); //} //else if (recepacao.protMDFe.infProt.cStat == "100") { daoManifesto.gravaProtocolo(recepacao.protMDFe.infProt.nProt, objPesquisa.sequencia); daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S"); IncluiTagInfProc(); } else if (recepacao.protMDFe.infProt.cStat == "101") //CANCELADO. { daoManifesto.gravaProtocolo(recepacao.nRec, objPesquisa.sequencia); } else if (recepacao.protMDFe.infProt.cStat == "204") //DUPLICADO. { string sRec = recepacao.protMDFe.infProt.xMotivo.Substring(recepacao.protMDFe.infProt.xMotivo.IndexOf("nRec:"), 20).Replace("nRec:", ""); daoManifesto.gravaRecibo(sRec, objPesquisa.sequencia); daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S"); //IncluiTagInfProc(); daoManifesto.AlteraUltimoRetornoNULL(objPesquisa.sequencia); // BuscarRetorno(); } else if (recepacao.protMDFe.infProt.cStat == "105") //LOTE EM PROCESSAMENTO. { daoManifesto.gravaProtocolo(recepacao.nRec, objPesquisa.sequencia); } else { daoManifesto.LimpaRecibo(objPesquisa.sequencia); } } else { daoManifesto.LimpaRecibo(objPesquisa.sequencia); } } } }
private string BuscaRetornoWebService(tcIdentificacaoPrestador Prestador) { try { if (Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES) { string sVerificacao = Pastas.GINFES + this.Protocolo + ".txt"; bool bValida = false; if (File.Exists(sVerificacao)) { StreamReader sr = new StreamReader(sVerificacao); string sdt = sr.ReadToEnd(); sr.Close(); DateTime dtEnvio = Convert.ToDateTime(sdt).AddMinutes(6); DateTime dtAtual = DateTime.Now; if (dtEnvio > dtAtual) { throw new Exception("Aguarde mais alguns minutos para o buscar o retorno da Nota. Aproximadamente 6 minutos após o envio."); } else { bValida = true; } } else { bValida = true; } string sretorno = ""; if (bValida) { if (Acesso.TP_AMB_SERV == 2) { WebService.Itu_servicos_Homologacao.ServiceGinfesImplService teste = new WebService.Itu_servicos_Homologacao.ServiceGinfesImplService(); teste.ClientCertificates.Add(Acesso.cert_NFs); teste.Timeout = 60000; string sret = teste.ConsultarSituacaoLoteRpsV3(NfeCabecMsg(), MontaXmlConsultarSituacaoLoteRps(Prestador)); WebService.Itu_servicos_Homologacao.ServiceGinfesImplService objtrans = new WebService.Itu_servicos_Homologacao.ServiceGinfesImplService(); objtrans.ClientCertificates.Add(Acesso.cert_NFs); objtrans.Timeout = 60000; return(objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador))); } else if (Acesso.TP_AMB_SERV == 1) { ConsultarSituacaoLoteRpsResposta objResposta; try { WebService.Itu_servicos_Producao.ServiceGinfesImplService teste = new WebService.Itu_servicos_Producao.ServiceGinfesImplService(); teste.ClientCertificates.Add(Acesso.cert_NFs); teste.Timeout = 60000; string sret = teste.ConsultarSituacaoLoteRpsV3(NfeCabecMsg(), MontaXmlConsultarSituacaoLoteRps(Prestador)); XmlDocument doc = new XmlDocument(); doc.LoadXml(sret); string sNmFile = Pastas.PROTOCOLOS + "//ConsultaSitLoteRps_" + this.Protocolo + ".xml"; if (File.Exists(sNmFile)) { File.Delete(sNmFile); } doc.Save(sNmFile); objResposta = SerializeClassToXml.DeserializeClasse <ConsultarSituacaoLoteRpsResposta>(sNmFile); } catch (Exception ex) { throw ex; } if (objResposta != null) { if ((objResposta.Situacao == 4) || (objResposta.Situacao == 3)) { WebService.Itu_servicos_Producao.ServiceGinfesImplService objtrans = new WebService.Itu_servicos_Producao.ServiceGinfesImplService(); objtrans.ClientCertificates.Add(Acesso.cert_NFs); objtrans.Timeout = 60000; sretorno = objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador)); } else { if (objResposta.Situacao == 1) { throw new Exception("Lote ainda não recebido."); } else if (objResposta.Situacao == 2) { throw new Exception("Lote ainda não processado."); } } } } return(sretorno); } else { throw new Exception("Cadastro de Empresa não configurado para enviar NFe-serviço"); } } else { WebService.riodasostras_Producao.Nfse nfse = new WebService.riodasostras_Producao.Nfse(); nfse.ClientCertificates.Add(Acesso.cert_NFs); nfse.Timeout = 60000; return(nfse.ConsultarLoteRps(MontaXmlConsultaLote2(Prestador))); } } catch (Exception ex) { throw ex; } }
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; } }