public static Item findById(int id) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT * FROM Item WHERE id = @id"; cmd.Parameters.AddWithValue("@id", id); SqlDataReader dr = Conexao.selecionar(cmd); Item obj = new Item(); if (dr.HasRows) { dr.Read(); obj.Id = (int)dr["id"]; obj.Nome = dr["nome"].ToString(); obj.Complemento = dr["complemento"].ToString(); obj.Imagem = dr["imagem"].ToString(); obj.QtdEstoque = (int)dr["qtd_estoque"]; obj.Marca = MarcaDAO.findById((int)dr["fk_marca"]); obj.Setor = SetorDAO.findById((int)dr["fk_setor"]); } else { obj = null; } return(obj); }
public List <Item> findAll() { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT * FROM Item"; SqlDataReader dr = Conexao.selecionar(cmd); List <Item> objs = new List <Item>(); if (dr.HasRows) { while (dr.Read()) { dr.Read(); Item obj = new Item(); obj.Id = (int)dr["id"]; obj.Nome = dr["nome"].ToString(); obj.Complemento = dr["complemento"].ToString(); obj.Imagem = dr["imagem"].ToString(); obj.QtdEstoque = (int)dr["qtd_estoque"]; obj.Marca = MarcaDAO.findById((int)dr["fk_marca"]); obj.Setor = SetorDAO.findById((int)dr["fk_setor"]); objs.Add(obj); } } else { objs = null; } return(objs); }