public static string GetAssinatura(LoteRPS rps)
        {
            StringBuilder ass = new StringBuilder();

            ass.Append(rps.InscricaoMunicipalPrestador.PadLeft(11, '0'));
            ass.Append(rps.SerieRPS.PadRight(5, ' '));
            ass.Append(rps.NumeroRPS.ToString().PadLeft(12, '0'));
            ass.Append(rps.DataEmissaoRPS.ToString("yyyyMMdd"));
            ass.Append(rps.Tributacao.ToString().PadRight(2, ' '));
            ass.Append(rps.SituacaoRPS);
            ass.Append(rps.TipoRecolhimento == "A" ? "N" : "S");
            decimal dTotal        = Truncate(rps.Itens.Item.Sum(c => c.ValorUnitario), 2);
            decimal dTotalDeducao = Truncate(rps.Deducoes.Deducao.Sum(c => c.ValorDeduzir), 2);

            ass.Append((dTotal - dTotalDeducao).ToString("#0.00").Replace(",", "").PadLeft(15, '0'));
            ass.Append(dTotalDeducao.ToString("#0.00").Replace(",", "").PadLeft(15, '0'));
            ass.Append(rps.CodigoAtividade.PadLeft(10, '0'));
            ass.Append(Util.TiraSimbolo(rps.CPFCNPJTomador).PadLeft(14, '0'));

            return(Util.StringToHashSHA1(ass.ToString()));
        }
        private static dsNFSeCampinas CarregaDataSet(string sCD_NFSEQ, daoUtil dadosEmpresa, string sEnderPrestador, LoteRPS nota)
        {
            dsNFSeCampinas ds = new dsNFSeCampinas();
            dsNFSeCampinas.NotaRow row = ds.Nota.NewNotaRow();

            row.RazaoSocialPrestador = nota.RazaoSocialPrestador;
            row.NumeroRPS = nota.NumeroRPS;
            row.DataEmissaoRPS = nota.DataEmissaoRPS;
            row.CPFCNPJTomador = nota.CPFCNPJTomador;
            row.RazaoSocialTomador = nota.RazaoSocialTomador;
            row.TipoLogradouroTomador = nota.TipoLogradouroTomador.ToUpper();
            row.LogradouroTomador = nota.LogradouroTomador;
            row.NumeroEnderecoTomador = nota.NumeroEnderecoTomador;
            row.TipoBairroTomador = nota.TipoBairroTomador;
            row.CEPTomador = nota.CEPTomador;
            row.EmailTomador = nota.EmailTomador;
            row.CodigoAtividade = nota.CodigoAtividade;
            row.AliquotaAtividade = nota.AliquotaAtividade.ToString();

            switch (nota.TipoRecolhimento)
            {
                case "A": row.TipoRecolhimento = "A Recolher";
                    break;
                case "R": row.TipoRecolhimento = "Retido na fonte";
                    break;
            }
            row.MunicipioPrestacaoDescricao = nota.MunicipioPrestacaoDescricao;
            switch (nota.Tributacao)
            {
                case "C": row.Tributacao = "Isenta de ISS";
                    break;
                case "E": row.Tributacao = "Não Incidência no Município";
                    break;
                case "F": row.Tributacao = "Imune";
                    break;
                case "K": row.Tributacao = "Exigibilidd Susp.Dec.J/Proc.A";
                    break;
                case "N": row.Tributacao = "Não Tributável";
                    break;
                case "T": row.Tributacao = "Tributável";
                    break;
                case "G": row.Tributacao = "Tributável Fixo";
                    break;
                case "H": row.Tributacao = "Tributável S.N.";
                    break;
                case "M": row.Tributacao = "Micro Empreendedor Individual (MEI)";
                    break;
            }
            row.AliquotaPIS = nota.AliquotaPIS;
            row.AliquotaCOFINS = nota.AliquotaCOFINS;
            row.AliquotaINSS = nota.AliquotaINSS;
            row.AliquotaIR = nota.AliquotaIR;
            row.AliquotaCSLL = nota.AliquotaCSLL;

            row.ValorCOFINS = Convert.ToDecimal(nota.ValorCOFINS.ToString().Replace(".", ","));
            row.ValorCSLL = Convert.ToDecimal(nota.ValorCSLL.ToString().Replace(".", ","));
            row.ValorINSS = Convert.ToDecimal(nota.ValorINSS.ToString().Replace(".", ","));
            row.ValorIR = Convert.ToDecimal(nota.ValorIR.ToString().Replace(".", ","));
            row.ValorPIS = Convert.ToDecimal(nota.ValorPIS.ToString().Replace(".", ","));

            row.DescricaoRPS = nota.DescricaoRPS;
            row.F_ENDER_TOMADOR =
            row.F_RECOLHIMENTO =
            row.F_TRIBUTACAO =
            row.F_CD_VERIFICACAO = daoUtil.GetCodVerificacaoByCD_NFSEQ(sCD_NFSEQ);
            row.F_CNPJ_PRESTADOR = Acesso.CNPJ_EMPRESA;
            row.F_ENDERECO_PRESTADOR = sEnderPrestador;
            row.F_MUNICIPIO_PRESTADOR = Acesso.CIDADE_EMPRESA;
            row.F_UF_PRESTADOR = daoUtil.GetUfByNome(nota.CidadeTomadorDescricao);
            row.F_EMAIL_PRESTADOR = dadosEmpresa.EmailEmpresa;
            //row.F_UF_TOMADOR = daoUtil.GetUfByNome(nota.CidadeTomadorDescricao);
            row.F_UF_TOMADOR = daoUtil.GetUfTomador(nota.CD_NFSEQ);
            row.F_MES_RECOLHIMENTO = nota.DataEmissaoRPS.ToString("MM/yyyy");
            if (nota.Deducoes.Deducao.Count() > 0)
            {
                row.F_VALOR_DECUCAO = nota.Deducoes.Deducao.Sum(c => c.ValorDeduzir);
            }
            else
            {
                row.F_VALOR_DECUCAO = 0;
            }
            row.CidadeTomadorDescricao = nota.CidadeTomadorDescricao;
            row.InscricaoPrestador = nota.InscricaoMunicipalPrestador;

            row.Duplicatas = daoCobr.BuscaFatToImpressaoNFSE_DSF(nota.CD_NFSEQ);

            ds.Nota.AddNotaRow(row);

            dsNFSeCampinas.ItensRow rowItem;
            foreach (LoteRPSItensItem item in nota.Itens.Item)
            {
                rowItem = ds.Itens.NewItensRow();
                rowItem.DiscriminacaoServico = item.DiscriminacaoServico;
                rowItem.Quantidade = item.Quantidade;
                rowItem.ValorTotal = item.ValorTotal;
                rowItem.ValorUnitario = item.ValorUnitario;
                rowItem.NumeroRPS = nota.NumeroRPS;
                ds.Itens.AddItensRow(rowItem);
            }



            return ds;
        }
        private LoteRPS CarregaLote(string cd_nfseq)
        {
            try
            {
                base.GetRps(cd_nfseq);

                LoteRPS rps = null;
                foreach (DataRow row in dtRPS.Rows)
                {
                    rps = new LoteRPS();
                    rps.CD_NFSEQ = cd_nfseq;

                    #region Carrega as propriedades do RPS
                    rps.InscricaoMunicipalPrestador = Util.TiraSimbolo(row["InscricaoMunicipalPrestador"].ToString()).PadLeft(9, '0');
                    rps.TipoRPS = "RPS";
                    rps.SerieRPS = "NF";
                    rps.RazaoSocialPrestador = row["RazaoSocialPrestador"].ToString();
                    //rps.NumeroRPS = sNumeroRps;
                    rps.DataEmissaoRPS = DateTime.Today;// Convert.ToDateTime(row["DataEmissaoRPS"].ToString());
                    rps.SituacaoRPS = row["SituacaoRPS"].ToString();
                    rps.SerieRPSSubstituido = row["SerieRPSSubstituido"].ToString();
                    rps.NumeroRPSSubstituido = Convert.ToByte(row["NumeroRPSSubstituido"].ToString());
                    rps.NumeroNFSeSubstituida = Convert.ToByte(row["NumeroNFSeSubstituida"].ToString());
                    rps.DataEmissaoNFSeSubstituida = Convert.ToDateTime(row["DataEmissaoNFSeSubstituida"].ToString());
                    rps.SeriePrestacao = Convert.ToByte(row["SeriePrestacao"].ToString());
                    rps.InscricaoMunicipalTomador = row["InscricaoMunicipalTomador"].ToString().PadLeft(9,'0');
                    rps.CPFCNPJTomador = Util.TiraSimbolo(row["CNPJ_Tomador"].ToString() == "" ? row["CPF_Tomador"].ToString() : row["CNPJ_Tomador"].ToString());
                    rps.RazaoSocialTomador = row["RazaoSocialTomador"].ToString().Trim();
                    rps.DocTomadorEstrangeiro = row["DocTomadorEstrangeiro"].ToString();
                    rps.TipoLogradouroTomador = row["TipoLogradouroTomador"].ToString();
                    rps.LogradouroTomador = row["LogradouroTomador"].ToString();
                    rps.NumeroEnderecoTomador = row["NumeroEnderecoTomador"].ToString();
                    rps.TipoBairroTomador = "Bairro";
                    rps.ComplementoEnderecoTomador = row["ComplementoEnderecoTomador"].ToString();
                    rps.BairroTomador = row["BairroTomador"].ToString();
                    rps.CidadeTomador = daoUtil.GetCodigoSiafiByCodigo((row["CidadeTomador"].ToString()));
                    rps.CidadeTomadorDescricao = row["CidadeTomadorDescricao"].ToString();
                    rps.CEPTomador = Util.TiraSimbolo(row["CEPTomador"].ToString());
                    rps.EmailTomador = row["EmailTomador"].ToString();
                    rps.CodigoAtividade = row["CodigoAtividade"].ToString();
                    rps.TipoRecolhimento = row["TipoRecolhimento"].ToString();
                    if (row["cd_munPrestacao"].ToString() == "")
                    {
                        rps.MunicipioPrestacao = rps.CidadeTomador; // VERIFICAR TRATAMENTO
                        rps.MunicipioPrestacaoDescricao = rps.CidadeTomadorDescricao; // VERIFICAR TRATAMENTO   
                    }
                    else
                    {
                        rps.MunicipioPrestacao = daoUtil.GetCodigoSiafiByCodigo(row["cd_munPrestacao"].ToString());
                        rps.MunicipioPrestacaoDescricao = daoUtil.GetNM_MUNICIPIO(row["cd_munPrestacao"].ToString());
                    }
                    rps.Operacao = row["Operacao"].ToString();
                    rps.Tributacao = row["Tributacao"].ToString();

                    rps.ValorPIS = row["ValorPIS"].ToString();
                    rps.ValorCOFINS = row["ValorCOFINS"].ToString();
                    rps.ValorINSS = row["ValorINSS"].ToString();
                    rps.ValorCSLL = row["ValorCSLL"].ToString();


                    rps.ValorIR = GetValorIR(cd_nfseq).ToString();



                    rps.AliquotaPIS = Convert.ToDecimal(row["AliquotaPIS"].ToString());
                    rps.AliquotaCOFINS = Convert.ToDecimal(row["AliquotaCOFINS"].ToString());
                    rps.AliquotaINSS = Convert.ToDecimal(row["AliquotaINSS"].ToString());
                    rps.AliquotaIR = Convert.ToDecimal(row["AliquotaIR"].ToString());    //Convert.ToDecimal(GetValorIR(cd_nfseq));
                    rps.AliquotaCSLL = Convert.ToDecimal(row["AliquotaCSLL"].ToString());




                    rps.DescricaoRPS = daoUtil.GetTotImpostosServ(cd_nfseq) + GetDescricaoRPS(cd_nfseq);
                    if (Acesso.TRANSPARENCIA == 0 || Acesso.TRANSPARENCIA == 2)
                    {
                        rps.DescricaoRPS += Environment.NewLine + daoUtil.CarregaObsTransparenciaNF(cd_nfseq);
                    }

                    rps.TelefonePrestador = row["TelefonePrestador"].ToString();
                    rps.TelefoneTomador = row["TelefoneTomador"].ToString();
                    rps.MotCancelamento = "";

                    #endregion

                    rps.Itens = new LoteRPSItens();
                    rps.Itens.Item = new List<LoteRPSItensItem>();
                    // Carregos os Itens da Nota
                    base.GetItens(cd_nfseq);
                    LoteRPSItensItem item;
                    foreach (DataRow rowItem in dtItem.Rows)
                    {
                        rps.AliquotaAtividade = base.GetAliquotaAtividade(rowItem["cd_clifor"].ToString(), rowItem["cd_oper"].ToString()).ToString();
                        item = new LoteRPSItensItem();
                        item.DiscriminacaoServico = rowItem["DiscriminacaoServico"].ToString();
                        if (Acesso.TRANSPARENCIA == 1 || Acesso.TRANSPARENCIA == 2)
                        {
                            item.DiscriminacaoServico += Environment.NewLine + daoUtil.CarregaObsTransparenciaITEM(rowItem["nr_lanc"].ToString());
                        }
                        item.Quantidade = Convert.ToByte(rowItem["Quantidade"].ToString());
                        item.ValorUnitario = Convert.ToDecimal(rowItem["ValorUnitario"].ToString());
                        item.ValorTotal = Convert.ToDecimal(rowItem["ValorTotal"].ToString());
                        rps.Itens.Item.Add(item);
                    }

                    // Verificar de onde ira puxar as deduções.
                    rps.Deducoes = new LoteRPSDeducoes();
                    rps.Deducoes.Deducao = new List<LoteRPSDeducoesDeducao>();

                    belConsultaSequencia seq = new belConsultaSequencia();
                    if (!bBuscaRetonro)
                    {
                        rps.NumeroRPS = seq.GetSequenciaNota(rps.InscricaoMunicipalPrestador, cd_nfseq);
                        this.SaveNumRPS(cd_nfseq, rps.NumeroRPS);
                    }
                    else
                    {
                        rps.NumeroRPS = this.GetNumeroRPSsalvo(cd_nfseq);
                    }

                    rps.Assinatura = belCarregaDadosRPS.GetAssinatura(rps);

                }
                return rps;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static string GetAssinatura(LoteRPS rps)
        {
            StringBuilder ass = new StringBuilder();

            ass.Append(rps.InscricaoMunicipalPrestador.PadLeft(11, '0'));
            ass.Append(rps.SerieRPS.PadRight(5, ' '));
            ass.Append(rps.NumeroRPS.ToString().PadLeft(12, '0'));
            ass.Append(rps.DataEmissaoRPS.ToString("yyyyMMdd"));
            ass.Append(rps.Tributacao.ToString().PadRight(2, ' '));
            ass.Append(rps.SituacaoRPS);
            ass.Append(rps.TipoRecolhimento == "A" ? "N" : "S");
            decimal dTotal = Truncate(rps.Itens.Item.Sum(c => c.ValorUnitario), 2);
            decimal dTotalDeducao = Truncate(rps.Deducoes.Deducao.Sum(c => c.ValorDeduzir), 2);
            ass.Append((dTotal - dTotalDeducao).ToString("#0.00").Replace(",", "").PadLeft(15, '0'));
            ass.Append(dTotalDeducao.ToString("#0.00").Replace(",", "").PadLeft(15, '0'));
            ass.Append(rps.CodigoAtividade.PadLeft(10, '0'));
            ass.Append(Util.TiraSimbolo(rps.CPFCNPJTomador).PadLeft(14, '0'));

            return Util.StringToHashSHA1(ass.ToString());
        }
        private LoteRPS CarregaLote(string cd_nfseq)
        {
            try
            {
                base.GetRps(cd_nfseq);

                LoteRPS rps = null;
                foreach (DataRow row in dtRPS.Rows)
                {
                    rps          = new LoteRPS();
                    rps.CD_NFSEQ = cd_nfseq;

                    #region Carrega as propriedades do RPS
                    rps.InscricaoMunicipalPrestador = Util.TiraSimbolo(row["InscricaoMunicipalPrestador"].ToString()).PadLeft(9, '0');
                    rps.TipoRPS              = "RPS";
                    rps.SerieRPS             = "NF";
                    rps.RazaoSocialPrestador = row["RazaoSocialPrestador"].ToString();
                    //rps.NumeroRPS = sNumeroRps;
                    rps.DataEmissaoRPS             = DateTime.Today;// Convert.ToDateTime(row["DataEmissaoRPS"].ToString());
                    rps.SituacaoRPS                = row["SituacaoRPS"].ToString();
                    rps.SerieRPSSubstituido        = row["SerieRPSSubstituido"].ToString();
                    rps.NumeroRPSSubstituido       = Convert.ToByte(row["NumeroRPSSubstituido"].ToString());
                    rps.NumeroNFSeSubstituida      = Convert.ToByte(row["NumeroNFSeSubstituida"].ToString());
                    rps.DataEmissaoNFSeSubstituida = Convert.ToDateTime(row["DataEmissaoNFSeSubstituida"].ToString());
                    rps.SeriePrestacao             = Convert.ToByte(row["SeriePrestacao"].ToString());
                    rps.InscricaoMunicipalTomador  = row["InscricaoMunicipalTomador"].ToString().PadLeft(9, '0');
                    rps.CPFCNPJTomador             = Util.TiraSimbolo(row["CNPJ_Tomador"].ToString() == "" ? row["CPF_Tomador"].ToString() : row["CNPJ_Tomador"].ToString());
                    rps.RazaoSocialTomador         = row["RazaoSocialTomador"].ToString().Trim();
                    rps.DocTomadorEstrangeiro      = row["DocTomadorEstrangeiro"].ToString();
                    rps.TipoLogradouroTomador      = row["TipoLogradouroTomador"].ToString();
                    rps.LogradouroTomador          = row["LogradouroTomador"].ToString();
                    rps.NumeroEnderecoTomador      = row["NumeroEnderecoTomador"].ToString();
                    rps.TipoBairroTomador          = "Bairro";
                    rps.ComplementoEnderecoTomador = row["ComplementoEnderecoTomador"].ToString();
                    rps.BairroTomador              = row["BairroTomador"].ToString();
                    rps.CidadeTomador              = daoUtil.GetCodigoSiafiByCodigo((row["CidadeTomador"].ToString()));
                    rps.CidadeTomadorDescricao     = row["CidadeTomadorDescricao"].ToString();
                    rps.CEPTomador       = Util.TiraSimbolo(row["CEPTomador"].ToString());
                    rps.EmailTomador     = row["EmailTomador"].ToString();
                    rps.CodigoAtividade  = row["CodigoAtividade"].ToString();
                    rps.TipoRecolhimento = row["TipoRecolhimento"].ToString();
                    if (row["cd_munPrestacao"].ToString() == "")
                    {
                        rps.MunicipioPrestacao          = rps.CidadeTomador;          // VERIFICAR TRATAMENTO
                        rps.MunicipioPrestacaoDescricao = rps.CidadeTomadorDescricao; // VERIFICAR TRATAMENTO
                    }
                    else
                    {
                        rps.MunicipioPrestacao          = daoUtil.GetCodigoSiafiByCodigo(row["cd_munPrestacao"].ToString());
                        rps.MunicipioPrestacaoDescricao = daoUtil.GetNM_MUNICIPIO(row["cd_munPrestacao"].ToString());
                    }
                    rps.Operacao   = row["Operacao"].ToString();
                    rps.Tributacao = row["Tributacao"].ToString();

                    rps.ValorPIS    = row["ValorPIS"].ToString();
                    rps.ValorCOFINS = row["ValorCOFINS"].ToString();
                    rps.ValorINSS   = row["ValorINSS"].ToString();
                    rps.ValorCSLL   = row["ValorCSLL"].ToString();


                    rps.ValorIR = GetValorIR(cd_nfseq).ToString();



                    rps.AliquotaPIS    = Convert.ToDecimal(row["AliquotaPIS"].ToString());
                    rps.AliquotaCOFINS = Convert.ToDecimal(row["AliquotaCOFINS"].ToString());
                    rps.AliquotaINSS   = Convert.ToDecimal(row["AliquotaINSS"].ToString());
                    rps.AliquotaIR     = Convert.ToDecimal(row["AliquotaIR"].ToString()); //Convert.ToDecimal(GetValorIR(cd_nfseq));
                    rps.AliquotaCSLL   = Convert.ToDecimal(row["AliquotaCSLL"].ToString());



                    rps.DescricaoRPS = daoUtil.GetTotImpostosServ(cd_nfseq) + GetDescricaoRPS(cd_nfseq);
                    if (Acesso.TRANSPARENCIA == 0 || Acesso.TRANSPARENCIA == 2)
                    {
                        rps.DescricaoRPS += Environment.NewLine + daoUtil.CarregaObsTransparenciaNF(cd_nfseq);
                    }

                    rps.TelefonePrestador = row["TelefonePrestador"].ToString();
                    rps.TelefoneTomador   = row["TelefoneTomador"].ToString();
                    rps.MotCancelamento   = "";

                    #endregion

                    rps.Itens      = new LoteRPSItens();
                    rps.Itens.Item = new List <LoteRPSItensItem>();
                    // Carregos os Itens da Nota
                    base.GetItens(cd_nfseq);
                    LoteRPSItensItem item;
                    foreach (DataRow rowItem in dtItem.Rows)
                    {
                        rps.AliquotaAtividade = base.GetAliquotaAtividade(rowItem["cd_clifor"].ToString(), rowItem["cd_oper"].ToString()).ToString();
                        item = new LoteRPSItensItem();
                        item.DiscriminacaoServico = rowItem["DiscriminacaoServico"].ToString();
                        if (Acesso.TRANSPARENCIA == 1 || Acesso.TRANSPARENCIA == 2)
                        {
                            item.DiscriminacaoServico += Environment.NewLine + daoUtil.CarregaObsTransparenciaITEM(rowItem["nr_lanc"].ToString());
                        }
                        item.Quantidade    = Convert.ToByte(rowItem["Quantidade"].ToString());
                        item.ValorUnitario = Convert.ToDecimal(rowItem["ValorUnitario"].ToString());
                        item.ValorTotal    = Convert.ToDecimal(rowItem["ValorTotal"].ToString());
                        rps.Itens.Item.Add(item);
                    }

                    // Verificar de onde ira puxar as deduções.
                    rps.Deducoes         = new LoteRPSDeducoes();
                    rps.Deducoes.Deducao = new List <LoteRPSDeducoesDeducao>();

                    belConsultaSequencia seq = new belConsultaSequencia();
                    if (!bBuscaRetonro)
                    {
                        rps.NumeroRPS = seq.GetSequenciaNota(rps.InscricaoMunicipalPrestador, cd_nfseq);
                        this.SaveNumRPS(cd_nfseq, rps.NumeroRPS);
                    }
                    else
                    {
                        rps.NumeroRPS = this.GetNumeroRPSsalvo(cd_nfseq);
                    }

                    rps.Assinatura = belCarregaDadosRPS.GetAssinatura(rps);
                }
                return(rps);
            }
            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;
            }
        }