Пример #1
0
        public ConteudoTexto Consultar(int id)
        {
            SqlCommand    comm = new SqlCommand("Select * from ConteudoTexto where ID_ConteudoTexto = " + id, Banco.Abrir());
            SqlDataReader dr   = comm.ExecuteReader();
            ConteudoTexto c    = new ConteudoTexto();

            while (dr.Read())
            {
                Texto t = null;
                if (dr.GetValue(2) != null)
                {
                    t = new Texto();
                    TextoDAL daltex = new TextoDAL();
                    t = daltex.Consultar(Convert.ToInt32(dr.GetValue(2)));
                }
                Conteudo cc = null;
                if (dr.GetValue(1) != null)
                {
                    cc = new Conteudo();
                    ConteudoDAL dalcont = new ConteudoDAL();
                    cc = dalcont.Consultar(Convert.ToInt32(dr.GetValue(1)));
                }
                Imagem i = null;
                if (dr.GetValue(4) != null)
                {
                    i = new Imagem();
                    ImagemDAL dalimg = new ImagemDAL();
                    i = dalimg.Consultar(Convert.ToInt32(dr.GetValue(4)));
                }
                Video v = null;
                if (dr.GetValue(3) != null)
                {
                    v = new Video();
                    VideoDAL dalvid = new VideoDAL();
                    v = dalvid.Consultar(Convert.ToInt32(dr.GetValue(3)));
                }
                c = new ConteudoTexto
                {
                    ID       = Convert.ToInt32(dr.GetValue(0)),
                    Conteudo = cc,
                    Texto    = t,
                    Imagem   = i,
                    Video    = v,
                    Ordem    = Convert.ToInt32(dr.GetValue(5)),
                    Usuario  = Convert.ToInt32(dr.GetValue(6))
                };
            }
            comm.Connection.Close();
            return(c);
        }
Пример #2
0
        /// <summary>
        /// Altera um Conteudo na tabela conteudo no Banco de dados
        /// Com Imagem Podendo ser nula
        /// </summary>
        /// <param name="C"> Parametro do tipo Conteudo| com id </param>
        public void Alterar(Conteudo C)
        {
            SqlCommand comm = new SqlCommand("", Banco.Abrir());

            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.CommandText = "AlterarConteudo";
            comm.Parameters.Add("@ID", SqlDbType.Int).Value       = C.ID;
            comm.Parameters.Add("@Materia", SqlDbType.Int).Value  = C.Materia.ID;
            comm.Parameters.Add("@Nome", SqlDbType.VarChar).Value = C.Nome;
            comm.Parameters.Add("@Ordem", SqlDbType.Int).Value    = C.Ordem;
            comm.Parameters.Add("@Usuario", SqlDbType.Int).Value  = C.Usuario;
            if (C.Imagem != null)
            {
                comm.Parameters.Add("@Imagem", SqlDbType.VarBinary).Value = C.Imagem;
            }
            comm.ExecuteNonQuery();
            comm.Parameters.Clear();
            comm.CommandType = CommandType.Text;
            comm.CommandText = "Delete From ConteudoTexto Where ID_Conteudo = " + C.ID;
            comm.ExecuteNonQuery();
            comm.CommandText = "Select Count(*) from Resumo Where ID_Conteudo = " + C.ID;
            if (Convert.ToInt32(comm.ExecuteScalar()) > 0)
            {
                comm.CommandText = "Delete From Resumo Where ID_Conteudo = " + C.ID;
                comm.ExecuteNonQuery();
            }
            foreach (var item in C.ConteudoTexto)
            {
                if (item.Texto != null)
                {
                    TextoDAL dal = new TextoDAL();
                    dal.Deletar(item.Texto.ID);
                }
                if (item.Imagem != null)
                {
                    ImagemDAL dal = new ImagemDAL();
                    dal.Deletar(item.Imagem.ID);
                }
                if (item.Video != null)
                {
                    VideoDAL dal = new VideoDAL();
                    dal.Deletar(item.Video.ID);
                }
            }
            comm.Connection.Close();
        }