Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EugenioNhampossa committed May 17, 2022
0 parents commit 3c2eb78
Show file tree
Hide file tree
Showing 69 changed files with 6,427 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.vscode
/out
12 changes: 12 additions & 0 deletions SistemaGestaoVendas.iml
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 added itextpdf-5.4.0.jar
Binary file not shown.
Binary file added jcommon-1.0.23.jar
Binary file not shown.
Binary file added jfreechart-1.0.19.jar
Binary file not shown.
Empty file.
187 changes: 187 additions & 0 deletions src/Controller/ControllerArmazem.java
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()));
}
}

}
185 changes: 185 additions & 0 deletions src/Controller/ControllerCliente.java
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;
}
}
}
}
}
Loading

0 comments on commit 3c2eb78

Please sign in to comment.