Esempio n. 1
0
        //public static bool CarregaDados(FRS_Biblioteca.Notas nota)
        //{
        //    string expressao = string.Empty;
        //    XPathDocument documento = new XPathDocument(nota.Arquivo);
        //    var navegador = documento.CreateNavigator();
        //    try
        //    {
        //        if (navegador.SelectSingleNode("//CFeCanc").Value.Length > 10)
        //        {
        //            return false;
        //        }
        //    }
        //    catch (NullReferenceException)
        //    {
        //    }
        //    expressao = "//nserieSAT";
        //    nota.NumeroSerieSat = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//nCFe";
        //    nota.NCFe = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//dEmi";
        //    nota.DataEmissao = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//hEmi";
        //    nota.HoraEmissao = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//numeroCaixa";
        //    nota.NumeroCaixa = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//emit/CNPJ";
        //    nota.CNPJ = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//emit/xNome";
        //    nota.Estabelecimento = navegador.SelectSingleNode(expressao).Value;
        //    try
        //    {
        //        expressao = "//dest/CPF";
        //        nota.CPF_Destino = navegador.SelectSingleNode(expressao).Value;
        //    }
        //    catch (Exception)
        //    {
        //        expressao = "//dest/CNPJ";
        //        nota.CPF_Destino = navegador.SelectSingleNode(expressao).Value;
        //    }
        //    expressao = "//total/ICMSTot/vProd";
        //    nota.ValorBruto = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//total/ICMSTot/vDesc";
        //    nota.ValorDesconto = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//vCFe";
        //    nota.ValorFinal = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "//vCFeLei12741";
        //    nota.Tributos = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "/CFe/infCFe/pgto/MP/cMP";
        //    nota.MeiodePagamento = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "/CFe/infCFe/pgto/MP/vMP";
        //    nota.ValorMeiodePagamento = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "/CFe/infCFe/pgto/vTroco";
        //    nota.ValorTroco = navegador.SelectSingleNode(expressao).Value;
        //    expressao = "/CFe/infCFe/@Id";
        //    nota.Arquivonome = "AD" + navegador.SelectSingleNode(expressao).Value.Substring(3) + ".xml";
        //    expressao = "/CFe/infCFe/det/@nItem";
        //    nota.TotalProdutos = navegador.Select(expressao).Count.ToString();
        //    nota.XML = File.ReadAllText(nota.Arquivo);
        //    nota.Data = ConverteDataeHora(nota);

        //    return true;
        //}

        private static string ConverteDataeHora(FRS_Biblioteca.Notas nota)
        {
            string temp1 = nota.DataEmissao.Remove(4) + "-" + nota.DataEmissao.Substring(4, 2) + "-" + nota.DataEmissao.Substring(6, 2);
            string temp2 = nota.HoraEmissao.Substring(0, 2) + ":" + nota.HoraEmissao.Substring(2, 2) + ":" + nota.HoraEmissao.Substring(4, 2);

            return(temp1 + " " + temp2);
        }
Esempio n. 2
0
        public static string GeraComandoInclusao(FRS_Biblioteca.Notas nota)
        {
            string temp1 = "INSERT INTO [LojaDB].[dbo].[Notas_Fiscais] ([nCFe],[TotalProdutos],[NumeroSerieSat],[Data],[DataEmissao],[HoraEmissao], [NumeroCaixa], [CNPJ],[Estabelecimento],[CPF_Destino],[ValorBruto],[ValorDesconto],[ValorFinal],[Tributos],[MeiodePagamento],[ValorMeiodePagamento],[ValorTroco],[Arquivo],[XML]) ";
            string temp2 = ("VALUES ('" +
                            nota.NCFe
                            + "', '" + nota.TotalProdutos
                            + "', '" + nota.NumeroSerieSat
                            + "', '" + nota.Data
                            + "', '" + nota.DataEmissao
                            + "', '" + nota.HoraEmissao
                            + "', '" + nota.NumeroCaixa
                            + "', '" + nota.CNPJ
                            + "', '" + nota.Estabelecimento
                            + "', '" + nota.CPF_Destino
                            + "', '" + nota.ValorBruto
                            + "', '" + nota.ValorDesconto
                            + "', '" + nota.ValorFinal
                            + "', '" + nota.Tributos
                            + "', '" + nota.MeiodePagamento
                            + "', '" + nota.ValorMeiodePagamento
                            + "', '" + nota.ValorTroco
                            + "', '" + nota.Arquivonome
                            + "', '" + nota.XML
                            + "')");
            string comando = temp1 + temp2;

            return(comando);
        }
Esempio n. 3
0
        /// <summary>
        /// Verifica se o número da nota fiscal eletrônica já existe no banco de dados. True = existe no banco, False =  não existe no banco
        /// </summary>
        public static bool TestaNfeDB(FRS_Biblioteca.Notas nota)
        {
            var        cs         = Variaveis.ObtemConnectionString();
            var        conexao    = new SqlConnection(cs);
            string     comandosql = $"select * from dbo.Notas_Fiscais where nCFe = '{nota.NCFe}'";
            SqlCommand cmd        = new SqlCommand(comandosql, conexao);

            try
            {
                cmd.Connection.Open();
                var reader = cmd.ExecuteReader();
                if (!reader.HasRows)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                FRS_Biblioteca.Log log = new Log("TestaNfeDB", $"Erro ao consultar banco de dados para verificar a existência da notafiscal: {nota.NCFe}", ex.Message);
                FRS_Biblioteca.Log.GravaLog(log);

                return(false);
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
        }