Commit 8643d18f authored by Bruno H. Labres's avatar Bruno H. Labres

Arrumamos os erros

parent 80cdc170
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/home/commander/Downloads/sqlite-jdbc-3.7.2.jar"/>
<classpathentry kind="output" path=""/>
</classpath>
/DAO.class
/DAOinterface$1.class
/DAOinterface.class
/SQLiteJDBConnection.class
/empresa.class
/DAOInterface$1.class
/DAOInterface.class
/DAOInterface$2.class
/Editando$1.class
/Editando.class
/Editando$2.class
/Editando$3.class
/DAOInterface$3.class
/Empresa.class
/TelaEmpresas$1.class
/TelaEmpresas$2.class
/TelaEmpresas$3.class
/TelaEmpresas.class
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>src</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/ConnectDataBase.class
package bd;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectDataBase {
public Connection conexao()
{
Connection c = null;
try
{
File file = new File("db_nutricao");
if(!file.exists())
{
System.out.println("Banco de dados não encontrado");
return null;
}
else
{
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:db_nutricao");
}
}
catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
return c;
}
}
\ No newline at end of file
/DaoImpl.class
/Dao.class
package dao;
public interface Dao {
}
package dao;
import bd.ConnectDataBase;
import java.sql.Connection;
public class DaoImpl {
private static ConnectDataBase connectDataBase;
private static Connection c;
static public Connection getConnection(){
if(c == null){
connectDataBase = new ConnectDataBase();
c = connectDataBase.conexao();
}
return c;
}
}
\ No newline at end of file
File added
package elemento;
public class Elemento {
private String nome;
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
/ElementoDaoImpl.class
/ElementoDao.class
package elemento.dao;
public interface ElementoDao {
}
package elemento.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import dao.DaoImpl;
import elemento.Elemento;
public class ElementoDaoImpl {
public void insert(Elemento e)
{
String sql = "INSERT INTO elemento(nome,endereco) VALUES(?)";
try {
PreparedStatement pstmt = DaoImpl.getConnection().prepareStatement(sql);
pstmt.setString(1, e.getNome());
pstmt.executeUpdate();
}catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
public void update(Elemento e)
{
String sql = "UPDATE elemento SET nome = '"+ e.getNome()+ "' WHERE id ="+ e.getId();
try {
PreparedStatement pstmt = DaoImpl.getConnection().prepareStatement(sql);
pstmt.executeUpdate();
}catch (SQLException es) {
System.out.println(es.getMessage());
}
}
public void delete(Elemento e)
{
String sql = "DELETE FROM elemento WHERE elemento.id ="+e.getId();
try {
PreparedStatement pstmt = DaoImpl.getConnection().prepareStatement(sql);
pstmt.executeUpdate();
}catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
public List<Elemento> retornaTodas() throws SQLException {
List<Elemento> elementos = new ArrayList<Elemento>();
String sql = "select * from elemento";
PreparedStatement stmt = DaoImpl.getConnection().prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Elemento e = new Elemento();
e.setNome(rs.getString("nome"));
elementos.add(e);
}
rs.close();
stmt.close();
return elementos;
}
}
package empresa;
public class Empresa {
int cnpj;
String nome;
String endereco;
String responsavel;
public void setCnpj(int cnpj){
this.cnpj = cnpj;
}
public void setNome(String nome){
this.nome = nome;
}
public void setEndereco(String endereco){
this.endereco = endereco;
}
public void setResponsavel(String responsavel){
this.responsavel = responsavel;
}
public int getCnpj(){
return this.cnpj;
}
public String getNome(){
return this.nome;
}
public String getEndereco(){
return this.endereco;
}
public String getResponsavel(){
return this.responsavel;
}
}
/EmpresaDAO.class
/EmpresaDAOImpl.class
package empresa.dao;
import empresa.Empresa;
public interface EmpresaDAO {
public void insert(Empresa empresa);
public void delete(Empresa empresa);
}
package empresa.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import dao.DaoImpl;
import empresa.Empresa;
public class EmpresaDAOImpl implements EmpresaDAO {
public void insert(Empresa empresa)
{
String sql = "INSERT INTO EMPRESA(cnpj,endereco,nome,responsavel_tecnico) VALUES(?,?,?,?)";
try {
PreparedStatement pstmt = DaoImpl.getConnection().prepareStatement(sql);
pstmt.setInt(1, empresa.getCnpj());
pstmt.setString(2, empresa.getEndereco());
pstmt.setString(3, empresa.getNome());
pstmt.setString(4, empresa.getResponsavel());
pstmt.executeUpdate();
}catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public void update(Empresa empresa)
{
String sql = "UPDATE EMPRESA SET nome = '"+ empresa.getNome()+ "',endereco = '"+ empresa.getEndereco()+ "',responsavel_tecnico= '"+empresa.getResponsavel()+"' WHERE CNPJ ="+ empresa.getCnpj();
try {
PreparedStatement pstmt = DaoImpl.getConnection().prepareStatement(sql);
pstmt.executeUpdate();
}catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public void delete(Empresa empresa)
{
String sql = "DELETE FROM EMPRESA WHERE EMPRESA.CNPJ ="+empresa.getCnpj();
try {
PreparedStatement pstmt = DaoImpl.getConnection().prepareStatement(sql);
pstmt.executeUpdate();
}catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public List<Empresa> retornaTodas() throws SQLException {
List<Empresa> empresas = new ArrayList<Empresa>();
String sql = "select * from empresa";
PreparedStatement stmt = DaoImpl.getConnection().prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Empresa e = new Empresa();
e.setCnpj(rs.getInt("CNPJ"));
e.setNome(rs.getString("nome"));
e.setEndereco(rs.getString("endereco"));
e.setResponsavel(rs.getString("responsavel_tecnico"));
empresas.add(e);
}
rs.close();
stmt.close();
return empresas;
}
}
/EmpresaPrincipal$1.class
/EmpresaPrincipal.class
/EmpresaPrincipal$2.class
/EmpresaCadastro$1.class
/EmpresaCadastro.class
/EmpresaPrincipal$3.class
/EmpresaTableModel.class
/FrameListener.class
/EmpresaPrincipal$4.class
/EmpresaPrincipal$5.class
/EmpresaEditar$1.class
/EmpresaEditar.class
/EmpresaCadastro$2.class
/EmpresaCadastro$3.class
/EmpresaPrincipal$6.class
package empresa.janelas;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import empresa.Empresa;
import empresa.dao.EmpresaDAOImpl;
import empresa.janelas.publicoAlvojanelas.PublicoAlvoPrincipal;
import refeicao.janela.RefeicaoPrincipal;
import javax.swing.UIManager;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.awt.Color;
public class EmpresaCadastro extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private EmpresaPrincipal parent;
private JButton btnAdicionarPblicoAlvo;
private JButton btnAdicionarCardpio;
/**
* Launch the application.
*/
/**
* Create the frame.
*/
public EmpresaCadastro(EmpresaPrincipal p) {
parent=p;
setBackground(UIManager.getColor("CheckBox.focus"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(UIManager.getColor("Button.darkShadow"));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblCnpj = new JLabel("CNPJ: ");
lblCnpj.setBounds(12, 51, 80, 15);
lblCnpj.setFont(new Font("Ubuntu", Font.BOLD, 12));
contentPane.add(lblCnpj);
JLabel lblNome = new JLabel("Nome: ");
lblNome.setBounds(12, 98, 40, 15);
lblNome.setFont(new Font("Ubuntu", Font.BOLD, 12));
contentPane.add(lblNome);
JLabel lblEndereo = new JLabel("Endereço: ");
lblEndereo.setBounds(12, 148, 60, 15);
lblEndereo.setFont(new Font("Ubuntu", Font.BOLD, 12));
contentPane.add(lblEndereo);
JLabel lblResponsvel = new JLabel("Responsável: ");
lblResponsvel.setBounds(12, 193, 80, 15);
lblResponsvel.setFont(new Font("Ubuntu", Font.BOLD, 12));
contentPane.add(lblResponsvel);
textField = new JTextField();
textField.setBounds(115, 49, 114, 19);
contentPane.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(115, 96, 114, 19);
contentPane.add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setFont(new Font("Ubuntu", Font.PLAIN, 12));
textField_2.setBounds(115, 146, 114, 19);
contentPane.add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setBounds(115, 191, 114, 19);
contentPane.add(textField_3);
textField_3.setColumns(10);
JButton btnSalvar = new JButton("Salvar");
btnSalvar.setBackground(Color.WHITE);
btnSalvar.setFont(new Font("Ubuntu", Font.BOLD, 12));
btnSalvar.setBounds(308, 223, 117, 25);
contentPane.add(btnSalvar);
btnAdicionarPblicoAlvo = new JButton("Adicionar Público Alvo");
btnAdicionarPblicoAlvo.setBackground(Color.WHITE);
btnAdicionarPblicoAlvo.setBounds(221, 12, 217, 25);
contentPane.add(btnAdicionarPblicoAlvo);
btnAdicionarPblicoAlvo.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent evento){
try {
PublicoAlvoPrincipal publico = new PublicoAlvoPrincipal();
publico.setVisible(true);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
);
btnAdicionarCardpio = new JButton("Adicionar Refeição");
btnAdicionarCardpio.setBackground(Color.WHITE);
btnAdicionarCardpio.setBounds(12, 12, 197, 25);
btnAdicionarCardpio.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent evento){
try {
RefeicaoPrincipal ref = new RefeicaoPrincipal();
ref.setVisible(true);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
);
contentPane.add(btnAdicionarCardpio);
btnSalvar.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent evento){
Empresa e = new Empresa();
e.setCnpj(Integer.parseInt(textField.getText()));
e.setNome(textField_1.getText());
e.setEndereco(textField_2.getText());
e.setResponsavel(textField_3.getText());
EmpresaDAOImpl dao = new EmpresaDAOImpl();
dao.insert(e);
try {
parent.atualizaTabela();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dispose();
}
}
);
}
}
package empresa.janelas;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import empresa.Empresa;
import empresa.dao.EmpresaDAOImpl;
import javax.swing.UIManager;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
public class EmpresaEditar extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private EmpresaPrincipal parent;
private Empresa empresa;
/**
* Launch the application.
*/
/**
* Create the frame.
*/
public EmpresaEditar(Empresa e, EmpresaPrincipal p) {
parent=p;
empresa = e;
setBackground(UIManager.getColor("CheckBox.focus"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(UIManager.getColor("Button.darkShadow"));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNome = new JLabel("Nome: ");
lblNome.setBounds(12, 98, 40, 15);
lblNome.setFont(new Font("Ubuntu", Font.BOLD, 12));
contentPane.add(lblNome);
JLabel lblEndereo = new JLabel("Endereço: ");
lblEndereo.setBounds(12, 148, 60, 15);
lblEndereo.setFont(new Font("Ubuntu", Font.BOLD, 12));
contentPane.add(lblEndereo);
JLabel lblResponsvel = new JLabel("Responsável: ");
lblResponsvel.setBounds(12, 193, 80, 15);
lblResponsvel.setFont(new Font("Ubuntu", Font.BOLD, 12));
contentPane.add(lblResponsvel);
textField_1 = new JTextField();
textField_1.setBounds(115, 96, 114, 19);
contentPane.add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setFont(new Font("Ubuntu", Font.PLAIN, 12));
textField_2.setBounds(115, 146, 114, 19);
contentPane.add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setBounds(115, 191, 114, 19);
contentPane.add(textField_3);
textField_3.setColumns(10);
if(empresa != null){
textField_2.setText(empresa.getEndereco());
textField_1.setText(empresa.getNome());
textField_3.setText(empresa.getResponsavel());
}
JButton btnSalvar = new JButton("Salvar");
btnSalvar.setBackground(UIManager.getColor("Button.select"));
btnSalvar.setFont(new Font("Ubuntu", Font.BOLD, 12));
btnSalvar.setBounds(308, 223, 117, 25);
contentPane.add(btnSalvar);
btnSalvar.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent evento){
Empresa e = new Empresa();
e.setCnpj(empresa.getCnpj());
e.setNome(textField_1.getText());
e.setEndereco(textField_2.getText());
e.setResponsavel(textField_3.getText());
EmpresaDAOImpl dao = new EmpresaDAOImpl();
dao.update(e);
try {
parent.atualizaTabela();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dispose();
}
}
);
}
}
package empresa.janelas;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import javax.swing.UIManager;
import java.awt.Font;
import javax.swing.JTable;
import empresa.Empresa;
import empresa.dao.EmpresaDAOImpl;
import java.awt.Color;
public class EmpresaPrincipal extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable table;
private JButton btnEditar;
private int linhaSelecionada;
private JButton btnExcluir;
private Empresa empresa;
private JButton btnDetalhes;
private JButton btnFechar;