Esempio n. 1
0
        public List <Usuario> Pesquisar(string nome)
        {
            List <Usuario> users = new List <Usuario>();
            string         sql   = $@"select *
							from usuario
							where nome like @Nome"                            ;

            try
            {
                Dictionary <string, object> parametros = new Dictionary <string, object>();

                parametros.Add("@Nome", "%" + nome + "%");

                DbDataReader dr = _bd.ExecuteQuery(sql, parametros);

                users = Map(dr);
            }
            catch
            {
                return(null);
            }
            finally
            {
                if (!_bd._manterConexaoAberta)
                {
                    _bd.Fechar();
                }
            }

            return(users);
        }
Esempio n. 2
0
        public bool getCategoria(int id, Categoria cat)
        {
            string sql = $"select * from categoria where CategoriaId = {id}";
            bool   ok  = false;

            try
            {
                DbDataReader dr = _bd.ExecuteQuery(sql);

                if (dr.HasRows)
                {
                    ok       = dr.Read();
                    cat.Id   = id;
                    cat.Nome = dr["Nome"].ToString();

                    ok = true;
                }
            }
            catch
            {
            }
            finally
            {
                if (!_bd._manterConexaoAberta)
                {
                    _bd.Fechar();
                }
            }

            return(ok);
        }
        public int getMaxPK()
        {
            int    maxPK = -1;
            string sql   = @"SELECT 
								MAX(ProdutoId) as MaxPK
							FROM
								produto"                                ;

            try
            {
                DbDataReader dr = _bd.ExecuteQuery(sql);
                if (dr.Read())
                {
                    maxPK = Convert.ToInt32(dr["MaxPK"]);
                }
            }
            catch { }
            finally
            {
                _bd.Fechar();
            }

            return(maxPK);
        }