//Procedure alterada para que
        public static int ExecutaProc(string nomeProc,
                                      SqlParameter[] parametros,
                                      bool consultaUltimoIdentity = false)
        {
            using (SqlConnection conexao = ConexaoBD.GetConexao())
            {
                using (SqlCommand comando = new SqlCommand(nomeProc, conexao))
                {
                    comando.CommandType = CommandType.StoredProcedure;
                    if (parametros != null)
                    {
                        comando.Parameters.AddRange(parametros);
                    }
                    comando.ExecuteNonQuery();

                    if (consultaUltimoIdentity)
                    {
                        string sql = "select isnull(@@IDENTITY,0)";
                        comando.CommandType = CommandType.Text;
                        comando.CommandText = sql;
                        int vendaId = Convert.ToInt32(comando.ExecuteScalar());
                        conexao.Close();
                        return(vendaId);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
        }
 public static void ExecutaSQL(string sql, SqlParameter[] parametros)
 {
     using (SqlConnection conexao = ConexaoBD.GetConexao())
     {
         using (SqlCommand comando = new SqlCommand(sql, conexao))
         {
             if (parametros != null)
             {
                 comando.Parameters.AddRange(parametros);
             }
             comando.ExecuteNonQuery();
         }
         conexao.Close();
     }
 }
 public static DataTable ExecutaSelect(string sql, SqlParameter[] parametros)
 {
     using (SqlConnection conexao = ConexaoBD.GetConexao())
     {
         using (SqlDataAdapter adapter = new SqlDataAdapter(sql, conexao))
         {
             if (parametros != null)
             {
                 adapter.SelectCommand.Parameters.AddRange(parametros);
             }
             DataTable tabela = new DataTable();
             adapter.Fill(tabela);
             conexao.Close();
             return(tabela);
         }
     }
 }
        public static DataTable ExecutaProcSelect(string nomeProc, SqlParameter[] parametros)
        {
            using (SqlConnection conexao = ConexaoBD.GetConexao())
            {
                using (SqlDataAdapter adapter = new SqlDataAdapter(nomeProc, conexao))
                {
                    if (parametros != null)
                    {
                        adapter.SelectCommand.Parameters.AddRange(parametros);
                    }

                    adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                    DataTable tabela = new DataTable();
                    adapter.Fill(tabela);
                    conexao.Close();
                    return(tabela);
                }
            }
        }
        public static int ExecutaProcScalar(string nomeProc, SqlParameter[] parametros)
        {
            using (SqlConnection conexao = ConexaoBD.GetConexao())
            {
                int numero;

                using (SqlDataAdapter adapter = new SqlDataAdapter(nomeProc, conexao))
                {
                    if (parametros != null)
                    {
                        adapter.SelectCommand.Parameters.AddRange(parametros);
                    }

                    adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                    numero = Convert.ToInt32(adapter.SelectCommand.ExecuteScalar());
                    //adapter.Fill(tabela);
                    conexao.Close();
                    return(numero);
                }
            }
        }