Exemplo n.º 1
0
 protected void gvGerenciamentoAutores_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     try
     {
         GridViewRow loRGridViewRow = this.gvGerenciamentoAutores.Rows[e.RowIndex];
         decimal     ldcIdAutor     = Convert.ToDecimal((this.gvGerenciamentoAutores.Rows[e.RowIndex].FindControl("lblIdAutor") as
                                                         Label).Text);
         Autores loAutor = this.ioAutoresDAO.BuscaAutores(ldcIdAutor).FirstOrDefault();
         if (loAutor != null)
         {
             //Crie LivrosDAO e o método FindLivrosByAutor() que deve receber um Autor como parâmetro e retornar
             //uma lista de livros.
             LivrosDAO loLivrosDAO = new LivrosDAO();
             if (loLivrosDAO.FindLivrosByAutor(loAutor).Count != 0)
             {
                 HttpContext.Current.Response.Write("<script>alert('Não é possível remover o autor selecionado pois existem livros associados a ele.');</script>");
             }
             else
             {
                 this.ioAutoresDAO.DeletaAutor(loAutor);
                 this.CarregaDados();
             }
         }
     }
     catch (Exception ex)
     {
         HttpContext.Current.Response.Write("<script>alert('Erro na remoção do autor selecionado.');</script>");
         HttpContext.Current.Response.Write($"<script>console.log({ex.Message});</script>");
         HttpContext.Current.Response.Write($"<script>console.log({ex.StackTrace});</script>");
     }
 }
Exemplo n.º 2
0
        private void CarregaDados()
        {
            if (AutorSessao != null)
            {
                // se existir sessao de autor
                // carregar os livros daquele autor
                this.ListaLivros = ioLivrosDAO.FindLivrosByAutor(AutorSessao);
            }
            else
            {
                // se não, carrega tudo
                // carrega uma lista de livros
                this.ListaLivros = ioLivrosDAO.BuscaLivros();
            }

            // carrega o gridview de livros
            gvGerenciamentoLivros.DataSource = ListaLivros.OrderBy(livro => livro.liv_nm_titulo);
            gvGerenciamentoLivros.DataBind();
        }