Beispiel #1
0
        public static Setor findById(int id)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "SELECT * FROM Setor WHERE id = @id";
            cmd.Parameters.AddWithValue("@id", id);
            SqlDataReader dr = Conexao.selecionar(cmd);

            Setor obj = new Setor();

            if (dr.HasRows)
            {
                dr.Read();
                obj.Id              = (int)dr["id"];
                obj.Nome            = dr["nome"].ToString();
                obj.Descricao       = dr["descricao"].ToString();
                obj.SubDepartamento = SubdepartamentoDAO.findById((int)dr["fk_sub_departamento"]);
                obj.QtdEstoque      = (int)dr["qtd_estoque"];
            }
            else
            {
                obj = null;
            }
            return(obj);
        }
Beispiel #2
0
        public List <Setor> findAll()
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "SELECT * FROM Setor";
            SqlDataReader dr   = Conexao.selecionar(cmd);
            List <Setor>  objs = new List <Setor>();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    dr.Read();
                    Setor obj = new Setor();
                    obj.Id              = (int)dr["id"];
                    obj.Nome            = dr["nome"].ToString();
                    obj.Descricao       = dr["descricao"].ToString();
                    obj.SubDepartamento = SubdepartamentoDAO.findById((int)dr["fk_sub_departamento"]);
                    obj.QtdEstoque      = (int)dr["qtd_estoque"];
                    objs.Add(obj);
                }
            }
            else
            {
                objs = null;
            }
            return(objs);
        }