public MakeXMLSAT(CancelNFCE _cancelSAT, Utils.ConfigureXml _config) { config = _config; processCancel(_cancelSAT); }
public makeXmlCancel(CancelNFCE _dtNfce, Utils.ConfigureXml _config, X509Certificate2 _cert) { config = _config; dtNfce = _dtNfce; cert = _cert; processCancel(); string a = (String.Format("{0}\\{1}.xml", config.configMaquina.pathFiles , nomeXml)); xmlDoc.Save(String.Format("{0}\\{1}.xml", config.configMaquina.pathFiles , nomeXml)); assinaturaXML(); }
public string ProcessaCancel(CancelNFCE _cncNfce) { makeXmlCancel xmlData = null; try { xmlData = new makeXmlCancel(_cncNfce, config, cert); id_db = xmlData.id_banco; ManagerDB.Instance.InsertNfceStatus(id_db, (int)StatusCupom.xmlCancelamentoGerado, "XML de cancelamento gerado", ""); XmlDocument arqNfce = xmlData.xmlDoc; enviaSeFaz.verificaStatusSefaz(); if (enviaSeFaz.CancelamentoNfce(arqNfce)) ManagerDB.Instance.InsertNfceStatus(id_db, (int)StatusCupom.xmlCancelamentoEnviado, "NFCE Cancelamento", ""); } catch (ApplicationException ex) { ManagerDB.Instance.InsertNfceStatus(id_db, (int)StatusCupom.xmlCancelamentoRejeicao, "NFCE Cancelamento rejeitado", ""); Utils.Logger.getInstance.error(ex); return "NFCE Cancelamento rejeitado"; } catch (Exception e) { ManagerDB.Instance.InsertNfceStatus(id_db, (int)StatusCupom.xmlCancelamentoRejeicao, "NFCE Cancelamento rejeitado", ""); Utils.Logger.getInstance.error(e); return "NFCE Cancelamento rejeitado"; } finally { XmlDocument xmlCancel = enviaSeFaz.GetXmlCancelamento(); Utils.Logger.getInstance.error("Arquivo Cancelamento Salvo em: " + String.Format("{0}\\canceladas\\{1}.xml", config.configMaquina.pathFiles, xmlData.nomeXml)); xmlCancel.Save(String.Format("{0}\\canceladas\\{1}.xml", config.configMaquina.pathFiles, xmlData.nomeXml)); } return "NFCE Cancelamento Com sucesso"; }
public string messageCancel(string msg) { string ret = ""; try { string[] dados = msg.Split('|'); CancelNFCE cancel = new CancelNFCE(); cancel.printer = dados[0]; cancel.chaveCancelamento = dados[1]; cancel.tipoCli = dados[2]; cancel.cpf_cnpj = dados[3]; ret = processaDados.ProcessaCancel(cancel); return ret; } catch (Exception e) { Utils.Logger.getInstance.error(e); throw e; } }
public string ProcessaCancel(CancelNFCE cancel) //"F"|"J" { try { xmlData = new MakeXMLSAT(cancel, config); XmlDocument xmlSATImpressaoCancelamento = new XmlDocument(); string fileCancel = String.Format("{0}{1}\\CFe{2}.xml", config.configMaquina.pathFiles, "\\enviados", cancel.chaveCancelamento); if (File.Exists(fileCancel)) { xmlSATImpressaoCancelamento.Load(fileCancel); } else { throw new Exception("Arquivo XML CFe Original não encontrado em: " + fileCancel); } string retorno; try { retorno = gerenSAT.CancelarCFe(gerenSAT.generatorKey(), config.configSAT.ChaveAtivacao, "CFe" + cancel.chaveCancelamento, xmlData.xmlCancel.OuterXml); //TODO CONF //retorno = SatDLL.CancelarCFe(SatDLL.generatorKey(), config.configSAT.ChaveAtivacao, "CFe" + cancel.chaveCancelamento, xmlData.xmlCancel.OuterXml); //TODO CONF } catch (Exception exceptionSATDll) { throw new Exception("Erro enviando comando de Cancelamento de CFe " + exceptionSATDll.Message); } string[] tmpSplit = retorno.Split('|'); if (tmpSplit[1].Equals("07000")) { byte[] tmpByte = Convert.FromBase64String(tmpSplit[6]); String notaRet = tmpByte.ToString(); notaRet = System.Text.Encoding.UTF8.GetString(tmpByte); string xmlName = String.Format("{0}{1}\\{2}.xml", config.configMaquina.pathFiles, "\\enviados", tmpSplit[8]); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(xmlName)) { sw.Write(notaRet); sw.Flush(); } XmlDocument xmlSATImpressao = new XmlDocument(); xmlSATImpressao.LoadXml(notaRet); dadosQR = String.Format("{0}|{1}|{2}|{3}|{4}", tmpSplit[8].Substring(3), tmpSplit[7], tmpSplit[9], tmpSplit[10], tmpSplit[11]); Impressao(xmlSATImpressao, xmlSATImpressaoCancelamento, TipoImpressao.Cancelamento, cancel.printer); // dadosSatImp = new ImpressaoSAT(xmlSATImpressao, xmlSATImpressaoCancelamento, config, TipoImpressao.Cancelamento); // ImprimirEpsonNF.ImprimirNF(cancel.printer, dadosSatImp.DadosImpressao1, dadosSatImp.DadosImpressao2, dadosQR, dadosSatImp.DadosQrCodeCancelamento, "", true, true); } else { throw new Exception(String.Format("Erro processando SAT Cancelamento {0}{1}{2}{3}{4}", tmpSplit[1], tmpSplit[2], tmpSplit[3], tmpSplit[4], tmpSplit[5])); } return "SAT: Cancelamento Com sucesso"; } catch (Exception ex) { throw new Exception("Erro processabdo Cancelamento " + ex.Message); } }
public void processCancel(CancelNFCE _cancelSAT) { try { //xmlSATImpressaoCancelamento = new XmlDocument(); //string fileCancel = String.Format("{0}{1}\\CFe{2}.xml", config.configMaquina.pathFiles, "\\enviados", _cancelSAT.chaveCancelamento); //if (File.Exists(fileCancel)) //{ // this.xmlCancel.Load(fileCancel); //} //else //{ // throw new Exception("Arquivo XML CFe Original não encontrado em: " + fileCancel); //} xmlWriter = new XmlTextWriter(XmlString); //cabeçalho xmlWriter.WriteStartElement("CFeCanc"); xmlWriter.WriteStartElement("infCFe"); xmlWriter.WriteAttributeString("chCanc", "CFe" + _cancelSAT.chaveCancelamento); xmlWriter.WriteStartElement("ide"); xmlWriter.WriteElementString("CNPJ", config.configSAT.CNPJ_SoftwareHouse); xmlWriter.WriteElementString("signAC", config.configSAT.IDE_signAC); xmlWriter.WriteElementString("numeroCaixa", config.configSAT.IDE_NumeroCaixa); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("emit"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("dest"); if (!(String.IsNullOrEmpty(_cancelSAT.cpf_cnpj))) { if (_cancelSAT.tipoCli.Equals("F")) xmlWriter.WriteElementString("CPF", _cancelSAT.cpf_cnpj); else if (_cancelSAT.tipoCli.Equals("J")) xmlWriter.WriteElementString("CNPJ", _cancelSAT.cpf_cnpj); } xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("total"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.Close(); //XmlDocument xmlCancel = new XmlDocument(); xmlCancel.LoadXml(XmlString.ToString()); string xmlName = String.Format("{0}{1}\\{2}.xml", config.configMaquina.pathFiles, "\\gerados", String.Format("Cancelamento_{0}_{1}_{2}", _cancelSAT.chaveCancelamento, DateTime.Now.ToString("ddMMyyyy"), DateTime.Now.ToString("hhmmss"))); xmlCancel.Save(xmlName); } catch (Exception e) { Utils.Logger.getInstance.error(e); } }