Datasets:

ArXiv:
License:
File size: 1,986 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.dsw.beans;

import br.dsw.dao.TeatroDAO;
import br.dsw.dao.UsuarioDAO;
import br.dsw.pojo.Teatro;
import br.dsw.pojo.Usuario;
import java.sql.SQLException;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author pedro
 */
@ManagedBean
@RequestScoped
public class TeatroBean {

    private Teatro teatro;

    public String lista() {
        return "/teatros/listar.xhtml";
    }

    public String cadastra() {
        teatro = new Teatro();
        return "/teatros/alterar.xhtml";
    }

    public String cadastraParaUsuario(Usuario u) {
        UsuarioDAO udau = new UsuarioDAO();
        teatro = udau.getTeatro(u);
        if (teatro == null) {
            teatro = new Teatro();
        }
        teatro.setUsuario(u);
        return "/teatros/alterar.xhtml";
    }

    public String edita(String id) {
        TeatroDAO dao = new TeatroDAO();
        teatro = dao.get(id);
        return "/teatros/alterar.xhtml";
    }

    public String salva() throws Exception {
        TeatroDAO dao = new TeatroDAO();
        try {
            dao.update(teatro);
        } catch (Exception e) {
            throw new Exception("Este usuário ja possui teatro, ou então o nome já está em uso");
        }
        return lista();
    }

    public String delete(Teatro teatro) {
        TeatroDAO dao = new TeatroDAO();
        dao.delete(teatro);
        return lista();
    }

    public String volta() {
        return "/index.xhtml?faces-redirect=true";
    }

    public List<Teatro> getTeatros() throws SQLException {
        TeatroDAO dao = new TeatroDAO();
        return dao.getAll();
    }

    public Teatro getTeatro() {
        return teatro;
    }

    public TeatroBean() {
        teatro = new Teatro();
    }
}