This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3c2eb78
Showing
69 changed files
with
6,427 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.vscode | ||
/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="swingx-all-1.6.4" level="project" /> | ||
</component> | ||
</module> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
package Controller; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
import java.text.DecimalFormat; | ||
import java.util.Arrays; | ||
import java.util.Vector; | ||
|
||
import javax.swing.JOptionPane; | ||
import javax.swing.RowFilter; | ||
import javax.swing.table.DefaultTableModel; | ||
import javax.swing.table.TableModel; | ||
import javax.swing.table.TableRowSorter; | ||
|
||
import Model.Armazem; | ||
import Model.Produto; | ||
import View.TelaArmazens; | ||
|
||
public class ControllerArmazem { | ||
|
||
private final TelaArmazens view; | ||
private final Vector<Object> armazens; | ||
private final Vector<Object> produtos; | ||
|
||
public ControllerArmazem(TelaArmazens view, Vector<Object> armazens, Vector<Object> produtos) { | ||
this.view = view; | ||
this.armazens = armazens; | ||
this.produtos = produtos; | ||
view.addAccaoBtGravar(new AccaoBtGravar()); | ||
view.addAccaoBtApagar(new AccaoBtApagar()); | ||
view.addAccaoTxtPesquisar(new AccaoPesquisar()); | ||
view.addAccaoBtEditar(new AccaoBtEditar()); | ||
preencherTabela(); | ||
} | ||
|
||
private class AccaoBtGravar implements ActionListener { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (!view.getNomeArmazem().equals("")) { | ||
if (verificarNome(view.getNomeArmazem())) { | ||
Armazem a = new Armazem(geradorId(), view.getNomeArmazem()); | ||
if (armazens.add(a) && a.getDao().escrever(a)) { | ||
view.limparTxt(); | ||
view.message("Dados Registrados com sucesso"); | ||
} else { | ||
view.errorMessage("Falha na Gravação dos dados"); | ||
} | ||
} else { | ||
view.errorMessage("O armazém [" + view.getNomeArmazem() + "] já existe\nInsira um nome Diferente"); | ||
} | ||
} else { | ||
view.errorMessage("Preencha o campo obrigatório [Nome]"); | ||
} | ||
preencherTabela(); | ||
} | ||
} | ||
|
||
public boolean verificarNome(String nome) { | ||
for (Object obj : armazens) { | ||
if (((Armazem) obj).getNome().equals(nome)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private class AccaoBtApagar implements ActionListener { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (view.getTbArmazens().getSelectedRow() != -1) { | ||
int codigo = Integer | ||
.parseInt((String) view.getTbArmazens().getValueAt(view.getTbArmazens().getSelectedRow(), 0)); | ||
if (!verificar(codigo)) { | ||
Armazem a = pesquisar(codigo); | ||
if (view.confirmationMessage("Deseja apagar??") == JOptionPane.YES_OPTION) { | ||
armazens.remove(a); | ||
a.getDao().actualizar(armazens); | ||
view.message("Apagado com sucesso"); | ||
preencherTabela(); | ||
} | ||
} else { | ||
view.errorMessage( | ||
"O Registro do armazém não pode ser apagado\nO armazém está ralacionado a um produto."); | ||
} | ||
} else { | ||
view.errorMessage("Nenhuma linha seleccionada!"); | ||
} | ||
} | ||
} | ||
|
||
private boolean verificar(int codigo) { | ||
for (Object obj : produtos) { | ||
if (((Produto) obj).getCodArmazem() == codigo) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private class AccaoBtEditar implements ActionListener { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (verificarNome(view.getNomeArmazem())) { | ||
for (Object obj : armazens) { | ||
Armazem a = pesquisar(view.getCodigo()); | ||
if (a.equals(obj)) { | ||
int c = view.confirmationMessage("Deseja actualizar o armazém [" + a.getNome() + "] ?"); | ||
if (c == JOptionPane.YES_OPTION) { | ||
((Armazem) obj).setNome(view.getNomeArmazem()); | ||
((Armazem) obj).getDao().actualizar(armazens); | ||
view.message("Armazém actualizado com sucesso"); | ||
preencherTabela(); | ||
} | ||
view.desabilitarBtEditar(); | ||
view.hobilitarBtGravar(); | ||
view.limparTxt(); | ||
break; | ||
} | ||
} | ||
} else { | ||
view.errorMessage("O nome introduzido já existe!\nEscolha outro"); | ||
} | ||
} | ||
} | ||
|
||
public Armazem pesquisar(int id) { | ||
for (Object obj : armazens) { | ||
if (((Armazem) obj).getId() == id) { | ||
return (Armazem) obj; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void preencherTabela() { | ||
Vector<Vector<String>> linhas = new Vector<>(); | ||
|
||
Vector<String> colunas = new Vector<>(Arrays.asList("Codigo", "Nome")); | ||
|
||
for (Object armazem : armazens) { | ||
Vector<String> v = new Vector<>(); | ||
|
||
v.add(new DecimalFormat("0000").format(((Armazem) armazem).getId())); | ||
v.add(((Armazem) armazem).getNome()); | ||
|
||
linhas.add(v); | ||
|
||
} | ||
DefaultTableModel model = new DefaultTableModel(linhas, colunas) { | ||
@Override | ||
public boolean isCellEditable(int row, int column) { | ||
return false; | ||
} | ||
}; | ||
view.getTbArmazens().setModel(model); | ||
|
||
} | ||
|
||
private int geradorId() { | ||
if (armazens.isEmpty()) { | ||
return 1; | ||
} else { | ||
return ((Armazem) armazens.lastElement()).getId() + 1; | ||
} | ||
} | ||
|
||
private class AccaoPesquisar implements KeyListener { | ||
@Override | ||
public void keyTyped(KeyEvent e) { | ||
} | ||
|
||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent e) { | ||
TableRowSorter<TableModel> rowSorter = new TableRowSorter<>(view.getTbArmazens().getModel()); | ||
view.getTbArmazens().setRowSorter(rowSorter); | ||
rowSorter.setRowFilter(RowFilter.regexFilter(view.getPesquisa())); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package Controller; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
import java.text.DecimalFormat; | ||
import java.util.Arrays; | ||
import java.util.Vector; | ||
|
||
import javax.swing.JOptionPane; | ||
import javax.swing.RowFilter; | ||
import javax.swing.table.DefaultTableModel; | ||
import javax.swing.table.TableModel; | ||
import javax.swing.table.TableRowSorter; | ||
|
||
import Model.Cliente; | ||
import Model.Venda; | ||
import View.TelaClientes; | ||
|
||
public class ControllerCliente { | ||
private final TelaClientes view; | ||
private final Vector<Object> clientes; | ||
private final Vector<Object> vendas; | ||
|
||
public ControllerCliente(TelaClientes view, Vector<Object> clientes, Vector<Object> vendas) { | ||
this.view = view; | ||
this.clientes = clientes; | ||
this.vendas = vendas; | ||
view.addActionBtGravar(new ActionBtGravar()); | ||
view.addActionTxtPesquisar(new ActionTxtPesquisar()); | ||
view.addActionBtApagar(new ActionBtApagar()); | ||
view.addAccaoBtEditar(new ActionBtEditar()); | ||
preencherTabela(); | ||
} | ||
|
||
private class ActionBtGravar implements ActionListener { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (!view.getNome().equals("")) { | ||
if (!verificarNome(view.getNome())) { | ||
Cliente cliente = new Cliente(geradorId(), view.getNome(), view.getEmail(), view.getCell()); | ||
if (cliente.getDao().escrever(cliente) && clientes.add(cliente)) { | ||
preencherTabela(); | ||
view.message("Cliente Registrado com sucesso!"); | ||
view.limparTxt(); | ||
} else { | ||
view.errorMessage("Falha no Registro do cliente"); | ||
} | ||
} else { | ||
view.errorMessage("O Cliente [" + view.getNome() + "] já está registrado"); | ||
} | ||
} else { | ||
view.errorMessage("Preencha o campo obrigatório [Nome]"); | ||
} | ||
} | ||
} | ||
|
||
public boolean verificarNome(String nome) { | ||
for (Object obj : clientes) { | ||
if (((Cliente) obj).getNome().equals(nome)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private class ActionTxtPesquisar implements KeyListener { | ||
@Override | ||
public void keyReleased(KeyEvent e) { | ||
TableRowSorter<TableModel> rowSorter = new TableRowSorter<>(view.getTbClientes().getModel()); | ||
view.getTbClientes().setRowSorter(rowSorter); | ||
rowSorter.setRowFilter(RowFilter.regexFilter(view.getPesquisa())); | ||
} | ||
|
||
@Override | ||
public void keyTyped(KeyEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
|
||
} | ||
} | ||
|
||
private class ActionBtApagar implements ActionListener { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (view.getTbClientes().getSelectedRow() != -1) { | ||
int codigo = Integer | ||
.parseInt((String) view.getTbClientes().getValueAt(view.getTbClientes().getSelectedRow(), 0)); | ||
if (!verificar(codigo)) { | ||
Cliente c = pesquisar(codigo); | ||
if (view.confirmationMessage("Deseja apagar??") == JOptionPane.YES_OPTION) { | ||
clientes.remove(c); | ||
c.getDao().actualizar(clientes); | ||
view.message("Apagado com sucesso"); | ||
preencherTabela(); | ||
} | ||
} else { | ||
view.errorMessage("Não pode apagar os dados do Cliente\nO cliente está relacionado a uma venda"); | ||
} | ||
} else { | ||
view.errorMessage("Nenhuma linha seleccionada"); | ||
} | ||
|
||
} | ||
} | ||
|
||
private boolean verificar(int codigo) { | ||
for (Object obj : vendas) { | ||
if (((Venda) obj).getIdCli() == codigo) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public Cliente pesquisar(int id) { | ||
for (Object obj : clientes) { | ||
if (((Cliente) obj).getId() == id) { | ||
return (Cliente) obj; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void preencherTabela() { | ||
Vector<Vector<String>> linhas = new Vector<>(); | ||
|
||
Vector<String> colunas = new Vector<>(Arrays.asList("Código", "Nome", "Celular", "Email")); | ||
|
||
for (Object cliente : clientes) { | ||
Vector<String> v = new Vector<>(); | ||
|
||
v.add(new DecimalFormat("0000").format(((Cliente) cliente).getId())); | ||
v.add(((Cliente) cliente).getNome()); | ||
v.add(((Cliente) cliente).getEmail()); | ||
v.add(((Cliente) cliente).getCell()); | ||
|
||
linhas.add(v); | ||
|
||
} | ||
DefaultTableModel model = new DefaultTableModel(linhas, colunas) { | ||
@Override | ||
public boolean isCellEditable(int row, int column) { | ||
return false; | ||
} | ||
}; | ||
view.getTbClientes().setModel(model); | ||
} | ||
|
||
private int geradorId() { | ||
if (clientes.isEmpty()) { | ||
return 1; | ||
} else { | ||
return ((Cliente) clientes.lastElement()).getId() + 1; | ||
} | ||
} | ||
|
||
private class ActionBtEditar implements ActionListener { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
for (Object obj : clientes) { | ||
Cliente c = pesquisar(view.getCodigo()); | ||
if (c.equals(obj)) { | ||
int confirm = view.confirmationMessage("Deseja actualizar o cliente [" + c.getNome() + "] ?"); | ||
if (confirm == JOptionPane.YES_OPTION) { | ||
((Cliente) obj).setNome(view.getNome()); | ||
((Cliente) obj).setEmail(view.getEmail()); | ||
((Cliente) obj).setCell(view.getCell()); | ||
((Cliente) obj).getDao().actualizar(clientes); | ||
view.message("Dados do Cliente actualizados com sucesso"); | ||
preencherTabela(); | ||
} | ||
view.desabilitarBtEditar(); | ||
view.hobilitarBtGravar(); | ||
view.limparTxt(); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.