Exemplo n.º 1
0
        public void DeserilizarEvento(object obj, ref Entidade_Recibo objDes)
        {
            Entidade_Recibo  retRecibo = new Entidade_Recibo();
            Model_NotaFiscal mNf       = new Model_NotaFiscal();
            Model_Lote       mLote     = new Model_Lote();
            XmlDocument      docRet    = new XmlDocument();

            RetReciNFe = new TRetConsReciNFe();
            StreamWriter SW;
            string       xProtNFe = string.Empty;

            object objRet = new object();

            retXmlNodeReader = new XmlNodeReader((XmlNode)obj);
            xmlDesSerializar = new XmlSerializer(typeof(TRetConsReciNFe));

            objRet = xmlDesSerializar.Deserialize(retXmlNodeReader);

            var Retorno = (TRetConsReciNFe)objRet;


            XmlNodeList xNodList = ((XmlNode)obj).ChildNodes;

            try
            {
                if (Retorno.protNFe != null)
                {
                    foreach (var Prot in Retorno.protNFe)
                    {
                        if (objDes.TpNf.Trim() == "S")
                        {
                            mNf.AtualizaRetornoNfeSaida(Prot.infProt.cStat, Prot.infProt.nProt, objDes.Loja, Prot.infProt.chNFe, Model_NotaFiscal.NotaFiscal.Saida);
                        }
                        else
                        {
                            mNf.AtualizaRetornoNfeSaida(Prot.infProt.cStat, Prot.infProt.nProt, objDes.Loja, Prot.infProt.chNFe, Model_NotaFiscal.NotaFiscal.Entrada);
                        }

                        for (int i = 0; i < xNodList.Count; i++)
                        {
                            if (xNodList.Item(i).Name.Equals("protNFe"))
                            {
                                XmlNode     xNodListProc  = xNodList.Item(i).FirstChild;
                                XmlNodeList xNodListProc2 = xNodListProc.ChildNodes;

                                for (int j = 0; j < xNodListProc2.Count; j++)
                                {
                                    if (xNodListProc2.Item(j).Name.Equals("chNFe"))
                                    {
                                        xProtNFe = xNodList.Item(i).OuterXml;
                                        break;
                                    }
                                }
                            }
                        }
                        mLote.ItemLoteNfe(Prot.infProt.cStat, Prot.infProt.chNFe, xProtNFe);
                        mLote.LoteProcessado(Retorno.cStat, Convert.ToDateTime(Prot.infProt.dhRecbto), Retorno.nRec);
                    }
                }
                else
                {
                    mLote.LoteProcessado(Retorno.cStat, Convert.ToDateTime(Retorno.dhRecbto), Retorno.nRec);
                }

                if (!Directory.Exists(@"C:\NFe\Retorno_Proc_NFe\"))
                {
                    Directory.CreateDirectory(@"C:\NFe\Retorno_Proc_NFe\");
                }
                FileStream FS = new FileStream(@"C:\NFe\Retorno_Proc_NFe\" + string.Format("{0:MMddyyyy}", DateTime.Now.Date) + "_" + Retorno.nRec.Trim() + ".xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                SW = new StreamWriter(FS);

                xmlDesSerializar.Serialize(SW, Retorno);
            }
            catch (Exception Ex)
            {
                Mensagem.MensagemErro(Mensagem.TipoMensagem.RetAutoriz, "Saida", Ex.Message.ToString());

                if (!Directory.Exists(@"C:\NFe\Retorno_Proc_NFe\"))
                {
                    Directory.CreateDirectory(@"C:\NFe\Retorno_Proc_NFe\");
                }
                FileStream FS = new FileStream(@"C:\NFe\Retorno_Proc_NFe\" + string.Format("{0:MMddyyyy}", DateTime.Now.Date) + "_" + Retorno.nRec.Trim() + ".xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                SW = new StreamWriter(FS);

                xmlDesSerializar.Serialize(SW, Retorno);
            }
        }