Example #1
0
        public static string ExecutaSQLparaString(string comandoSQL)
        {
            string     resultado  = null;
            var        cs         = Variaveis.ObtemConnectionString();
            var        conexao    = new SqlConnection(cs);
            string     comandosql = comandoSQL;
            SqlCommand cmd        = new SqlCommand(comandosql, conexao);

            try
            {
                cmd.Connection.Open();
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    resultado = reader[0].ToString();
                }
                return(resultado);
            }
            catch (Exception ex)
            {
                FRS_Biblioteca.Log log = new Log(System.Reflection.MethodBase.GetCurrentMethod().Name, $"Erro ao executar stored procedure {comandoSQL}", ex.Message);
                FRS_Biblioteca.Log.GravaLog(log);
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
            return(null);
        }
Example #2
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();
            }
        }
Example #3
0
        public static List <string> ExecutaStoredProcedure(string storedprocedure)
        {
            var        resultado  = new List <string>();
            var        cs         = Variaveis.ObtemConnectionString();
            var        conexao    = new SqlConnection(cs);
            string     comandosql = "EXECUTE dbo." + storedprocedure;
            SqlCommand cmd        = new SqlCommand(comandosql, conexao);

            try
            {
                cmd.Connection.Open();
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    resultado.Add(reader[0].ToString());
                }
            }
            catch (Exception ex)
            {
                FRS_Biblioteca.Log log = new Log("ExecutaStoredProcedure", $"Erro ao executar stored procedure {storedprocedure}", ex.Message);
                FRS_Biblioteca.Log.GravaLog(log);
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
            return(resultado);
        }
Example #4
0
        public static List <string> VendaveisProcessados()
        {
            var        resultado  = new List <string>();
            var        cs         = Variaveis.ObtemConnectionString();
            var        conexao    = new SqlConnection(cs);
            string     comandosql = "select nCFe from dbo.Vendas order by nCFe";
            SqlCommand cmd        = new SqlCommand(comandosql, conexao);

            try
            {
                cmd.Connection.Open();
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    resultado.Add(reader[0].ToString());
                }
            }
            catch (Exception ex)
            {
                FRS_Biblioteca.Log log = new Log("VendaveisProcessados", $"Erro ao gerar a lista de notas armazenadas no BD Vendas", ex.Message);
                FRS_Biblioteca.Log.GravaLog(log);
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
            return(resultado);
        }
Example #5
0
        //todo: Deve ser criado um método para checar se o banco de dados é acessível
        /// <summary>
        /// Executa comando SLQ (String)
        /// </summary>
        /// <remarks>Este método executa um comando SQL e checa se ao menos um registro foi afetado.</remarks>
        /// <returns>Campo Returns</returns>
        public static bool ExecutaSql(string comandosql)
        {
            var        cs      = Variaveis.ObtemConnectionString();
            var        conexao = new SqlConnection(cs);
            SqlCommand cmd     = new SqlCommand(comandosql, conexao);

            try
            {
                cmd.Connection.Open();
                var reader = cmd.ExecuteReader();
                if (reader.RecordsAffected > 0)
                {
                    return(true);
                }
                if (!reader.HasRows)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                FRS_Biblioteca.Log log = new Log("ExecutaSql", "Erro ao tentar executar SQL", ex.Message);
                FRS_Biblioteca.Log.GravaLog(log);
                return(false);
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
        }
Example #6
0
        public static string GetTC()

        {
            using (SqlConnection conexaoBD = new SqlConnection(Variaveis.ObtemConnectionString()))
            {
                var repo = conexaoBD.Execute(@"select count(nCFe) from dbo.Notas_Fiscais where cast(data as date) = cast(getdate() as date)");
                if (repo == -1)
                {
                    repo = 0;
                }
                return(Convert.ToString(repo));
            }

            //if (FRS_Biblioteca.DB.ExecutaSQLparaString("EXEC dbo.sp_TC") == null)
            //{
            //    return "0";
            //}
            //else
            //{
            //    return FRS_Biblioteca.DB.ExecutaSQLparaString("EXEC dbo.sp_TC");
            //}
        }
Example #7
0
        public static bool GravaProdutosVendidos(string nCFe, string Data, string Vendavel, string CodVendavel, string ValorVendavel, string ValorDesconto, string ValorVendido)
        {
            string comandosql2 = $"INSERT INTO [LojaDB].[dbo].[A_Processar] " +
                                 $"(Vendavel) VALUES ('{Vendavel}')";

            DB.ExecutaSql(comandosql2);
            var    cs         = Variaveis.ObtemConnectionString();
            var    conexao    = new SqlConnection(cs);
            string comandosql = $"INSERT INTO [LojaDB].[dbo].[Vendas] " +
                                $"([nCFe],[Data],[Vendavel],[CodVendavel],[ValorVendavel],[ValorDesconto],[ValorVendido]) " +
                                $"VALUES " +
                                $"('{nCFe}', '{Data}', '{Vendavel}', '{CodVendavel}', '{ValorVendavel}', '{ValorDesconto}', '{ValorVendido}')";
            SqlCommand cmd = new SqlCommand(comandosql, conexao);

            try
            {
                cmd.Connection.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows || reader.RecordsAffected > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                FRS_Biblioteca.Log log = new Log("GravaProdutosVendidos", $"Erro ao gravar Vendas: {nCFe}", ex.Message);
                FRS_Biblioteca.Log.GravaLog(log);
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }

            return(false);
        }
 public static bool TestaDouble(string valor)
 {
     try
     {
         if (!(valor == ""))
         {
             double teste = Convert.ToDouble(valor);
             return(true);
         }
     }
     catch (System.FormatException)
     {
         MessageBox.Show($"O valor digitado está inválido,\r\nO separador de casa decimais é -> {Variaveis.GetSeparadorNumerico()} \r\nfavor tentar novamente", "Valor digitado errado", MessageBoxButtons.OK, MessageBoxIcon.Stop);
     }
     return(false);
 }