Example #1
0
        public belCancelaCte PopulaDadosCancelamento(string sCodConhecimento, string sJustificativa)
        {
            try
            {
                belCancelaCte objBelCancelaCte = new belCancelaCte();
                DataTable dt = BuscaDadosCancelamento(sCodConhecimento, sJustificativa);
                foreach (DataRow dr in dt.Rows)
                {
                    objBelCancelaCte.versao = Acesso.versaoCTe;
                    objBelCancelaCte.Id = "ID" + dr["chCTe"].ToString();
                    objBelCancelaCte.tpAmb = Acesso.TP_AMB.ToString();
                    objBelCancelaCte.xServ = "CANCELAR";
                    objBelCancelaCte.chCTe = dr["chCTe"].ToString();
                    objBelCancelaCte.nProt = dr["nProt"].ToString();
                    objBelCancelaCte.xJust = sJustificativa;
                }

                return objBelCancelaCte;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
Example #2
0
        private void CancelaCte()
        {
            try
            {
                daoBuscaDadosGerais objdaoDadosGerais = new daoBuscaDadosGerais();
                daoGravaDadosRetorno objDadosRetorno = new daoGravaDadosRetorno();
                belCancelaCte objCancelaCte = new belCancelaCte();


                string sJustificativa = txtJust.Text;
                belCancelaCte objCte = objCancelaCte.PopulaDadosCancelamento(sCodConhecimento, sJustificativa);

                belCriaXml objXml = new belCriaXml();
                HLP.GeraXml.bel.CTe.Evento.TRetEvento ret = objXml.GerarXmlCancelamento(objCte);


                if (ret.infEvento.cStat == "135")
                {
                    objDadosRetorno.GravarReciboCancelamento(sCodConhecimento, ret.infEvento.nProt, sJustificativa);
                    objXml.SalvaArquivoPastaCancelado(objdaoDadosGerais.BuscaChaveRetornoCteSeq(objCte.chCTe));
                }

                string sMessageRetorno = string.Format("Codigo do Retorno: {0}{1}Motivo: {2}{1}Chave: {3}{1}Protocolo: {4}{1}",
                    ret.infEvento.cStat,
                    Environment.NewLine,
                    ret.infEvento.xMotivo,
                    ret.infEvento.chCTe,
                    ret.infEvento.nProt);

                KryptonMessageBox.Show(sMessageRetorno, Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public belCancelaCte PopulaDadosCancelamento(string sCodConhecimento, string sJustificativa)
        {
            try
            {
                belCancelaCte objBelCancelaCte = new belCancelaCte();
                DataTable     dt = BuscaDadosCancelamento(sCodConhecimento, sJustificativa);
                foreach (DataRow dr in dt.Rows)
                {
                    objBelCancelaCte.versao = Acesso.versaoCTe;
                    objBelCancelaCte.Id     = "ID" + dr["chCTe"].ToString();
                    objBelCancelaCte.tpAmb  = Acesso.TP_AMB.ToString();
                    objBelCancelaCte.xServ  = "CANCELAR";
                    objBelCancelaCte.chCTe  = dr["chCTe"].ToString();
                    objBelCancelaCte.nProt  = dr["nProt"].ToString();
                    objBelCancelaCte.xJust  = sJustificativa;
                }

                return(objBelCancelaCte);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public TRetEvento GerarXmlCancelamento(belCancelaCte objCancelaCte)
        {
            try
            {
                //Serialização Cancelamento
                XNamespace pf = "http://www.portalfiscal.inf.br/cte";


                XContainer envCTe = new XElement(pf + "evCancCTe",
                     new XElement(pf + "descEvento", "Cancelamento"),
                     new XElement(pf + "nProt", objCancelaCte.nProt),
                     new XElement(pf + "xJust", objCancelaCte.xJust));


                XmlDocument xmlCanc = new XmlDocument();
                xmlCanc.LoadXml(envCTe.ToString());

                // Serialização Evento
                string sVersao = Acesso.versaoCTe; // "1.00";

                TEvento evento = new TEvento();
                evento.versao = sVersao;
                evento.infEvento = new TEventoInfEvento();
                evento.infEvento.tpEvento = "110111";
                evento.infEvento.nSeqEvento = "1"; // numero de evento
                evento.infEvento.Id = "ID" + evento.infEvento.tpEvento + objCancelaCte.chCTe + evento.infEvento.nSeqEvento.PadLeft(2, '0');
                evento.infEvento.cOrgao = Convert.ToByte(Acesso.cUF);
                evento.infEvento.tpAmb = Acesso.TP_AMB == 1 ? TAmb.Item1 : TAmb.Item2;
                evento.infEvento.CNPJ = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
                evento.infEvento.chCTe = objCancelaCte.chCTe;
                evento.infEvento.dhEvento = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss");
                evento.infEvento.detEvento = new TEventoInfEventoDetEvento();
                evento.infEvento.detEvento.versaoEvento = sVersao;
                evento.infEvento.detEvento.Any = (System.Xml.XmlElement)xmlCanc.DocumentElement;

                string sEvento = "";

                XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
                nameSpaces.Add("", "");
                nameSpaces.Add("", "http://www.portalfiscal.inf.br/cte");


                //SerializeClassToXml.SerializeClasse(TEvento,)



                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();
                sEvento = encoding.GetString(memory.ToArray());
                sEvento = sEvento.Substring(1);


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

                //string sXMLfinal = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.00\"><idLote>" + nota.sCD_NFSEQ.PadLeft(15, '0')
                //                    + "</idLote>" + sEvento.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "") + "</envEvento>";

                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(sEvento);
                string sPath = Pastas.PROTOCOLOS + "\\" + objCancelaCte.chCTe + "_ped-can.xml";
                if (File.Exists(sPath))
                {
                    File.Delete(sPath);
                }
                xDoc.Save(sPath);
                try
                {
                    belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/cte", Pastas.SCHEMA_CTE + "\\eventoCTe_v2.00.xsd", sPath);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                #region Cancelar Cte


                XmlDocument doc = new XmlDocument();
                doc.Load(sPath);

                string sRetorno = CancelarCte(doc);

                XDocument xRet = XDocument.Parse(sRetorno);
                xRet.Save(sPath);
                HLP.GeraXml.bel.CTe.Evento.TRetEvento retorno = SerializeClassToXml.DeserializeClasse<HLP.GeraXml.bel.CTe.Evento.TRetEvento>(sPath);

                //List<belStatusCte> ListaStatus = TrataDadosRetorno(sRetorno);

                //foreach (belStatusCte cte in ListaStatus)
                //{
                if (retorno.infEvento.cStat != "135")
                {
                    File.Delete(sPath);
                }
                //}

                #endregion

                return retorno;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }