Example #1
0
        public Exercicio Consultar(int id)
        {
            SqlCommand    comm = new SqlCommand("Select * from Exercicio Where ID_Exercicio = " + id, Banco.Abrir());
            SqlDataReader dr   = comm.ExecuteReader();
            Exercicio     e    = new Exercicio();

            while (dr.Read())
            {
                e.ID = Convert.ToInt32(dr.GetValue(0));
                Conteudo cont = new Conteudo();
                cont.ID            = Convert.ToInt32(dr.GetValue(1));
                e.Conteudo         = cont;
                e.Descricao        = dr.GetValue(2).ToString();
                e.Tipo             = dr.GetValue(3).ToString();
                e.AleatorioQuestao = Convert.ToBoolean(dr.GetValue(4));
                e.Usuario          = Convert.ToInt32(dr.GetValue(5));
            }
            dr.Close();
            comm.CommandText = "Select ID_Questao, Ordem_Questao from Questao Where ID_Exercicio = " + id + " order by Ordem_Questao";
            dr = comm.ExecuteReader();
            List <Questao> lista = new List <Questao>();

            while (dr.Read())
            {
                QuestaoDAL dalq = new QuestaoDAL();
                Questao    q    = new Questao();
                q = dalq.Consultar(Convert.ToInt32(dr.GetValue(0)));
                lista.Add(q);
            }
            e.Questao = lista;
            comm.Connection.Close();
            return(e);
        }
Example #2
0
        /// <summary>
        /// Altera um Exercicio no Banco de daodos
        /// Precisando apenas do ID do Conteudo
        /// </summary>
        /// <param name="E"> Parametro do tipo exercicio | com id </param>
        public void Alterar(Exercicio E)
        {
            SqlCommand    comm = new SqlCommand("Select * From Questao Where ID_Exercicio = " + E.ID, Banco.Abrir());
            SqlDataReader dr   = comm.ExecuteReader();

            while (dr.Read())
            {
                SqlCommand comm2 = new SqlCommand("Delete Alternativa Where ID_Questao = " + dr.GetValue(0).ToString(), Banco.Abrir());
                comm2.ExecuteNonQuery();
                try
                {
                    comm2.CommandText = "Delete ImagemQuestao Where ID_Questao = " + dr.GetValue(0).ToString();
                    comm2.ExecuteNonQuery();
                } catch  {}
                comm2.Connection.Close();
            }
            dr.Close();
            comm.CommandText = "Delete Questao Where ID_Exercicio = " + E.ID;
            comm.ExecuteNonQuery();
            foreach (var item in E.Questao)
            {
                QuestaoDAL dal = new QuestaoDAL();
                item.ID = dal.Criar(item);
                foreach (var i in item.Alternativa)
                {
                    i.Questao = item;
                    AlternativaDAL dalalt = new AlternativaDAL();
                    dalalt.Criar(i);
                }
            }
            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.CommandText = "AlterarExercicio";
            comm.Parameters.Add("@ID", SqlDbType.Int).Value               = E.ID;
            comm.Parameters.Add("@Conteudo", SqlDbType.Int).Value         = E.Conteudo.ID;
            comm.Parameters.Add("@Descricao", SqlDbType.VarChar).Value    = E.Descricao;
            comm.Parameters.Add("@Tipo", SqlDbType.Char).Value            = E.Tipo;
            comm.Parameters.Add("@AleatorioQuestao", SqlDbType.Bit).Value = E.AleatorioQuestao;
            comm.Parameters.Add("@Usuario", SqlDbType.Int).Value          = E.Usuario;
            comm.ExecuteNonQuery();
            comm.Connection.Close();
        }