Beispiel #1
0
        public T ConsultarEntidade(string sql, Func <IDataReader, T> TuplaParaEntidade, Dictionary <string, object> parametros = null)
        {
            using (Conexao)
            {
                using (Comando)
                {
                    Conexao.ConnectionString = ConexaoDBFactory.ObterStringDeConexao(Tipo).ConnectionString;

                    Comando.Parameters.Clear();
                    Comando.Connection  = Conexao;
                    Comando.CommandText = sql.FormatarSQL(Tipo);

                    Conexao.Open();

                    Comando.AdicionarParametros(parametros);

                    Leitor = Comando.ExecuteReader();

                    if (Leitor.Read())
                    {
                        return(TuplaParaEntidade(Leitor));
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        protected int ExecutarAtualizacao(string sql, Dictionary <string, object> parametros = null, bool carregarId = true)
        {
            int id = 0;

            using (Conexao)
            {
                using (Comando)
                {
                    Conexao.ConnectionString = ConexaoDBFactory.ObterStringDeConexao(Tipo).ConnectionString;

                    Comando.Parameters.Clear();
                    Comando.Connection  = Conexao;
                    Comando.CommandText = sql.FormatarSQL(Tipo, carregarId);

                    Conexao.Open();

                    Comando.AdicionarParametros(parametros);

                    if (carregarId)
                    {
                        id = Convert.ToInt32(Comando.ExecuteScalar());
                    }
                    else
                    {
                        Comando.ExecuteNonQuery();
                    }
                }
            }

            return(id);
        }
Beispiel #3
0
        public int Excluir(string sql, int id)
        {
            var items = 0;

            using (Conexao)
            {
                Conexao.ConnectionString = ConexaoDBFactory.ObterStringDeConexao(Tipo).ConnectionString;

                Comando.Parameters.Clear();
                Comando.Connection  = Conexao;
                Comando.CommandText = sql.FormatarSQL(Tipo);

                Conexao.Open();

                var parametro = Comando.CreateParameter();
                parametro.Value         = id;
                parametro.ParameterName = "Id";
                Comando.Parameters.Add(parametro);

                items = Comando.ExecuteNonQuery();
            }


            return(items);
        }
Beispiel #4
0
 public Db(TipoRepositorio tipo)
 {
     this.Tipo = tipo;
     Conexao   = ConexaoDBFactory.CriarConexao(tipo);
     Comando   = Conexao.CreateCommand();
 }