diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f6216a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.vscode +/out \ No newline at end of file diff --git a/SistemaGestaoVendas.iml b/SistemaGestaoVendas.iml new file mode 100755 index 0000000..0f94504 --- /dev/null +++ b/SistemaGestaoVendas.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/itextpdf-5.4.0.jar b/itextpdf-5.4.0.jar new file mode 100755 index 0000000..417112d Binary files /dev/null and b/itextpdf-5.4.0.jar differ diff --git a/jcommon-1.0.23.jar b/jcommon-1.0.23.jar new file mode 100755 index 0000000..4dbb094 Binary files /dev/null and b/jcommon-1.0.23.jar differ diff --git a/jfreechart-1.0.19.jar b/jfreechart-1.0.19.jar new file mode 100755 index 0000000..10f276c Binary files /dev/null and b/jfreechart-1.0.19.jar differ diff --git a/sqltools_20211101153131_10890.log b/sqltools_20211101153131_10890.log new file mode 100755 index 0000000..e69de29 diff --git a/src/Controller/ControllerArmazem.java b/src/Controller/ControllerArmazem.java new file mode 100755 index 0000000..3c17a1c --- /dev/null +++ b/src/Controller/ControllerArmazem.java @@ -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 armazens; + private final Vector produtos; + + public ControllerArmazem(TelaArmazens view, Vector armazens, Vector 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> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Codigo", "Nome")); + + for (Object armazem : armazens) { + Vector 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 rowSorter = new TableRowSorter<>(view.getTbArmazens().getModel()); + view.getTbArmazens().setRowSorter(rowSorter); + rowSorter.setRowFilter(RowFilter.regexFilter(view.getPesquisa())); + } + } + +} diff --git a/src/Controller/ControllerCliente.java b/src/Controller/ControllerCliente.java new file mode 100755 index 0000000..3964ab0 --- /dev/null +++ b/src/Controller/ControllerCliente.java @@ -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 clientes; + private final Vector vendas; + + public ControllerCliente(TelaClientes view, Vector clientes, Vector 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 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> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Código", "Nome", "Celular", "Email")); + + for (Object cliente : clientes) { + Vector 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; + } + } + } + } +} diff --git a/src/Controller/ControllerEstatistica.java b/src/Controller/ControllerEstatistica.java new file mode 100755 index 0000000..5521317 --- /dev/null +++ b/src/Controller/ControllerEstatistica.java @@ -0,0 +1,176 @@ +package Controller; + +import Model.Armazem; +import View.TelaEstatistica; +import Model.Produto; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.category.DefaultCategoryDataset; + +import javax.swing.table.DefaultTableModel; +import java.awt.Color; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Vector; + +public class ControllerEstatistica { + private final TelaEstatistica view; + private final Vector produtos; + private final Vector armazens; + private final Vector maisVendidos; + private final Vector vectorProdutos; + + public ControllerEstatistica(TelaEstatistica view, Vector produtos, Vector armazens) { + this.view = view; + this.produtos = produtos; + this.armazens = armazens; + maisVendidos = new Vector(); + vectorProdutos = (Vector) produtos.clone(); + determinarMaisVendidos(); + preencherTbMVendidos(); + criarGraficoQty(); + criarGraficArmazem(); + preencherTbPEncomenda(); + preencherTbValidade(); + } + + + public void determinarMaisVendidos() { + Object mv; + for (int a = 0; a < 5; a++) { + mv = determinarMaisVendido(); + if (mv != null) { + maisVendidos.add(mv); + } + } + } + + private Object determinarMaisVendido() { + Object max = null; + if (!vectorProdutos.isEmpty()) { + max = vectorProdutos.get(0); + } + for (int i = 1; i < vectorProdutos.size(); i++) { + if (((Produto) vectorProdutos.get(i)).getQtyVendida() > ((Produto) max).getQtyVendida()) { + max = vectorProdutos.get(i); + } + } + vectorProdutos.remove(max); + + return max; + } + + public void preencherTbMVendidos() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Código", "Nome", "Armazém", "Stock mínimo", "Unidades Vendidas")); + + for (Object produto : maisVendidos) { + if (((Produto) produto).getQtyVendida() > 0) { + Vector v = new Vector<>(); + v.add(new DecimalFormat("0000").format(((Produto) produto).getId())); + v.add(((Produto) produto).getNomeProd()); + v.add(nomeArmazem(((Produto) produto).getCodArmazem())); + v.add(String.valueOf(((Produto) produto).getStockMinimo())); + v.add(String.valueOf(((Produto) produto).getQtyVendida())); + linhas.add(v); + } + + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbMaisVendidos().setModel(model); + } + + public void preencherTbPEncomenda() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Código", "Nome", "Armazém", "Stock mínimo", "Qty em Stock")); + + for (Object produto : produtos) { + Vector v = new Vector<>(); + if (((Produto) produto).verificarPontoEncomenda()) { + v.add(String.valueOf(((Produto) produto).getId())); + v.add(((Produto) produto).getNomeProd()); + v.add(nomeArmazem(((Produto) produto).getCodArmazem())); + v.add(String.valueOf(((Produto) produto).getStockMinimo())); + v.add(String.valueOf(((Produto) produto).getQtyStock())); + linhas.add(v); + } + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbPEncomenda().setModel(model); + } + + public void preencherTbValidade() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Código", "Nome", "Qty", "Prazo de validade", "Condição")); + + for (Object produto : produtos) { + Vector v = new Vector<>(); + if (((Produto) produto).getQtyStock() > 0) { + if (((Produto) produto).verificarValidade()) { + v.add(String.valueOf(((Produto) produto).getId())); + v.add(((Produto) produto).getNomeProd()); + v.add(String.valueOf(((Produto) produto).getQtyStock())); + v.add(new SimpleDateFormat("MMMM, dd, yyyy").format(((Produto) produto).getDataValidade())); + v.add(((Produto) produto).verificarCondicao()); + linhas.add(v); + } + } + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbValidade().setModel(model); + } + + + private void criarGraficoQty() { + DefaultCategoryDataset barra = new DefaultCategoryDataset(); + for (Object produto : maisVendidos) { + barra.setValue(((Produto) produto).getQtyStock(), ((Produto) produto).getNomeProd(), ((Produto) produto).getNomeProd()); + } + JFreeChart grafico = ChartFactory.createStackedBarChart("Quantidade em stock dos mais vendidos", "Produto", "Quantidade", barra, PlotOrientation.VERTICAL, true, true, true); + ChartPanel cp = new ChartPanel(grafico); + grafico.setBackgroundPaint(Color.WHITE); + view.addGraficoQty(cp); + + } + + + private void criarGraficArmazem() { + DefaultCategoryDataset barra = new DefaultCategoryDataset(); + for (Object obj : armazens) { + barra.setValue(((Armazem) obj).getNrProdutos(), ((Armazem) obj).getNome(), ((Armazem) obj).getNome()); + } + JFreeChart grafico = ChartFactory.createStackedBarChart("Número de Produtos por Armazém", "Produto", "Quantidade", barra, PlotOrientation.VERTICAL, true, true, true); + ChartPanel cp = new ChartPanel(grafico); + view.addGraficoArm(cp); + } + + private String nomeArmazem(int codigo) { + for (Object a : armazens) { + if (((Armazem) a).getId() == codigo) { + return ((Armazem) a).getNome(); + } + } + return null; + } +} diff --git a/src/Controller/ControllerFornecedor.java b/src/Controller/ControllerFornecedor.java new file mode 100755 index 0000000..92ecc31 --- /dev/null +++ b/src/Controller/ControllerFornecedor.java @@ -0,0 +1,197 @@ +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.Fornecedor; +import Model.Fornecimento; +import View.TelaFornecedor; + +public class ControllerFornecedor { + + private final TelaFornecedor view; + private final Vector fornecedores; + private final Vector fornecimentos; + + public ControllerFornecedor(TelaFornecedor view, Vector fornecedores, Vector fornecimentos) { + this.view = view; + this.fornecedores = fornecedores; + this.fornecimentos = fornecimentos; + view.addAccaoBtGravar(new ActionBtGravar()); + view.addAccaoTxtPesquisar(new ActionTxtPesquisar()); + view.addAccaoBtApagar(new ActionBtApagar()); + view.addAccaoBtEditar(new ActionBtEditar()); + + preencherTabela(); + } + + private class ActionBtGravar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + if (!view.getNome().equals("")) { + try { + if (!verificarNome(view.getNome())) { + Fornecedor forn = new Fornecedor(geradorId(), view.getNome(), view.getEmail(), view.getCell(), + view.getNuit()); + if (forn.getDao().escrever(forn) && fornecedores.add(forn)) { + preencherTabela(); + view.message("Fornecedor Registrado com sucesso!"); + view.limparTxt(); + } else { + view.errorMessage("Falha no Registro do Fornecedor"); + } + } else { + view.errorMessage("O Fornecedor [" + view.getNome() + "] já está registrado"); + } + } catch (NumberFormatException ex) { + view.errorMessage("Formato de Nuit Inválido!"); + } + } else { + view.errorMessage("Preencha o campo obrigatório [Nome]"); + } + } + } + + public boolean verificarNome(String nome) { + for (Object obj : fornecedores) { + if (((Fornecedor) obj).getNome().equals(nome)) { + return true; + } + } + return false; + } + + private class ActionTxtPesquisar implements KeyListener { + @Override + public void keyReleased(KeyEvent e) { + TableRowSorter rowSorter = new TableRowSorter<>(view.getTbFornecedores().getModel()); + view.getTbFornecedores().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.getTbFornecedores().getSelectedRow() != -1) { + int codigo = Integer.parseInt( + (String) view.getTbFornecedores().getValueAt(view.getTbFornecedores().getSelectedRow(), 0)); + if (!verificar(codigo)) { + Fornecedor f = pesquisar(codigo); + if (view.confirmationMessage("Deseja apagar??") == JOptionPane.YES_OPTION) { + fornecedores.remove(f); + f.getDao().actualizar(fornecedores); + view.message("Apagado com sucesso"); + preencherTabela(); + } + } else { + view.errorMessage( + "Os Dados do fornecedor não podem ser apagados\nO fornecedor está relacionado a um fornecimento"); + } + } else { + view.errorMessage("Nenhama linha seleccionada!"); + } + + } + } + + public boolean verificar(int codigo) { + for (Object obj : fornecimentos) { + if (codigo == ((Fornecimento) obj).getIdForn()) { + return true; + } + } + return false; + } + + public Fornecedor pesquisar(int id) { + for (Object obj : fornecedores) { + if (((Fornecedor) obj).getId() == id) { + return (Fornecedor) obj; + } + } + return null; + } + + public void preencherTabela() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Código", "Nome", "Nuit", "Celular", "Email")); + + for (Object forn : fornecedores) { + Vector v = new Vector<>(); + + v.add(new DecimalFormat("0000").format(((Fornecedor) forn).getId())); + v.add(((Fornecedor) forn).getNome()); + v.add(String.valueOf(((Fornecedor) forn).getNuit())); + v.add(((Fornecedor) forn).getCell()); + v.add(((Fornecedor) forn).getEmail()); + + linhas.add(v); + + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbFornecedores().setModel(model); + } + + private int geradorId() { + if (fornecedores.isEmpty()) { + return 1; + } else { + return ((Fornecedor) fornecedores.lastElement()).getId() + 1; + } + } + + private class ActionBtEditar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + for (Object obj : fornecedores) { + Fornecedor fornecedor = pesquisar(view.getCodigo()); + if (fornecedor.equals(obj)) { + int confirm = view.confirmationMessage( + "Deseja actualizar os dados do fornecedor [" + fornecedor.getNome() + "] ?"); + if (confirm == JOptionPane.YES_OPTION) { + ((Fornecedor) obj).setNome(view.getNome()); + ((Fornecedor) obj).setEmail(view.getEmail()); + ((Fornecedor) obj).setCell(view.getCell()); + ((Fornecedor) obj).setNuit(view.getNuit()); + ((Fornecedor) obj).getDao().actualizar(fornecedores); + view.message("Dados do Fornecedor actualizados com sucesso"); + view.limparTxt(); + preencherTabela(); + } + view.desabilitarBtEditar(); + view.hobilitarBtGravar(); + view.limparTxt(); + break; + } + } + } + } +} diff --git a/src/Controller/ControllerFornecimento.java b/src/Controller/ControllerFornecimento.java new file mode 100755 index 0000000..69bc0b7 --- /dev/null +++ b/src/Controller/ControllerFornecimento.java @@ -0,0 +1,318 @@ +package Controller; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Vector; + +import javax.swing.JFileChooser; +import javax.swing.JTable; +import javax.swing.RowFilter; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; + +import com.itextpdf.text.BaseColor; +import com.itextpdf.text.Document; +import com.itextpdf.text.DocumentException; +import com.itextpdf.text.Element; +import com.itextpdf.text.Font; +import com.itextpdf.text.Paragraph; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.PdfPCell; +import com.itextpdf.text.pdf.PdfPTable; +import com.itextpdf.text.pdf.PdfWriter; + +import Model.Fornecedor; +import Model.Fornecimento; +import Model.ItemFornecido; +import Model.Produto; +import View.TelaFornecimento; + +public class ControllerFornecimento { + private final TelaFornecimento view; + private final Vector fornecimentos; + private final Vector produtos; + private final Vector fornecedores; + + public ControllerFornecimento(TelaFornecimento view, Vector fornecimentos, Vector produtos, + Vector fornecedores) { + this.view = view; + this.fornecimentos = fornecimentos; + this.fornecedores = fornecedores; + this.produtos = produtos; + + view.addAccaoBtAdicionar(new AccaoBtAdicionar()); + view.addAccaoBtRemover(new AccaoBtRemover()); + view.addAccaoBtCancelar(new AccaoBtCancelar()); + view.addAccaoBtConfirmar(new AccaoBtConfirmar()); + view.addAccaoTxtPesquisar(new AccaoTxtPesquisar()); + view.addAccaoBtExportar(new AccaoExportar()); + preencherCb(); + preencherTabela(); + } + + private class AccaoBtAdicionar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + try { + if (pesquisarNome(String.valueOf(view.getProduto()), produtos) != 0) { + String[] linha = new String[] { String.valueOf(view.getProduto()), String.valueOf(view.getQty()) }; + adicionarLinha(view.getTbProdForn(), linha); + view.limparTxt(); + } else { + view.errorMessage("Seleccione o produto"); + } + } catch (NumberFormatException ex) { + view.errorMessage("A quantidade deve ser um número\n" + ex.getMessage()); + } + } + } + + private class AccaoBtRemover implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + if (view.getTbProdForn().getRowCount() > 0) { + remLinha(view.getTbProdForn(), view.getTbProdForn().getSelectedRow()); + } else { + view.errorMessage("Nenhuma linha por remover"); + } + } + } + + private class AccaoBtCancelar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + view.limparTb(); + } + } + + private class AccaoBtConfirmar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + + DefaultTableModel dtm = (DefaultTableModel) view.getTbProdForn().getModel(); + int idProd = 0; + double qty = 0; + int idForn = pesquisarNome(String.valueOf(view.getFornecedor()), fornecedores); + if (view.getTbProdForn().getRowCount() != 0) { + if (idForn != 0) { + Vector itens = new Vector<>(); + for (int i = 0; i < view.getTbProdForn().getRowCount(); i++) { + idProd = pesquisarNome((String) dtm.getValueAt(i, 0), produtos); + qty = Double.parseDouble((String) dtm.getValueAt(i, 1)); + actualizarQty(qty, idProd); + itens.add(new ItemFornecido(idProd, qty)); + } + + Fornecimento fornecimento = new Fornecimento(geradorId(), idForn, view.getData(), itens); + if (fornecimento.getDao().escrever(fornecimento) && fornecimentos.add(fornecimento)) { + view.message("Fornecimento Registrado"); + view.message("Invenário actualizado com sucesoo"); + } + view.limparTxt(); + view.limparTb(); + preencherTabela(); + } else { + view.errorMessage("Seleccione o fornecedor"); + } + } else { + view.errorMessage("Sem dados por registrar"); + } + } + } + + public void actualizarQty(double qty, int idProd) { + for (Object obj : produtos) { + if (((Produto) obj).getId() == idProd) { + ((Produto) obj).somarQtyStock(qty); + ((Produto) obj).getDao().actualizar(produtos); + } + } + } + + private class AccaoTxtPesquisar implements KeyListener { + @Override + public void keyTyped(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + + } + + @Override + public void keyReleased(KeyEvent e) { + TableRowSorter rowSorter = new TableRowSorter<>(view.getTbFornecimento().getModel()); + view.getTbFornecimento().setRowSorter(rowSorter); + rowSorter.setRowFilter(RowFilter.regexFilter(view.getPesquisa())); + } + } + + public void remLinha(JTable tabela, int linha) { + DefaultTableModel model = (DefaultTableModel) tabela.getModel(); + if (linha != -1) { + model.removeRow(linha); + } else { + view.errorMessage("Seleccione uma linha"); + } + tabela = new JTable(model); + } + + public void adicionarLinha(JTable tabela, String[] linha) { + DefaultTableModel model = (DefaultTableModel) tabela.getModel(); + model.addRow(linha); + tabela = new JTable(model); + } + + public String pesquisarId(int id, Vector vector) { + for (Object obj : vector) { + if (obj instanceof Produto) { + if (((Produto) obj).getId() == id) { + return ((Produto) obj).getNomeProd(); + } + } + if (obj instanceof Fornecedor) { + if (((Fornecedor) obj).getId() == id) { + return ((Fornecedor) obj).getNome(); + } + } + } + return null; + } + + public int pesquisarNome(String nome, Vector vector) { + for (Object obj : vector) { + if (obj instanceof Produto) { + if (((Produto) obj).getNomeProd().equals(nome)) { + return ((Produto) obj).getId(); + } + } + if (obj instanceof Fornecedor) { + if (((Fornecedor) obj).getNome().equals(nome)) { + return ((Fornecedor) obj).getId(); + } + } + } + return 0; + } + + public void preencherCb() { + for (Object obj : produtos) { + view.addProduto(((Produto) obj).getNomeProd()); + } + for (Object obj : fornecedores) { + view.addFornecedor(((Fornecedor) obj).getNome()); + } + } + + public void preencherTabela() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>( + Arrays.asList("Código", "Fornecedor", "Produto", "Qty Fornecida", "Data")); + + for (Object forn : fornecimentos) { + for (ItemFornecido item : ((Fornecimento) forn).getItensFornecidos()) { + Vector v = new Vector<>(); + v.add(new DecimalFormat("0000").format(((Fornecimento) forn).getId())); + v.add(pesquisarId(((Fornecimento) forn).getIdForn(), fornecedores)); + v.add(pesquisarId(item.getIdProd(), produtos)); + v.add(String.valueOf(item.getQtyForn())); + v.add(new SimpleDateFormat("MMMM, dd, yyyy").format(((Fornecimento) forn).getData())); + linhas.add(v); + } + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbFornecimento().setModel(model); + } + + private int geradorId() { + if (fornecimentos.isEmpty()) { + return 1; + } else { + return ((Fornecimento) fornecimentos.lastElement()).getId() + 1; + } + } + + private class AccaoExportar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + try { + criarPDF(); + } catch (NullPointerException ex) { + view.message("Nenhum ficheiro seleccionado"); + } + } + } + + public String escolherDirectoria() { + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + int resultado = fileChooser.showOpenDialog(view); + if (resultado == JFileChooser.APPROVE_OPTION) { + File ficheiro = fileChooser.getSelectedFile(); + return ficheiro.getAbsolutePath(); + } + return null; + } + + public void criarPDF() throws NullPointerException { + Document doc = new Document(new Rectangle(900, 900)); + + try { + PdfWriter.getInstance(doc, new FileOutputStream(escolherDirectoria())); + doc.open(); + Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD, new BaseColor(255, 129, 101)); + Font fonte2 = new Font(Font.FontFamily.UNDEFINED, 13, Font.BOLD); + Paragraph p = new Paragraph("Relatório de Fornecimentos", fonte); + p.setAlignment(Element.ALIGN_CENTER); + doc.add(p); + Paragraph p2 = new Paragraph(" "); + doc.add(p2); + + PdfPTable tabela = new PdfPTable(5); + + PdfPCell codigo = new PdfPCell(new Paragraph("Código", fonte2)); + PdfPCell fornecedor = new PdfPCell(new Paragraph("Fornecedor", fonte2)); + PdfPCell produto = new PdfPCell(new Paragraph("Produto", fonte2)); + PdfPCell qtyFornecida = new PdfPCell(new Paragraph("Qty Fornecida", fonte2)); + PdfPCell data = new PdfPCell(new Paragraph("Data do Fornecimento", fonte2)); + + tabela.addCell(codigo); + tabela.addCell(fornecedor); + tabela.addCell(produto); + tabela.addCell(qtyFornecida); + tabela.addCell(data); + + for (int i = 0; i < view.getTbFornecimento().getRowCount(); i++) { + tabela.addCell((String) view.getTbFornecimento().getValueAt(i, 0)); + tabela.addCell((String) view.getTbFornecimento().getValueAt(i, 1)); + tabela.addCell((String) view.getTbFornecimento().getValueAt(i, 2)); + tabela.addCell((String) view.getTbFornecimento().getValueAt(i, 3)); + tabela.addCell((String) view.getTbFornecimento().getValueAt(i, 4)); + } + + doc.add(tabela); + doc.close(); + view.message("Ficheiro criado em com sucesso!"); + } catch (DocumentException | IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/Controller/ControllerLogin.java b/src/Controller/ControllerLogin.java new file mode 100755 index 0000000..b2e8bd1 --- /dev/null +++ b/src/Controller/ControllerLogin.java @@ -0,0 +1,85 @@ +package Controller; + +import Model.Armazem; +import Model.Cliente; +import Model.Fornecedor; +import Model.Fornecimento; +import Model.Produto; +import Model.User; +import Model.Venda; +import View.TelaLogin; +import View.TelaPrincipal; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Vector; + +public class ControllerLogin { + private final TelaLogin view; + private final Vector users; + private User userAutenticado; + + public ControllerLogin(TelaLogin view, Vector users) { + this.view = view; + this.users = users; + view.addAccaoBtEntrar(new AccaoBtEntrar()); + view.addAccaoBtCancelar(new AccaoBtCancelar()); + } + + + private class AccaoBtEntrar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + if (view.getNome().equals("admin") && view.getSenha().equals("admin")) { + userAutenticado = new User("", "Adiministrador", "Administrador", -1); + acessar(); + } else { + int control = 0; + for (Object user : users) { + if (((User) user).autenticar(view.getNome(), view.getSenha())) { + userAutenticado = ((User) user); + acessar(); + control = 1; + break; + } + } + if (control == 0) { + view.errorMessage("Senha e/ou nome de usáro incorrecto(s)\nTente Novamente!"); + } + } + } + } + + private void acessar() { + Armazem a = new Armazem(); + Vector armazens = a.getDao().ler(); + + Produto p = new Produto(); + Vector produtos = p.getDao().ler(); + + Cliente c = new Cliente(); + Vector clientes = c.getDao().ler(); + + Fornecedor f = new Fornecedor(); + Vector fornecedores = f.getDao().ler(); + + Fornecimento forn = new Fornecimento(); + Vector fornecimentos = forn.getDao().ler(); + + Venda venda = new Venda(); + Vector vendas = venda.getDao().ler(); + + TelaPrincipal tp = new TelaPrincipal(userAutenticado.getNomeUsuario(), userAutenticado.getAcesso()); + MainController mc = new MainController(tp, armazens, produtos, clientes, fornecedores, fornecimentos, vendas, users); + tp.setVisible(true); + + view.dispose(); + } + + private class AccaoBtCancelar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + view.dispose(); + } + } +} diff --git a/src/Controller/ControllerProduto.java b/src/Controller/ControllerProduto.java new file mode 100755 index 0000000..8541e33 --- /dev/null +++ b/src/Controller/ControllerProduto.java @@ -0,0 +1,287 @@ +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.text.SimpleDateFormat; +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.Fornecimento; +import Model.ItemFornecido; +import Model.ItemVenda; +import Model.Produto; +import Model.Venda; +import View.TelaProdutos; + +public class ControllerProduto { + private final TelaProdutos view; + private final Vector produtos; + private final Vector armazens; + private final Vector vendas; + private final Vector fornecimentos; + + public ControllerProduto(TelaProdutos view, Vector produtos, Vector armazens, Vector vendas, + Vector fornecimentos) { + this.view = view; + this.produtos = produtos; + this.armazens = armazens; + this.vendas = vendas; + this.fornecimentos = fornecimentos; + + view.addAccaoBtGravar(new AccaoBtGravar()); + view.addAccaoTxtPesquisar(new AccaoTxtPesquisar()); + view.addAccaoBtApagar(new AccaoBtApagar()); + view.addAccaoBtEditar(new AccaoBtEditar()); + preencherTabela(); + preencherArmazens(); + } + + private class AccaoBtGravar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + int codArm = codigoArmazem(); + if (codArm != 0) { + if (!view.getNome().equals("")) { + if (verificarNome(view.getNome())) { + try { + Produto produto = new Produto(geradorId(), view.getNome(), view.getPreco(), codArm, + view.getStockMinimo(), view.getData()); + if (view.getStockMinimo() >= 5) { + if (produto.getDao().escrever(produto) && produtos.add(produto)) { + view.message("Produto Registrado com sucesso"); + actualizarArm(codArm, 1); + view.limparTxt(); + preencherTabela(); + } else { + view.errorMessage("Falha no regitro do produto"); + } + } else { + view.errorMessage("O stock mínimo não pode ser menor que 5"); + } + } catch (NumberFormatException ex) { + view.errorMessage( + "Formato Incorrecto\nIntroduza números nos campos de Preço e/ou Stock mínimo "); + } + } else { + view.errorMessage( + "O produto [" + view.getNome() + "] já está registrado\nInsira um nome diferente"); + } + } else { + view.errorMessage("Insira o nome do produto"); + } + } else { + view.errorMessage("Seleccione o Armazém"); + } + } + } + + public void actualizarArm(int codArm, int accao) { + for (Object a : armazens) { + + if (((Armazem) a).getId() == codArm) { + if (accao == 1) { + ((Armazem) a).adicionarProduto(); + } else if (accao == 0) { + ((Armazem) a).removerProduto(); + } + ((Armazem) a).getDao().actualizar(armazens); + } + + } + + } + + public boolean verificarNome(String nome) { + for (Object obj : produtos) { + if (((Produto) obj).getNomeProd().equals(nome)) { + return false; + } + } + return true; + } + + private class AccaoTxtPesquisar implements KeyListener { + @Override + public void keyReleased(KeyEvent e) { + TableRowSorter rowSorter = new TableRowSorter<>(view.getTbProdutos().getModel()); + view.getTbProdutos().setRowSorter(rowSorter); + rowSorter.setRowFilter(RowFilter.regexFilter(view.getPesquisa())); + + } + + @Override + public void keyTyped(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + + } + + } + + private int codigoArmazem() { + for (Object a : armazens) { + if (((Armazem) a).getNome().equals(view.getArmazem())) { + return ((Armazem) a).getId(); + } + } + return 0; + } + + private Object buscarArmazem(int codigo) { + for (Object a : armazens) { + if (((Armazem) a).getId() == codigo) { + return a; + } + } + return ""; + } + + public void preencherArmazens() { + for (Object a : armazens) { + view.addArmazem(((Armazem) a).getNome()); + } + } + + public void preencherTabela() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Código", "Nome", "Preço Unitário", "Armazém", + "Qty em Stock", "Stock mínimo", "Prazo de Validade")); + + for (Object produto : produtos) { + Vector v = new Vector<>(); + + v.add(new DecimalFormat("0000").format(((Produto) produto).getId())); + v.add(((Produto) produto).getNomeProd()); + v.add(String.valueOf(((Produto) produto).getPrecoUnit())); + v.add(((Armazem) buscarArmazem(((Produto) produto).getCodArmazem())).getNome()); + v.add(String.valueOf(((Produto) produto).getQtyStock())); + v.add(String.valueOf(((Produto) produto).getStockMinimo())); + v.add(new SimpleDateFormat("MMMM, dd, yyyy").format(((Produto) produto).getDataValidade())); + linhas.add(v); + + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbProdutos().setModel(model); + } + + private int geradorId() { + if (produtos.isEmpty()) { + return 1; + } else { + return ((Produto) produtos.lastElement()).getId() + 1; + } + } + + private class AccaoBtApagar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + if (view.getTbProdutos().getSelectedRow() != -1) { + int codigo = Integer + .parseInt((String) view.getTbProdutos().getValueAt(view.getTbProdutos().getSelectedRow(), 0)); + if (!verificar(codigo)) { + if (view.confirmationMessage("Deseja apagar??") == JOptionPane.YES_OPTION) { + Produto p = pesquisar(codigo); + produtos.remove(p); + p.getDao().actualizar(produtos); + view.message("Apagado com sucesso"); + actualizarArm(p.getCodArmazem(), 0); + } + preencherTabela(); + } else { + view.errorMessage("Não pode apagar os dados do Produto\nHá registros relacionados ao produto"); + } + } else { + view.errorMessage("Nenhuma Linha Seleccionada!"); + } + } + } + + public void actualizarArmazem(Armazem armazem) { + + } + + private boolean verificar(int codigo) { + for (Object obj : vendas) { + for (ItemVenda item : ((Venda) obj).getItensVenda()) { + if (item.getIdProd() == codigo) { + return true; + } + } + } + + for (Object obj : fornecimentos) { + for (ItemFornecido item : ((Fornecimento) obj).getItensFornecidos()) + if (item.getIdProd() == codigo) { + return true; + } + } + return false; + } + + public Produto pesquisar(int id) { + for (Object obj : produtos) { + if (((Produto) obj).getId() == id) { + return (Produto) obj; + } + } + return null; + } + + private class AccaoBtEditar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + if (view.getStockMinimo() >= 5) { + for (Object obj : produtos) { + Produto produto = pesquisar(view.getCodigo()); + if (produto.equals(obj)) { + int confirm = view + .confirmationMessage("Deseja actualizar o produto [" + produto.getNomeProd() + "] ?"); + if (confirm == JOptionPane.YES_OPTION) { + ((Produto) obj).setNomeProd(view.getNome()); + ((Produto) obj).setPrecoUnit(view.getPreco()); + ((Produto) obj).setStockMinimo(view.getStockMinimo()); + ((Produto) obj).setCodArmazem(codArmazem((String) view.getArmazem())); + ((Produto) obj).setDataValidade(view.getData()); + ((Produto) obj).getDao().actualizar(produtos); + view.message("Dados do Produto actualizados com sucesso"); + preencherTabela(); + } + view.desabilitarBtEditar(); + view.hobilitarBtGravar(); + view.limparTxt(); + } + } + } else { + view.errorMessage("O stock mínimo não pode ser menor que 5"); + } + } + } + + private int codArmazem(String armazem) { + for (Object obj : armazens) { + if (((Armazem) obj).getNome().equals(armazem)) { + return ((Armazem) obj).getId(); + } + } + return 0; + } +} diff --git a/src/Controller/ControllerRelatorioVendas.java b/src/Controller/ControllerRelatorioVendas.java new file mode 100755 index 0000000..e56aece --- /dev/null +++ b/src/Controller/ControllerRelatorioVendas.java @@ -0,0 +1,201 @@ +package Controller; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Vector; + +import javax.swing.JFileChooser; +import javax.swing.RowFilter; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; + +import com.itextpdf.text.BaseColor; +import com.itextpdf.text.Document; +import com.itextpdf.text.DocumentException; +import com.itextpdf.text.Element; +import com.itextpdf.text.Font; +import com.itextpdf.text.Paragraph; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.PdfPCell; +import com.itextpdf.text.pdf.PdfPTable; +import com.itextpdf.text.pdf.PdfWriter; + +import Model.Cliente; +import Model.ItemVenda; +import Model.Produto; +import Model.Venda; +import View.TelaRelatorioVendas; + +public class ControllerRelatorioVendas { + private final TelaRelatorioVendas view; + private final Vector vendas; + private final Vector clientes; + private final Vector produtos; + + public ControllerRelatorioVendas(TelaRelatorioVendas view, Vector vendas, Vector clientes, + Vector produtos) { + this.view = view; + this.vendas = vendas; + this.clientes = clientes; + this.produtos = produtos; + view.addAccaoTxtPesquisar(new AccaoPesquisar()); + view.addAccaoBtExportar(new AccaoExportar()); + preencherTabela(); + } + + public void preencherTabela() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>( + Arrays.asList("Código", "Cliente", "P.Vendido", "Qty Vendida", "Preço", "P.Líquido", "Data da Venda")); + + for (Object venda : vendas) { + for (ItemVenda item : ((Venda) venda).getItensVenda()) { + Vector v = new Vector<>(); + double preco = pesquisar(item.getIdProd()).getPrecoUnit() * item.getQtyVendida(); + v.add(new DecimalFormat("0000").format(((Venda) venda).getId())); + v.add(pesquisarId(((Venda) venda).getIdCli(), clientes)); + v.add(pesquisarId(item.getIdProd(), produtos)); + v.add(String.valueOf(item.getQtyVendida())); + v.add(String.format("%.2f MT", preco)); + v.add(String.format("%.2f MT", preco + (preco * 0.17))); + v.add(new SimpleDateFormat("MMMM, dd, yyyy").format(((Venda) venda).getDataVenda())); + linhas.add(v); + } + + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbRelVendas().setModel(model); + } + + private class AccaoExportar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + try { + criarPDF(); + } catch (NullPointerException ex) { + view.message("Nenhum ficheiro seleccionado"); + } + } + } + + public String escolherDirectoria() { + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + int resultado = fileChooser.showOpenDialog(view); + if (resultado == JFileChooser.APPROVE_OPTION) { + File ficheiro = fileChooser.getSelectedFile(); + return ficheiro.getAbsolutePath(); + } + return null; + } + + public void criarPDF() throws NullPointerException { + Document doc = new Document(new Rectangle(900, 900)); + + try { + PdfWriter.getInstance(doc, new FileOutputStream(escolherDirectoria())); + doc.open(); + Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD, new BaseColor(255, 129, 101)); + Font fonte2 = new Font(Font.FontFamily.UNDEFINED, 13, Font.BOLD); + Paragraph p = new Paragraph("Relatório de Vendas", fonte); + p.setAlignment(Element.ALIGN_CENTER); + doc.add(p); + Paragraph p2 = new Paragraph(" "); + doc.add(p2); + + PdfPTable tabela = new PdfPTable(7); + + PdfPCell codigo = new PdfPCell(new Paragraph("Código", fonte2)); + PdfPCell cliente = new PdfPCell(new Paragraph("Cliente", fonte2)); + PdfPCell pVendido = new PdfPCell(new Paragraph("P.Vendido", fonte2)); + PdfPCell qtyVendida = new PdfPCell(new Paragraph("Qty Vendida", fonte2)); + PdfPCell preco = new PdfPCell(new Paragraph("Preço", fonte2)); + PdfPCell pLiq = new PdfPCell(new Paragraph("Preço Líquido", fonte2)); + PdfPCell data = new PdfPCell(new Paragraph("Data da Venda", fonte2)); + + tabela.addCell(codigo); + tabela.addCell(cliente); + tabela.addCell(pVendido); + tabela.addCell(qtyVendida); + tabela.addCell(preco); + tabela.addCell(pLiq); + tabela.addCell(data); + + for (int i = 0; i < view.getTbRelVendas().getRowCount(); i++) { + tabela.addCell((String) view.getTbRelVendas().getValueAt(i, 0)); + tabela.addCell((String) view.getTbRelVendas().getValueAt(i, 1)); + tabela.addCell((String) view.getTbRelVendas().getValueAt(i, 2)); + tabela.addCell((String) view.getTbRelVendas().getValueAt(i, 3)); + tabela.addCell((String) view.getTbRelVendas().getValueAt(i, 4)); + tabela.addCell((String) view.getTbRelVendas().getValueAt(i, 5)); + tabela.addCell((String) view.getTbRelVendas().getValueAt(i, 6)); + } + + doc.add(tabela); + doc.close(); + view.message("Ficheiro criado em com sucesso!"); + } catch (DocumentException | IOException e) { + e.printStackTrace(); + } + + } + + public Produto pesquisar(int id) { + for (Object obj : produtos) { + if (((Produto) obj).getId() == id) { + return (Produto) obj; + } + } + return null; + } + + private String pesquisarId(int id, Vector vector) { + for (Object obj : vector) { + if (obj instanceof Produto) { + if (((Produto) obj).getId() == id) { + return ((Produto) obj).getNomeProd(); + } + } + if (obj instanceof Cliente) { + if (((Cliente) obj).getId() == id) { + return ((Cliente) obj).getNome(); + } + } + } + return null; + } + + private class AccaoPesquisar implements KeyListener { + @Override + public void keyReleased(KeyEvent e) { + TableRowSorter rowSorter = new TableRowSorter<>(view.getTbRelVendas().getModel()); + view.getTbRelVendas().setRowSorter(rowSorter); + rowSorter.setRowFilter(RowFilter.regexFilter(view.getPesquisa())); + } + + @Override + public void keyTyped(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + } + } + +} diff --git a/src/Controller/ControllerUser.java b/src/Controller/ControllerUser.java new file mode 100755 index 0000000..7756cbf --- /dev/null +++ b/src/Controller/ControllerUser.java @@ -0,0 +1,166 @@ +package Controller; + +import Model.User; +import View.TelaUsuario; + +import javax.swing.JOptionPane; +import javax.swing.RowFilter; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; +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; + +public class ControllerUser { + private final TelaUsuario view; + protected Vector users; + + public ControllerUser(TelaUsuario view, Vector users) { + this.view = view; + this.users = users; + + 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("") || view.getSenha().equals("")) { + if (!verificarNome(view.getNome())) { + User user = new User(view.getSenha(), view.getNome(), view.getNvAcesso(), geradorId()); + if (user.getDao().escrever(user) && users.add(user)) { + preencherTabela(); + view.message("Usuário Registrado com sucesso!"); + view.limparTxt(); + } else { + view.errorMessage("Falha no Registro do usuário"); + } + } else { + view.errorMessage("O Usuário [" + view.getNome() + "] já está registrado"); + } + } else { + view.errorMessage("Preencha todos campos!"); + } + } + } + + public boolean verificarNome(String nome) { + for (Object obj : users) { + if (((User) obj).getNomeUsuario().equals(nome)) { + return true; + } + } + return false; + } + + private class ActionTxtPesquisar implements KeyListener { + @Override + public void keyReleased(KeyEvent e) { + TableRowSorter rowSorter = new TableRowSorter<>(view.getTbUsuarios().getModel()); + view.getTbUsuarios().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.getTbUsuarios().getSelectedRow() != -1) { + int codigo = Integer.parseInt((String) view.getTbUsuarios().getValueAt(view.getTbUsuarios().getSelectedRow(), 0)); + User u = pesquisar(codigo); + if (view.confirmationMessage("Deseja apagar??") == JOptionPane.YES_OPTION) { + users.remove(u); + u.getDao().actualizar(users); + view.message("Apagado com sucesso"); + preencherTabela(); + } + } else { + view.errorMessage("Nenhuma linha seleccionada"); + } + + } + } + + public User pesquisar(int id) { + for (Object obj : users) { + if (((User) obj).getId() == id) { + return (User) obj; + } + } + return null; + } + + public void preencherTabela() { + Vector> linhas = new Vector<>(); + + Vector colunas = new Vector<>(Arrays.asList("Código", "Nome do Usuário", "Senha", "Nível de Acesso")); + + for (Object user : users) { + Vector v = new Vector<>(); + + v.add(new DecimalFormat("0000").format(((User) user).getId())); + v.add(((User) user).getNomeUsuario()); + v.add(((User) user).getSenha()); + v.add(((User) user).getAcesso()); + + linhas.add(v); + } + DefaultTableModel model = new DefaultTableModel(linhas, colunas) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + view.getTbUsuarios().setModel(model); + } + + private int geradorId() { + if (users.isEmpty()) { + return 1; + } else { + return ((User) users.lastElement()).getId() + 1; + } + } + + private class ActionBtEditar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + for (Object obj : users) { + User user = pesquisar(view.getCodigo()); + if (user.equals(obj)) { + int confirm = view.confirmationMessage("Deseja actualizar o usuário [" + user.getNomeUsuario() + "] ?"); + if (confirm == JOptionPane.YES_OPTION) { + ((User) obj).setNomeUsuario(view.getNome()); + ((User) obj).setSenha(view.getSenha()); + ((User) obj).setAcesso(view.getNvAcesso()); + ((User) obj).getDao().actualizar(users); + view.message("Dados do Usuario actualizados com sucesso"); + preencherTabela(); + } + view.desabilitarBtEditar(); + view.hobilitarBtGravar(); + view.limparTxt(); + } + } + } + } +} diff --git a/src/Controller/ControllerVenda.java b/src/Controller/ControllerVenda.java new file mode 100755 index 0000000..b5b0213 --- /dev/null +++ b/src/Controller/ControllerVenda.java @@ -0,0 +1,211 @@ +package Controller; + +import Model.*; +import View.TelaVenda; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Vector; + +public class ControllerVenda { + private final TelaVenda view; + private final Vector vendas; + private final Vector clientes; + private final Vector produtos; + private final Vector prodPonto = new Vector<>(); + + public ControllerVenda(TelaVenda view, Vector vendas, Vector clientes, Vector produtos) { + this.view = view; + this.vendas = vendas; + this.clientes = clientes; + this.produtos = produtos; + + view.addAccaoBtAdicionar(new AccaoBtAdicionar()); + view.addAccaoBtRemover(new AccaoBtRemover()); + view.addAccaoBtCancelar(new AccaoBtCancelar()); + view.addAccaoBtConfirmar(new AccaoBtConfirmar()); + preencherCb(); + } + + private class AccaoBtAdicionar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + try { + if (pesquisarNome(String.valueOf(view.getProduto()), produtos) != 0) { + Produto produto = pesquisarProd(String.valueOf(view.getProduto())); + double preco = produto.getPrecoUnit() * view.getQty(); + String[] linha = new String[]{ + String.valueOf(view.getProduto()), + String.valueOf(view.getQty()), + String.format("%.2f MT", produto.getPrecoUnit()), + String.valueOf(preco) + }; + if (produto.getQtyStock() >= view.getQty()) { + adicionarLinha(view.getTbProdVenda(), linha); + view.limparTxt(); + calcularTotal(); + } else { + view.errorMessage("Apenas " + produto.getQtyStock() + " unidades disponíveis para " + produto.getNomeProd()); + } + } else { + view.errorMessage("Seleccione o produto"); + } + } catch (NumberFormatException ex) { + view.errorMessage("A quantidade deve ser um número\n" + ex.getMessage()); + } + } + } + + public void calcularTotal() { + double total = 0; + for (int i = 0; i < view.getTbProdVenda().getRowCount(); i++) { + total += Double.parseDouble((String) view.getTbProdVenda().getValueAt(i, 3)); + } + double totalIva = total * 0.17; + double totalLiquido = totalIva + total; + view.setLbTotalNr(total); + view.setLbIvaNr(totalIva); + view.setLbTotalLiq(totalLiquido); + } + + + private class AccaoBtRemover implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + if (view.getTbProdVenda().getRowCount() > 0) { + remLinha(view.getTbProdVenda(), view.getTbProdVenda().getSelectedRow()); + calcularTotal(); + } else { + view.errorMessage("Sem linhas por remover"); + } + } + } + + private class AccaoBtCancelar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + view.limparTb(); + view.limparCalc(); + } + } + + private class AccaoBtConfirmar implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + DefaultTableModel dtm = (DefaultTableModel) view.getTbProdVenda().getModel(); + int idProd = 0; + double qty = 0; + int idCli = pesquisarNome(String.valueOf(view.getCliente()), clientes); + if (view.getTbProdVenda().getRowCount() != 0) { + if (idCli != 0) { + Vector itens = new Vector<>(); + for (int i = 0; i < view.getTbProdVenda().getRowCount(); i++) { + idProd = pesquisarNome((String) dtm.getValueAt(i, 0), produtos); + qty = Double.parseDouble((String) dtm.getValueAt(i, 1)); + actualizarQty(qty, idProd, (String) dtm.getValueAt(i, 0)); + itens.add(new ItemVenda(qty, idProd)); + } + Venda venda = new Venda(geradorId(), idCli, view.getData(), itens); + if (venda.getDao().escrever(venda) && vendas.add(venda)) { + view.message("Venda Registrada"); + view.message("Inventário actualizado com sucesoo"); + view.limparTb(); + view.limparTxt(); + view.limparCalc(); + verificarPonto(); + } + } else { + view.errorMessage("Seleccione o Cliente"); + } + } else { + view.errorMessage("Sem dados por registrar"); + } + } + } + + public void verificarPonto() { + StringBuilder produto = new StringBuilder(); + for (String prod : prodPonto) { + produto.append("* ").append(prod).append("\n"); + } + if(!produto.isEmpty()) { + view.warningMassage("O(s) produto(s): \n" + produto + "Esta(ão) no ponto de encomenda"); + } + } + + public void actualizarQty(double qty, int idProd, String produto) { + for (Object obj : produtos) { + if (((Produto) obj).getId() == idProd) { + if (!((Produto) obj).subtrairQtyStock(qty)) { + view.errorMessage("Sem unidades suficientes do produto: " + produto); + } + ((Produto) obj).getDao().actualizar(produtos); + if (((Produto) obj).verificarPontoEncomenda()) { + prodPonto.add(((Produto) obj).getNomeProd()); + } + } + } + + } + + public void remLinha(JTable tabela, int linha) { + DefaultTableModel model = (DefaultTableModel) tabela.getModel(); + if (linha != -1) { + model.removeRow(linha); + tabela = new JTable(model); + } else { + view.errorMessage("Seleccione uma linha"); + } + } + + public void adicionarLinha(JTable tabela, String[] linha) { + DefaultTableModel model = (DefaultTableModel) tabela.getModel(); + model.addRow(linha); + tabela = new JTable(model); + } + + public int pesquisarNome(String nome, Vector vector) { + for (Object obj : vector) { + if (obj instanceof Produto) { + if (((Produto) obj).getNomeProd().equals(nome)) { + return ((Produto) obj).getId(); + } + } + if (obj instanceof Cliente) { + if (((Cliente) obj).getNome().equals(nome)) { + return ((Cliente) obj).getId(); + } + } + } + return 0; + } + + public Produto pesquisarProd(String nome) { + for (Object obj : produtos) { + if (((Produto) obj).getNomeProd().equals(nome)) { + return (Produto) obj; + } + } + return null; + } + + public void preencherCb() { + for (Object obj : produtos) { + view.addProduto(((Produto) obj).getNomeProd()); + } + for (Object obj : clientes) { + view.addCliente(((Cliente) obj).getNome()); + } + } + + + private int geradorId() { + if (vendas.isEmpty()) { + return 1; + } else { + return ((Venda) vendas.lastElement()).getId() + 1; + } + } +} diff --git a/src/Controller/MainController.java b/src/Controller/MainController.java new file mode 100755 index 0000000..2204426 --- /dev/null +++ b/src/Controller/MainController.java @@ -0,0 +1,208 @@ +package Controller; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Vector; + +import View.TelaArmazens; +import View.TelaClientes; +import View.TelaEstatistica; +import View.TelaFornecedor; +import View.TelaFornecimento; +import View.TelaPrincipal; +import View.TelaProdutos; +import View.TelaRelatorioVendas; +import View.TelaUsuario; +import View.TelaVenda; + +public class MainController { + private final TelaPrincipal view; + private final Vector armazens; + private final Vector produtos; + private final Vector clientes; + private final Vector fornecedores; + private final Vector fornecimentos; + private final Vector vendas; + private final Vector users; + + public MainController(TelaPrincipal view, Vector armazens, Vector produtos, Vector clientes, + Vector fornecedores, Vector fornecimentos, Vector vendas, Vector users) { + this.view = view; + this.armazens = armazens; + this.produtos = produtos; + this.clientes = clientes; + this.fornecedores = fornecedores; + this.fornecimentos = fornecimentos; + this.vendas = vendas; + this.users = users; + + view.addActionBtProdutos(new AccaoBtProdutos()); + view.addActionBtArmazens(new AccaoBtArmazens()); + view.addActionBtClientes(new AccaoBtClientes()); + view.addActionBtFornecedor(new AccaoBtFornecedor()); + view.addActionBtEstatisticas(new AccaoBtEstatistica()); + view.addActionBtVendas(new AccaoBtVendas()); + view.addActionBtNovaVenda(new AccaoBtNovaVenda()); + view.addActionBtFornecimento(new AccaoBtFornecimentos()); + view.addActionBtUsers(new AccaoBtUsers()); + } + + private class AccaoBtProdutos implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaProdutos tp = new TelaProdutos(); + view.getPg().setValue(30); + ControllerProduto cp = new ControllerProduto(tp, produtos, armazens, vendas, fornecimentos); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(tp); + view.getPg().setValue(100); + view.getPg().setVisible(false); + System.out.println("executado"); + }).start(); + } + } + + private class AccaoBtArmazens implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaArmazens ta = new TelaArmazens(); + view.getPg().setValue(30); + ControllerArmazem ca = new ControllerArmazem(ta, armazens, produtos); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(ta); + view.getPg().setValue(100); + view.getPg().setVisible(false); + }).start(); + } + } + + private class AccaoBtClientes implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaClientes tc = new TelaClientes(); + view.getPg().setValue(30); + ControllerCliente cc = new ControllerCliente(tc, clientes, vendas); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(tc); + view.getPg().setValue(100); + view.getPg().setVisible(false); + }).start(); + } + } + + private class AccaoBtFornecimentos implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaFornecimento tf = new TelaFornecimento(); + view.getPg().setValue(30); + ControllerFornecimento cf = new ControllerFornecimento(tf, fornecimentos, produtos, fornecedores); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(tf); + view.getPg().setValue(100); + view.getPg().setVisible(false); + }).start(); + + } + } + + private class AccaoBtFornecedor implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaFornecedor tf = new TelaFornecedor(); + view.getPg().setValue(30); + ControllerFornecedor cf = new ControllerFornecedor(tf, fornecedores, fornecimentos); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(tf); + view.getPg().setValue(100); + view.getPg().setVisible(false); + }).start(); + + } + } + + private class AccaoBtEstatistica implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaEstatistica te = new TelaEstatistica(); + view.getPg().setValue(30); + ControllerEstatistica ce = new ControllerEstatistica(te, produtos, armazens); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(te); + view.getPg().setValue(100); + view.getPg().setVisible(false); + + }).start(); + + } + } + + private class AccaoBtVendas implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaRelatorioVendas trv = new TelaRelatorioVendas(); + view.getPg().setValue(30); + ControllerRelatorioVendas cv = new ControllerRelatorioVendas(trv, vendas, clientes, produtos); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(trv); + view.getPg().setValue(100); + view.getPg().setVisible(false); + }).start(); + + } + } + + private class AccaoBtNovaVenda implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaVenda tv = new TelaVenda(); + view.getPg().setValue(30); + ControllerVenda cv = new ControllerVenda(tv, vendas, clientes, produtos); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(tv); + view.getPg().setValue(100); + view.getPg().setVisible(false); + }).start(); + } + } + + private class AccaoBtUsers implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(() -> { + view.getPg().setVisible(true); + TelaUsuario tu = new TelaUsuario(); + view.getPg().setValue(30); + ControllerUser uc = new ControllerUser(tu, users); + view.getPg().setValue(60); + view.getPg().setValue(80); + view.addTela(tu); + view.getPg().setValue(100); + view.getPg().setVisible(false); + }).start(); + } + } +} diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100755 index 0000000..a7e3ba5 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: View.TelaLogin + diff --git a/src/Model/Armazem.java b/src/Model/Armazem.java new file mode 100755 index 0000000..f6aec39 --- /dev/null +++ b/src/Model/Armazem.java @@ -0,0 +1,70 @@ +package Model; + +import Model.DAO.Dao; + +import java.io.Serial; +import java.io.Serializable; + +public class Armazem implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private int id; + private String nome; + private final Dao dao; + private int nrProdutos; + + public Armazem() { + dao = new Dao("Armazens"); + } + + public Armazem(int id, String nome) { + this.id = id; + this.nome = nome; + nrProdutos = 0; + dao = new Dao("Armazens"); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNome() { + return nome; + } + + public int getNrProdutos() { + return nrProdutos; + } + + public void adicionarProduto() { + this.nrProdutos = this.nrProdutos + 1; + } + + public void removerProduto() { + this.nrProdutos = this.nrProdutos - 1; + } + + public void setNome(String nome) { + this.nome = nome; + } + + public Dao getDao() { + return dao; + } + + @Override + public String toString() { + return "Armazem{" + + "id=" + id + + ", nome='" + nome + '\'' + + ", dao=" + dao + + ", nrProdutos=" + nrProdutos + + '}'; + } +} diff --git a/src/Model/Cliente.java b/src/Model/Cliente.java new file mode 100755 index 0000000..694c30a --- /dev/null +++ b/src/Model/Cliente.java @@ -0,0 +1,33 @@ +/* + * 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 Model; + +import Model.DAO.Dao; + +import java.io.Serial; + +/** + * + * @author eugenio + */ +public class Cliente extends Pessoa{ + + @Serial + private static final long serialVersionUID = 1L; + private final Dao dao; + + public Cliente(int id, String nome, String email, String cell) { + super(id, nome, email, cell); + dao = new Dao("Clientes"); + } + public Cliente(){ + dao = new Dao("Clientes"); + } + + public Dao getDao() { + return dao; + } +} diff --git a/src/Model/DAO/Dao.java b/src/Model/DAO/Dao.java new file mode 100755 index 0000000..cd86ff8 --- /dev/null +++ b/src/Model/DAO/Dao.java @@ -0,0 +1,94 @@ +/* + * 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 Model.DAO; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serial; +import java.io.Serializable; +import java.util.Vector; + +/** + * @author eugenio + */ +public class Dao implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private final String dir; + private final String ficheiro; + private File file; + + public Dao(String ficheiro) { + this.ficheiro = ficheiro; + dir = System.getProperty("user.home") + "/Venda Facil/Files/"; + File file = new File(dir); + var mkdirs = file.mkdirs(); + } + + public String getCaminho() { + return this.dir + this.ficheiro + ".dat"; + } + + public boolean escrever(Object obj) { + try { + FileOutputStream fOut = new FileOutputStream(getCaminho(), true); + ObjectOutputStream oOut = new ObjectOutputStream(fOut); + oOut.writeObject(obj); + oOut.close(); + return true; + } catch (IOException e) { + System.out.println("Erro na escrita dos dados\n"); + e.printStackTrace(); + return false; + } + } + + + public Vector ler() { + Vector v = new Vector<>(); + file = new File(getCaminho()); + if (file.exists()) { + try { + FileInputStream fIn = new FileInputStream(getCaminho()); + Object o; + while (fIn.available() > 0) { + ObjectInputStream oIn = new ObjectInputStream(fIn); + o = oIn.readObject(); + v.add(o); + } + return v; + } catch (IOException | ClassNotFoundException ex) { + ex.printStackTrace(); + return null; + } + } + return v; + } + + public boolean actualizar(Vector v) { + try { + file = new File(getCaminho()); + var delete = file.delete(); + + for (Object object : v) { + escrever(object); + } + return true; + } catch (Exception ex) { + System.out.println("Erro ao Actualizar\n" + ex); + ex.printStackTrace(); + return false; + } + + } + +} diff --git a/src/Model/Fornecedor.java b/src/Model/Fornecedor.java new file mode 100755 index 0000000..64e2df8 --- /dev/null +++ b/src/Model/Fornecedor.java @@ -0,0 +1,50 @@ +/* + * 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 Model; + +import Model.DAO.Dao; + +import java.io.Serial; + +/** + * + * @author eugenio + */ +public class Fornecedor extends Pessoa { + + @Serial + private static final long serialVersionUID = 1L; + private long nuit; + private final Dao dao; + + public Fornecedor(){ + dao = new Dao("Fornecedores"); + } + + public Fornecedor(int id, String nome, String email, String cell,long nuit) { + super(id, nome, email, cell); + this.nuit = nuit; + dao = new Dao("Fornecedores"); + } + public Dao getDao() { + return dao; + } + + public long getNuit() { + return nuit; + } + + public void setNuit(long nuit) { + this.nuit = nuit; + } + + @Override + public String toString() { + return "Fornecedor{" + + "nuit=" + nuit + + '}'; + } +} diff --git a/src/Model/Fornecimento.java b/src/Model/Fornecimento.java new file mode 100755 index 0000000..694cd23 --- /dev/null +++ b/src/Model/Fornecimento.java @@ -0,0 +1,133 @@ +/* + * 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 Model; + +import Model.DAO.Dao; + +import java.io.Serializable; +import java.util.Date; +import java.util.Vector; + +/** + * The type Fornecimento. + * + * @author eugenio + */ +public class Fornecimento implements Serializable { + + private static final long serialVersionUID = 1L; + + private int id; + private int idForn; + private Date data; + private Vector itensFornecidos; + private final Dao dao; + + /** + * Instantiates a new Fornecimento. + * + * @param id the id + * @param idForn the id forn + * @param data the data + * @param itensFornecidos the itens fornecidos + */ + public Fornecimento(int id, int idForn, Date data, Vector itensFornecidos) { + this.id = id; + this.idForn = idForn; + this.data = data; + this.itensFornecidos = itensFornecidos; + dao = new Dao("Fornecimentos"); + } + public Fornecimento(){ + dao = new Dao("Fornecimentos"); + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(int id) { + this.id = id; + } + + /** + * Gets id forn. + * + * @return the id forn + */ + public int getIdForn() { + return idForn; + } + + /** + * Sets id forn. + * + * @param idForn the id forn + */ + public void setIdForn(int idForn) { + this.idForn = idForn; + } + + /** + * Gets data. + * + * @return the data + */ + public Date getData() { + return data; + } + + /** + * Sets data. + * + * @param data the data + */ + public void setData(Date data) { + this.data = data; + } + + /** + * Gets itens fornecidos. + * + * @return the itens fornecidos + */ + public Vector getItensFornecidos() { + return itensFornecidos; + } + + /** + * Sets itens fornecidos. + * + * @param itensFornecidos the itens fornecidos + */ + public void setItensFornecidos(Vector itensFornecidos) { + this.itensFornecidos = itensFornecidos; + } + + public Dao getDao() { + return dao; + } + + @Override + public String toString() { + return "Fornecimento{" + + "id=" + id + + ", idForn=" + idForn + + ", data=" + data + + ", itensFornecidos=" + itensFornecidos + + '}'; + } +} diff --git a/src/Model/ItemFornecido.java b/src/Model/ItemFornecido.java new file mode 100755 index 0000000..f191723 --- /dev/null +++ b/src/Model/ItemFornecido.java @@ -0,0 +1,80 @@ +/* + * 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 Model; + +import java.io.Serial; +import java.io.Serializable; + + +/** + * The type Item fornecido. + * + * @author eugenio + */ +public class ItemFornecido implements Serializable{ + + @Serial + private static final long serialVersionUID = 1L; + + private int idProd; + private double qtyForn; + + /** + * Instantiates a new Item fornecido. + * + * @param idProd the id prod + * @param qtyForn the qty forn + */ + public ItemFornecido(int idProd, double qtyForn) { + this.idProd = idProd; + this.qtyForn = qtyForn; + } + + + /** + * Gets id prod. + * + * @return the id prod + */ + public int getIdProd() { + return idProd; + } + + /** + * Sets id prod. + * + * @param idProd the id prod + */ + public void setIdProd(int idProd) { + this.idProd = idProd; + } + + /** + * Gets qty forn. + * + * @return the qty forn + */ + public double getQtyForn() { + return qtyForn; + } + + /** + * Sets qty forn. + * + * @param qtyForn the qty forn + */ + public void setQtyForn(double qtyForn) { + this.qtyForn = qtyForn; + } + + @Override + public String toString() { + return "ItemFornecido{" + + " idProd=" + idProd + + ", qtyForn=" + qtyForn + + '}'; + } +} diff --git a/src/Model/ItemVenda.java b/src/Model/ItemVenda.java new file mode 100755 index 0000000..7da2e6b --- /dev/null +++ b/src/Model/ItemVenda.java @@ -0,0 +1,50 @@ +/* + * 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 Model; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author eugenio + */ +public class ItemVenda implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private double qtyVendida; + private int idProd; + + public ItemVenda(double qtyVendida, int idProd) { + this.qtyVendida = qtyVendida; + this.idProd = idProd; + } + + public double getQtyVendida() { + return qtyVendida; + } + + public void setQtyVendida(double qtyVendida) { + this.qtyVendida = qtyVendida; + } + + public int getIdProd() { + return idProd; + } + + public void setIdProd(int idProd) { + this.idProd = idProd; + } + + @Override + public String toString() { + return "ItemVenda{" + + ", qtyVendida=" + qtyVendida + + ", idProd=" + idProd + + '}'; + } +} \ No newline at end of file diff --git a/src/Model/Pessoa.java b/src/Model/Pessoa.java new file mode 100755 index 0000000..0ccadd8 --- /dev/null +++ b/src/Model/Pessoa.java @@ -0,0 +1,126 @@ +/* + * 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 Model; + + +import java.io.Serial; +import java.io.Serializable; + +/** + * The type Pessoa. + * + * @author eugenio + */ +public abstract class Pessoa implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + protected int id; + protected String nome; + protected String email; + protected String cell; + + /** + * Instantiates a new Pessoa. + * + * @param id the id + * @param nome the nome + * @param email the email + * @param cell the cell + */ + public Pessoa(int id, String nome, String email, String cell) { + this.id = id; + this.nome = nome; + this.email = email; + this.cell = cell; + } + public Pessoa(){ + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(int id) { + this.id = id; + } + + /** + * Gets nome. + * + * @return the nome + */ + public String getNome() { + return nome; + } + + /** + * Sets nome. + * + * @param nome the nome + */ + public void setNome(String nome) { + this.nome = nome; + } + + /** + * Gets email. + * + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * Sets email. + * + * @param email the email + */ + public void setEmail(String email) { + this.email = email; + } + + /** + * Gets cell. + * + * @return the cell + */ + public String getCell() { + return cell; + } + + /** + * Sets cell. + * + * @param cell the cell + */ + public void setCell(String cell) { + this.cell = cell; + } + + + @Override + public String toString() { + return "Pessoa{" + + "id=" + id + + ", nome='" + nome + '\'' + + ", email='" + email + '\'' + + ", cell='" + cell + '\'' + + '}'; + } +} diff --git a/src/Model/Produto.java b/src/Model/Produto.java new file mode 100755 index 0000000..8007099 --- /dev/null +++ b/src/Model/Produto.java @@ -0,0 +1,197 @@ +/* + * 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 Model; + +import Model.DAO.Dao; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Calendar; +import java.util.Date; + +/** + * The type Produto. + * + * @author eugenio + */ +public class Produto implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private int id; + private String nomeProd; + private double qtyStock; + private double precoUnit; + private int qtyVendida; + private int codArmazem; + private int stockMinimo; + private Date dataValidade; + private final Dao dao; + + public Produto() { + dao = new Dao("Produtos"); + } + + public Produto(int id, String nomeProd, double precoUnit, int codArmazem, int stockMinimo, Date dataValidade) { + this.id = id; + this.nomeProd = nomeProd; + this.qtyStock = 0; + this.qtyVendida = 0; + this.precoUnit = precoUnit; + this.codArmazem = codArmazem; + this.stockMinimo = stockMinimo; + this.dataValidade = dataValidade; + dao = new Dao("Produtos"); + } + + public int getQtyVendida() { + return qtyVendida; + } + + public void setQtyVendida(int qtyVendida) { + this.qtyVendida = qtyVendida; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the nomeProd + */ + public String getNomeProd() { + return nomeProd; + } + + /** + * @param nomeProd the nomeProd to set + */ + public void setNomeProd(String nomeProd) { + this.nomeProd = nomeProd; + } + + /** + * @return the qtyStock + */ + public double getQtyStock() { + return qtyStock; + } + + public boolean verificarPontoEncomenda() { + return qtyStock <= stockMinimo; + } + + public boolean verificarValidade() { + Calendar dataValidade = Calendar.getInstance(); + Calendar dataActual = Calendar.getInstance(); + dataValidade.setTime(this.getDataValidade()); + if (dataActual.get(Calendar.YEAR) >= dataValidade.get(Calendar.YEAR)) { + return dataActual.get(Calendar.MONTH) >= dataValidade.get(Calendar.MONTH) || dataActual.get(Calendar.MONTH) + 1 >= dataValidade.get(Calendar.MONTH); + } + return false; + } + + public String verificarCondicao() { + Calendar dataActual = Calendar.getInstance(); + Calendar dataValidade = Calendar.getInstance(); + dataValidade.setTime(this.getDataValidade()); + if (dataActual.get(Calendar.YEAR) >= dataValidade.get(Calendar.YEAR)) { + if (dataActual.get(Calendar.MONTH) >= dataValidade.get(Calendar.MONTH)) { + if (dataActual.get(Calendar.DAY_OF_MONTH) >= dataValidade.get(Calendar.DAY_OF_MONTH)) { + return "Expirou"; + } + } + } + return "Próximo da Data"; + } + + /** + * @return the precoUnit + */ + public double getPrecoUnit() { + return precoUnit; + } + + public int getStockMinimo() { + return stockMinimo; + } + + public Dao getDao() { + return dao; + } + + public Date getDataValidade() { + return dataValidade; + } + + public void setDataValidade(Date dataValidade) { + this.dataValidade = dataValidade; + } + + public void setStockMinimo(int stockMinimo) { + this.stockMinimo = stockMinimo; + } + + public int getCodArmazem() { + return codArmazem; + } + + public void setCodArmazem(int codArmazem) { + this.codArmazem = codArmazem; + } + + /** + * @param precoUnit the precoUnit to set + */ + public void setPrecoUnit(double precoUnit) { + this.precoUnit = precoUnit; + } + + public void somarQtyStock(double qty) { + this.qtyStock = this.qtyStock + qty; + } + + public boolean subtrairQtyStock(double qty) { + if (qty <= qtyStock) { + this.qtyStock = this.qtyStock - qty; + this.qtyVendida += qty; + return true; + } else { + return false; + } + } + + + public boolean verificarStock() { + return this.qtyStock <= stockMinimo; + } + + @Override + public String toString() { + return "Produto{" + + "id=" + id + + ", nomeProd='" + nomeProd + '\'' + + ", qtyStock=" + qtyStock + + ", precoUnit=" + precoUnit + + ", stockMinimo=" + stockMinimo + + '}'; + } +} diff --git a/src/Model/User.java b/src/Model/User.java new file mode 100755 index 0000000..0530b8c --- /dev/null +++ b/src/Model/User.java @@ -0,0 +1,88 @@ +/* + * 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 Model; + +import Model.DAO.Dao; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author eugenio + */ +public class User implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private int id; + private String senha; + private String nomeUsuario; + private String acesso; + private final Dao dao; + + public User(){ + dao = new Dao("Users"); + } + + public User(String senha, String nomeUsuario, String acesso, int id) { + this.id = id; + this.senha = senha; + this.nomeUsuario = nomeUsuario; + this.acesso = acesso; + dao = new Dao("Users"); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSenha() { + return senha; + } + + public void setSenha(String senha) { + this.senha = senha; + } + + public String getNomeUsuario() { + return nomeUsuario; + } + + public void setNomeUsuario(String nomeUsuario) { + this.nomeUsuario = nomeUsuario; + } + + public String getAcesso() { + return acesso; + } + + public void setAcesso(String acesso) { + this.acesso = acesso; + } + + public boolean autenticar(String usuario, String senha) { + return this.nomeUsuario.equals(usuario) && this.senha.equals(senha); + } + + public Dao getDao() { + return dao; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", senha='" + senha + '\'' + + ", nomeUsuario='" + nomeUsuario + '\'' + + ", acesso='" + acesso + '\'' + + '}'; + } +} diff --git a/src/Model/Venda.java b/src/Model/Venda.java new file mode 100755 index 0000000..934fe0e --- /dev/null +++ b/src/Model/Venda.java @@ -0,0 +1,104 @@ +/* + * 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 Model; + +import Model.DAO.Dao; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; +import java.util.Vector; + +/** + * @author eugenio + */ +public class Venda implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private int id; + private int idCli; + private Date dataVenda; + private Vector itensVenda; + private final Dao dao; + + public Venda(){ + dao = new Dao("Vendas"); + } + + public Venda(int id,int idCli, Date dataVenda, Vector itensVenda) { + this.id = id; + this.idCli = idCli; + this.dataVenda = dataVenda; + this.itensVenda = itensVenda; + dao = new Dao("Vendas"); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + /** + * @return the idCli + */ + public int getIdCli() { + return idCli; + } + + /** + * @param idCli the idCli to set + */ + public void setIdCli(int idCli) { + this.idCli = idCli; + } + + /** + * @return the dataVenda + */ + public Date getDataVenda() { + return dataVenda; + } + + /** + * @param dataVenda the dataVenda to set + */ + public void setDataVenda(Date dataVenda) { + this.dataVenda = dataVenda; + } + + /** + * @return the itensVenda + */ + public Vector getItensVenda() { + return itensVenda; + } + + /** + * @param itensVenda the itensVenda to set + */ + public void setItensVenda(Vector itensVenda) { + this.itensVenda = itensVenda; + } + + public Dao getDao() { + return dao; + } + + @Override + public String toString() { + return "Venda{" + + "id=" + id + + ", idCli=" + idCli + + ", dataVenda=" + dataVenda + + ", itensVenda=" + itensVenda + + '}'; + } +} diff --git a/src/View/Fonts/RobotoCondensed-Light.ttf b/src/View/Fonts/RobotoCondensed-Light.ttf new file mode 100755 index 0000000..43dd8f4 Binary files /dev/null and b/src/View/Fonts/RobotoCondensed-Light.ttf differ diff --git a/src/View/Icons/add-to-cart.png b/src/View/Icons/add-to-cart.png new file mode 100755 index 0000000..cc661a5 Binary files /dev/null and b/src/View/Icons/add-to-cart.png differ diff --git a/src/View/Icons/add.png b/src/View/Icons/add.png new file mode 100755 index 0000000..a2430ed Binary files /dev/null and b/src/View/Icons/add.png differ diff --git a/src/View/Icons/background.png b/src/View/Icons/background.png new file mode 100755 index 0000000..e40bc5d Binary files /dev/null and b/src/View/Icons/background.png differ diff --git a/src/View/Icons/cancel.png b/src/View/Icons/cancel.png new file mode 100755 index 0000000..a3406fd Binary files /dev/null and b/src/View/Icons/cancel.png differ diff --git a/src/View/Icons/confirm.png b/src/View/Icons/confirm.png new file mode 100755 index 0000000..00d9d61 Binary files /dev/null and b/src/View/Icons/confirm.png differ diff --git a/src/View/Icons/delete.png b/src/View/Icons/delete.png new file mode 100755 index 0000000..4333553 Binary files /dev/null and b/src/View/Icons/delete.png differ diff --git a/src/View/Icons/delivery.png b/src/View/Icons/delivery.png new file mode 100755 index 0000000..09cb0ec Binary files /dev/null and b/src/View/Icons/delivery.png differ diff --git a/src/View/Icons/edit.png b/src/View/Icons/edit.png new file mode 100755 index 0000000..5140585 Binary files /dev/null and b/src/View/Icons/edit.png differ diff --git a/src/View/Icons/export.png b/src/View/Icons/export.png new file mode 100755 index 0000000..ac28b76 Binary files /dev/null and b/src/View/Icons/export.png differ diff --git a/src/View/Icons/imgLogo.png b/src/View/Icons/imgLogo.png new file mode 100755 index 0000000..3090844 Binary files /dev/null and b/src/View/Icons/imgLogo.png differ diff --git a/src/View/Icons/imgLogo2.png b/src/View/Icons/imgLogo2.png new file mode 100755 index 0000000..eba15e8 Binary files /dev/null and b/src/View/Icons/imgLogo2.png differ diff --git a/src/View/Icons/logIn.png b/src/View/Icons/logIn.png new file mode 100755 index 0000000..335015b Binary files /dev/null and b/src/View/Icons/logIn.png differ diff --git a/src/View/Icons/login.png b/src/View/Icons/login.png new file mode 100755 index 0000000..1540eba Binary files /dev/null and b/src/View/Icons/login.png differ diff --git a/src/View/Icons/people.png b/src/View/Icons/people.png new file mode 100755 index 0000000..b3f721a Binary files /dev/null and b/src/View/Icons/people.png differ diff --git a/src/View/Icons/product.png b/src/View/Icons/product.png new file mode 100755 index 0000000..e681950 Binary files /dev/null and b/src/View/Icons/product.png differ diff --git a/src/View/Icons/remove.png b/src/View/Icons/remove.png new file mode 100755 index 0000000..3221697 Binary files /dev/null and b/src/View/Icons/remove.png differ diff --git a/src/View/Icons/sale-report.png b/src/View/Icons/sale-report.png new file mode 100755 index 0000000..7a4f1fe Binary files /dev/null and b/src/View/Icons/sale-report.png differ diff --git a/src/View/Icons/save.png b/src/View/Icons/save.png new file mode 100755 index 0000000..452baa0 Binary files /dev/null and b/src/View/Icons/save.png differ diff --git a/src/View/Icons/search.png b/src/View/Icons/search.png new file mode 100755 index 0000000..d17c322 Binary files /dev/null and b/src/View/Icons/search.png differ diff --git a/src/View/Icons/shop.png b/src/View/Icons/shop.png new file mode 100755 index 0000000..0ed7744 Binary files /dev/null and b/src/View/Icons/shop.png differ diff --git a/src/View/Icons/statistic.png b/src/View/Icons/statistic.png new file mode 100755 index 0000000..ad28039 Binary files /dev/null and b/src/View/Icons/statistic.png differ diff --git a/src/View/Icons/supplier.png b/src/View/Icons/supplier.png new file mode 100755 index 0000000..6673f29 Binary files /dev/null and b/src/View/Icons/supplier.png differ diff --git a/src/View/Icons/triangle-arrowDown.png b/src/View/Icons/triangle-arrowDown.png new file mode 100755 index 0000000..7118c0e Binary files /dev/null and b/src/View/Icons/triangle-arrowDown.png differ diff --git a/src/View/Icons/triangle-arrowUp.png b/src/View/Icons/triangle-arrowUp.png new file mode 100755 index 0000000..05d9995 Binary files /dev/null and b/src/View/Icons/triangle-arrowUp.png differ diff --git a/src/View/Icons/user.png b/src/View/Icons/user.png new file mode 100755 index 0000000..719f567 Binary files /dev/null and b/src/View/Icons/user.png differ diff --git a/src/View/Icons/users.png b/src/View/Icons/users.png new file mode 100755 index 0000000..d93bbdb Binary files /dev/null and b/src/View/Icons/users.png differ diff --git a/src/View/Icons/warehouse.png b/src/View/Icons/warehouse.png new file mode 100755 index 0000000..8b4c7fc Binary files /dev/null and b/src/View/Icons/warehouse.png differ diff --git a/src/View/TelaArmazens.java b/src/View/TelaArmazens.java new file mode 100755 index 0000000..c8210e6 --- /dev/null +++ b/src/View/TelaArmazens.java @@ -0,0 +1,276 @@ +package View; + +import org.jdesktop.swingx.JXCollapsiblePane; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Objects; + +public class TelaArmazens extends JPanel implements MouseListener { + private final JLabel lbTituloRegistro; + private final JLabel lbTituloConsulta; + private final JLabel lbImgLupa; + private final JLabel lbNome; + private final JTextArea txtPesquisar; + private final JTextArea txtNome; + private final JPanel pnPrincipal; + private final JPanel pnBt; + private final JPanel pnBtApagar; + private final JPanel pnPesquisa; + private final JPanel pnCentralCons; + private final JPanel pnCentralInser; + private final JPanel pnConsultaSup; + private final JPanel pnConsulta; + private final JPanel pnCbInsercao; + private final JPanel pnCbConsulta; + private final JButton btGravar; + private final JButton btApagar; + private final JButton btEditar; + private final JButton btColapse; + private final JScrollPane spArmazens; + private final JScrollPane spTabela; + private final JTable tbArmazens; + private final JXCollapsiblePane pnInsercao; + private int codigo; + + public TelaArmazens() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spArmazens = new JScrollPane(pnPrincipal); + spArmazens.setBorder(BorderFactory.createEmptyBorder()); + pnInsercao = new JXCollapsiblePane(JXCollapsiblePane.Direction.DOWN); + pnInsercao.setLayout(new BorderLayout(5, 5)); + pnInsercao.setCollapsed(true); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnConsulta = new JPanel(new BorderLayout(5, 5)); + pnCbConsulta = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbConsulta.setBackground(new Color(255, 147, 147)); + pnConsultaSup = new JPanel(new GridLayout(1, 2)); + pnBtApagar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnPesquisa = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbInsercao = new JPanel(new BorderLayout()); + pnCbInsercao.setBackground(new Color(255, 147, 147)); + pnCbInsercao.setMaximumSize(new Dimension(90000, pnCbInsercao.getHeight())); + pnCentralInser = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0)); + pnCentralCons = new JPanel(new GridLayout(1, 1)); + + lbTituloRegistro = new JLabel("Registro de Armazéns"); + lbTituloRegistro.setForeground(Color.WHITE); + lbTituloConsulta = new JLabel("Armazéns"); + lbTituloConsulta.setForeground(Color.WHITE); + lbImgLupa = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/search.png")))); + lbNome = new JLabel("Nome do Armazém: "); + + tbArmazens = new JTable(new DefaultTableModel()); + tbArmazens.setSelectionBackground(new Color(136, 224, 200)); + tbArmazens.setShowGrid(false); + tbArmazens.setShowHorizontalLines(true); + tbArmazens.setRowHeight(25); + tbArmazens.setAutoCreateRowSorter(true); + tbArmazens.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tbArmazens.getTableHeader().setBackground(new Color(0, 183, 164)); + spTabela = new JScrollPane(tbArmazens); + spTabela.setBorder(BorderFactory.createEmptyBorder()); + + txtNome = new JTextArea(2, 20); + txtNome.setLineWrap(true); + txtNome.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtPesquisar = new JTextArea(2, 15); + txtPesquisar.setLineWrap(true); + txtPesquisar.setSize(new Dimension(15, 20)); + txtPesquisar.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + btApagar = new JButton("Apagar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/delete.png")))); + btApagar.setBackground(new Color(255, 129, 101)); + btApagar.setForeground(Color.WHITE); + btEditar = new JButton("Editar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/edit.png")))); + btEditar.setBackground(new Color(79, 195, 247)); + btEditar.setForeground(Color.WHITE); + btEditar.setEnabled(false); + btGravar = new JButton("Gravar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/save.png")))); + btGravar.setForeground(Color.WHITE); + btGravar.setBackground(new Color(0, 229, 202)); + btColapse = new JButton(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + btColapse.setBorderPainted(false); + btColapse.setBackground(new Color(255, 147, 147)); + btColapse.setHorizontalAlignment(SwingConstants.RIGHT); + + pnCbInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnCbInsercao.add(lbTituloRegistro, BorderLayout.CENTER); + pnCbInsercao.add(btColapse, BorderLayout.EAST); + + pnCentralInser.add(lbNome); + pnCentralInser.add(txtNome); + + pnBt.add(btEditar); + pnBt.add(btGravar); + + pnInsercao.add(new JLabel(" "), BorderLayout.NORTH); + pnInsercao.add(pnCentralInser, BorderLayout.CENTER); + pnInsercao.add(new JLabel(" "), BorderLayout.EAST); + pnInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnInsercao.add(pnBt, BorderLayout.SOUTH); + + + pnCbConsulta.add(lbTituloConsulta); + pnPesquisa.add(txtPesquisar); + pnPesquisa.add(lbImgLupa); + pnBtApagar.add(btApagar); + pnConsultaSup.add(pnPesquisa); + pnConsultaSup.add(pnBtApagar); + + pnCentralCons.add(spTabela); + pnConsulta.add(new JLabel(" "), BorderLayout.SOUTH); + pnConsulta.add(pnCentralCons, BorderLayout.CENTER); + pnConsulta.add(pnConsultaSup, BorderLayout.NORTH); + pnConsulta.add(new JLabel(" "), BorderLayout.EAST); + pnConsulta.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbInsercao); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnInsercao); + pnPrincipal.add(pnCbConsulta); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnConsulta); + + this.add(spArmazens); + btColapse.addMouseListener(this); + btColapse.addActionListener(pnInsercao.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)); + tbArmazens.addMouseListener(this); + + } + + public void fecharPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + limparTxt(); + pnInsercao.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION); + btEditar.setEnabled(false); + btGravar.setEnabled(true); + } + + public void abrirPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowUp.png")))); + btGravar.setEnabled(true); + } + + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getSource() == btColapse) { + if (pnInsercao.isCollapsed()) { + fecharPnInsercao(); + } else { + abrirPnInsercao(); + + } + } + if (e.getClickCount() == 2 && e.getSource() == tbArmazens) { + codigo = Integer.parseInt((String) tbArmazens.getValueAt(tbArmazens.getSelectedRow(), 0)); + abrirPnInsercao(); + txtNome.setText((String) tbArmazens.getValueAt(tbArmazens.getSelectedRow(), 1)); + btEditar.setEnabled(true); + btGravar.setEnabled(false); + pnInsercao.setCollapsed(false); + } + + pnPrincipal.updateUI(); + + } + + public int getCodigo() { + return codigo; + } + + public void desabilitarBtEditar() { + btEditar.setEnabled(false); + } + + public void hobilitarBtGravar(){btGravar.setEnabled(true);} + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + + public void addAccaoBtGravar(ActionListener accao) { + btGravar.addActionListener(accao); + } + + public void addAccaoBtApagar(ActionListener accao) { + btApagar.addActionListener(accao); + } + + public void addAccaoBtEditar(ActionListener accao) { + btEditar.addActionListener(accao); + } + + public void addAccaoTxtPesquisar(KeyListener action) { + txtPesquisar.addKeyListener(action); + } + + public JTable getTbArmazens() { + return tbArmazens; + } + + public String getNomeArmazem() { + return txtNome.getText().trim(); + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + public void limparTxt() { + txtNome.setText(null); + } + + + public String getPesquisa() { + return txtPesquisar.getText().trim(); + } +} diff --git a/src/View/TelaClientes.java b/src/View/TelaClientes.java new file mode 100755 index 0000000..cad8be7 --- /dev/null +++ b/src/View/TelaClientes.java @@ -0,0 +1,306 @@ +package View; + +import org.jdesktop.swingx.JXCollapsiblePane; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Objects; + + +public class TelaClientes extends JPanel implements MouseListener { + private final JLabel lbTituloRegistro; + private final JLabel lbTituloConsulta; + private final JLabel lbImgLupa; + private final JLabel lbNome; + private final JLabel lbEmail; + private final JLabel lbCell; + private final JTextField txtNome; + private final JTextField txtEmail; + private final JTextField txtCell; + private final JTextArea txtPesquisar; + private final JPanel pnPrincipal; + private final JPanel pnBt; + private final JPanel pnBtApagar; + private final JPanel pnPesquisa; + private final JPanel pnCentralCons; + private final JPanel pnCentralInser; + private final JPanel pnConsultaSup; + private final JPanel pnConsulta; + private final JPanel pnCbInsercao; + private final JPanel pnCbConsulta; + private final JButton btGravar; + private final JButton btApagar; + private final JButton btEditar; + private final JButton btColapse; + private final JScrollPane spClientes; + private final JScrollPane spTabela; + private final JTable tbClientes; + private final JXCollapsiblePane pnInsercao; + private int codigo; + + public TelaClientes() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spClientes = new JScrollPane(pnPrincipal); + spClientes.setBorder(BorderFactory.createEmptyBorder()); + pnInsercao = new JXCollapsiblePane(JXCollapsiblePane.Direction.DOWN); + pnInsercao.setCollapsed(true); + pnInsercao.setLayout(new BorderLayout(5, 5)); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnConsulta = new JPanel(new BorderLayout(5, 5)); + pnCbConsulta = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbConsulta.setBackground(new Color(255, 147, 147)); + pnConsultaSup = new JPanel(new GridLayout(1, 2)); + pnBtApagar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnPesquisa = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbInsercao = new JPanel(new BorderLayout()); + pnCbInsercao.setBackground(new Color(255, 147, 147)); + pnCbInsercao.setMaximumSize(new Dimension(90000, pnCbInsercao.getHeight())); + pnCentralInser = new JPanel(new GridLayout(2, 4, 10, 10)); + pnCentralCons = new JPanel(new GridLayout(1, 1)); + + lbTituloRegistro = new JLabel("Registro de Clientes"); + lbTituloRegistro.setForeground(Color.WHITE); + lbTituloConsulta = new JLabel("Lista de Clientes"); + lbTituloConsulta.setForeground(Color.WHITE); + lbImgLupa = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/search.png")))); + lbNome = new JLabel("Nome do Cliente: "); + lbEmail = new JLabel("Email: "); + lbCell = new JLabel("Celular: "); + lbCell.setHorizontalAlignment(SwingConstants.CENTER); + + tbClientes = new JTable(new DefaultTableModel()); + tbClientes.setShowGrid(false); + tbClientes.setSelectionBackground(new Color(136, 224, 200)); + tbClientes.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tbClientes.getTableHeader().setBackground(new Color(0, 183, 164)); + tbClientes.setShowHorizontalLines(true); + tbClientes.setRowHeight(25); + tbClientes.setAutoCreateRowSorter(true); + spTabela = new JScrollPane(tbClientes); + spTabela.setBorder(BorderFactory.createEmptyBorder()); + + txtNome = new JTextField(); + + txtNome.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtCell = new JTextField(); + txtCell.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtEmail = new JTextField(); + txtEmail.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtPesquisar = new JTextArea(2, 15); + txtPesquisar.setLineWrap(true); + txtPesquisar.setSize(new Dimension(15, 20)); + txtPesquisar.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + btApagar = new JButton("Apagar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/delete.png")))); + btApagar.setBackground(new Color(255, 129, 101)); + btApagar.setForeground(Color.WHITE); + btEditar = new JButton("Editar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/edit.png")))); + btEditar.setBackground(new Color(79, 195, 247)); + btEditar.setForeground(Color.WHITE); + btEditar.setEnabled(false); + btGravar = new JButton("Gravar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/save.png")))); + btGravar.setForeground(Color.WHITE); + btGravar.setBackground(new Color(0, 229, 202)); + btColapse = new JButton(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + btColapse.setBorderPainted(false); + btColapse.setBackground(new Color(255, 147, 147)); + btColapse.setHorizontalAlignment(SwingConstants.RIGHT); + + pnCbInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnCbInsercao.add(lbTituloRegistro, BorderLayout.CENTER); + pnCbInsercao.add(btColapse, BorderLayout.EAST); + + pnCentralInser.add(lbNome); + pnCentralInser.add(txtNome); + pnCentralInser.add(lbCell); + pnCentralInser.add(txtEmail); + pnCentralInser.add(lbEmail); + pnCentralInser.add(txtCell); + pnCentralInser.add(new JLabel()); + pnCentralInser.add(new JLabel()); + + pnBt.add(btEditar); + pnBt.add(btGravar); + + pnInsercao.add(new JLabel(" "), BorderLayout.NORTH); + pnInsercao.add(pnCentralInser, BorderLayout.CENTER); + pnInsercao.add(new JLabel(" "), BorderLayout.EAST); + pnInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnInsercao.add(pnBt, BorderLayout.SOUTH); + + + pnCbConsulta.add(lbTituloConsulta); + pnPesquisa.add(txtPesquisar); + pnPesquisa.add(lbImgLupa); + pnBtApagar.add(btApagar); + pnConsultaSup.add(pnPesquisa); + pnConsultaSup.add(pnBtApagar); + + pnCentralCons.add(spTabela); + pnConsulta.add(new JLabel(" "), BorderLayout.SOUTH); + pnConsulta.add(pnCentralCons, BorderLayout.CENTER); + pnConsulta.add(pnConsultaSup, BorderLayout.NORTH); + pnConsulta.add(new JLabel(" "), BorderLayout.EAST); + pnConsulta.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbInsercao); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnInsercao); + pnPrincipal.add(pnCbConsulta); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnConsulta); + + this.add(spClientes); + btColapse.addMouseListener(this); + btColapse.addActionListener(pnInsercao.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)); + tbClientes.addMouseListener(this); + + } + + public void fecharPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + limparTxt(); + btEditar.setEnabled(false); + btGravar.setEnabled(true); + } + + public void abrirPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowUp.png")))); + btGravar.setEnabled(true); + } + + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getSource() == btColapse) { + if (pnInsercao.isCollapsed()) { + fecharPnInsercao(); + } else { + abrirPnInsercao(); + + } + } + + if (e.getClickCount() == 2 && e.getSource() == tbClientes) { + codigo = Integer.parseInt((String) tbClientes.getValueAt(tbClientes.getSelectedRow(), 0)); + abrirPnInsercao(); + txtNome.setText((String) tbClientes.getValueAt(tbClientes.getSelectedRow(), 1)); + txtEmail.setText((String) tbClientes.getValueAt(tbClientes.getSelectedRow(), 2)); + txtCell.setText((String) tbClientes.getValueAt(tbClientes.getSelectedRow(), 3)); + btEditar.setEnabled(true); + btGravar.setEnabled(false); + pnInsercao.setCollapsed(false); + } + + pnPrincipal.updateUI(); + + } + public void hobilitarBtGravar(){btGravar.setEnabled(true);} + + public int getCodigo() { + return codigo; + } + + public void addAccaoBtEditar(ActionListener accao) { + btEditar.addActionListener(accao); + } + + public void desabilitarBtEditar() { + btEditar.setEnabled(false); + } + + public void addActionBtGravar(ActionListener action) { + btGravar.addActionListener(action); + } + + public void addActionBtApagar(ActionListener action) { + btApagar.addActionListener(action); + } + + public void addActionTxtPesquisar(KeyListener action) { + txtPesquisar.addKeyListener(action); + } + + public String getPesquisa() { + return txtPesquisar.getText(); + } + + public String getNome() { + return txtNome.getText().trim(); + } + + public String getEmail() { + return txtEmail.getText().trim(); + } + + public String getCell() { + return txtCell.getText().trim(); + } + + public JTable getTbClientes() { + return tbClientes; + } + + public void limparTxt() { + txtNome.setText(null); + txtEmail.setText(null); + txtCell.setText(null); + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} diff --git a/src/View/TelaEstatistica.java b/src/View/TelaEstatistica.java new file mode 100755 index 0000000..41b8f2b --- /dev/null +++ b/src/View/TelaEstatistica.java @@ -0,0 +1,201 @@ +package View; + +import org.jfree.chart.ChartPanel; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +public class TelaEstatistica extends JPanel implements MouseListener { + private final JLabel lbTMVendidos; + private final JLabel lbTPEncomenda; + private final JLabel lbValidade; + private final JPanel pnPrincipal; + private final JPanel pnTbPEncomenda; + private final JPanel pnTbValidade; + private final JPanel pnCbValidade; + private final JPanel pnCentralValidade; + private final JPanel pnCbPEncomenda; + private final JPanel pnGraficoArm; + private final JPanel pnGraficoQty; + private final JPanel pnCentralCons; + private final JPanel pnCentralPE; + private final JPanel pnTbMVendidos; + private final JPanel pnCbMVendidos; + private final JScrollPane spEstatisticas; + private final JScrollPane spMVendidos; + private final JScrollPane spValidade; + private final JScrollPane spPEncomenda; + private final JTable tbMaisVendidos; + private final JTable tbPEncomenda; + private final JTable tbValidade; + + public TelaEstatistica() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spEstatisticas = new JScrollPane(pnPrincipal); + spEstatisticas.setBorder(BorderFactory.createEmptyBorder()); + pnTbMVendidos = new JPanel(new BorderLayout(5, 5)); + pnTbPEncomenda = new JPanel(new BorderLayout(5, 5)); + pnTbValidade = new JPanel(new BorderLayout(5, 5)); + pnCbMVendidos = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbMVendidos.setBackground(new Color(255, 147, 147)); + pnCbPEncomenda = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbPEncomenda.setBackground(new Color(255, 147, 147)); + pnCbValidade = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbValidade.setBackground(new Color(255, 147, 147)); + pnCentralCons = new JPanel(); + pnCentralCons.setLayout(new BoxLayout(pnCentralCons, BoxLayout.Y_AXIS)); + pnCentralPE = new JPanel(new GridLayout(1, 1)); + pnCentralValidade = new JPanel(new GridLayout(1, 1)); + pnGraficoQty = new JPanel(new GridLayout(1, 1)); + pnGraficoArm = new JPanel(new GridLayout(1, 1)); + + lbTMVendidos = new JLabel("Mais Vendidos"); + lbTMVendidos.setForeground(Color.WHITE); + lbTPEncomenda = new JLabel("Produtos no ponto de encomenda"); + lbTPEncomenda.setForeground(Color.WHITE); + lbValidade = new JLabel("Validade dos produtos"); + lbValidade.setForeground(Color.WHITE); + + tbMaisVendidos = new JTable(new DefaultTableModel()); + tbMaisVendidos.setRowHeight(25); + estiloTabela(tbMaisVendidos); + tbPEncomenda = new JTable(new DefaultTableModel()); + tbPEncomenda.setRowHeight(25); + estiloTabela(tbPEncomenda); + tbValidade = new JTable(new DefaultTableModel()); + tbValidade.setRowHeight(25); + estiloTabela(tbValidade); + + spMVendidos = new JScrollPane(tbMaisVendidos); + spMVendidos.setBorder(BorderFactory.createEmptyBorder()); + spMVendidos.setPreferredSize(new Dimension(0, 150)); + spPEncomenda = new JScrollPane(tbPEncomenda); + spPEncomenda.setBorder(BorderFactory.createEmptyBorder()); + spPEncomenda.setPreferredSize(new Dimension(0, 300)); + spValidade = new JScrollPane(tbValidade); + spValidade.setBorder(BorderFactory.createEmptyBorder()); + spValidade.setPreferredSize(new Dimension(0, 300)); + + pnCbMVendidos.add(lbTMVendidos); + pnCbPEncomenda.add(lbTPEncomenda); + pnCbValidade.add(lbValidade); + + pnCentralCons.add(spMVendidos); + pnCentralCons.add(pnGraficoQty); + pnCentralCons.add(pnGraficoArm); + pnTbMVendidos.add(new JLabel(" "), BorderLayout.SOUTH); + pnTbMVendidos.add(pnCentralCons, BorderLayout.CENTER); + pnTbMVendidos.add(new JLabel(" "), BorderLayout.EAST); + pnTbMVendidos.add(new JLabel(" "), BorderLayout.WEST); + + pnCentralPE.add(spPEncomenda); + pnTbPEncomenda.add(new JLabel(" "), BorderLayout.SOUTH); + pnTbPEncomenda.add(pnCentralPE, BorderLayout.CENTER); + pnTbPEncomenda.add(new JLabel(" "), BorderLayout.EAST); + pnTbPEncomenda.add(new JLabel(" "), BorderLayout.WEST); + + pnCentralValidade.add(spValidade); + pnTbValidade.add(new JLabel(" "), BorderLayout.SOUTH); + pnTbValidade.add(pnCentralValidade, BorderLayout.CENTER); + pnTbValidade.add(new JLabel(" "), BorderLayout.EAST); + pnTbValidade.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbMVendidos); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnTbMVendidos); + pnPrincipal.add(pnCbPEncomenda); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnTbPEncomenda); + pnPrincipal.add(pnCbValidade); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnTbValidade); + + this.add(spEstatisticas); + } + + private void estiloTabela(JTable tb) { + tb.setShowGrid(false); + tb.setSelectionBackground(new Color(136, 224, 200)); + tb.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tb.getTableHeader().setBackground(new Color(0, 183, 164)); + tb.setShowHorizontalLines(true); + tb.setAutoCreateRowSorter(true); + } + + public void addGraficoQty(ChartPanel cp) { + pnGraficoQty.removeAll(); + pnGraficoQty.add(cp); + } + + public void addGraficoArm(ChartPanel cp) { + pnGraficoArm.removeAll(); + pnGraficoArm.add(cp); + } + + @Override + public void mouseClicked(MouseEvent e) { + + } + + + public JTable getTbMaisVendidos() { + return tbMaisVendidos; + } + + public JTable getTbPEncomenda() { + return tbPEncomenda; + } + + public JTable getTbValidade() { + return tbValidade; + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} diff --git a/src/View/TelaFornecedor.java b/src/View/TelaFornecedor.java new file mode 100755 index 0000000..4d65726 --- /dev/null +++ b/src/View/TelaFornecedor.java @@ -0,0 +1,318 @@ +package View; + +import org.jdesktop.swingx.JXCollapsiblePane; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Objects; + +public class TelaFornecedor extends JPanel implements MouseListener { + private final JLabel lbTituloRegistro; + private final JLabel lbTituloConsulta; + private final JLabel lbImgLupa; + private final JLabel lbNome; + private final JLabel lbNuit; + private final JLabel lbEmail; + private final JLabel lbCelular; + private final JTextField txtNome; + private final JTextField txtCell; + private final JTextField txtEmail; + private final JTextField txtNuit; + private final JTextArea txtPesquisar; + private final JPanel pnPrincipal; + private final JPanel pnBt; + private final JPanel pnBtApagar; + private final JPanel pnPesquisa; + private final JPanel pnCentralCons; + private final JPanel pnCentralInser; + private final JPanel pnConsultaSup; + private final JPanel pnConsulta; + private final JPanel pnCbInsercao; + private final JPanel pnCbConsulta; + private final JButton btGravar; + private final JButton btApagar; + private final JButton btEditar; + private final JButton btColapse; + private final JScrollPane spProdutos; + private final JScrollPane spTabela; + private final JTable tbFornecedores; + private final JXCollapsiblePane pnInsercao; + private int codigo; + + public TelaFornecedor() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spProdutos = new JScrollPane(pnPrincipal); + spProdutos.setBorder(BorderFactory.createEmptyBorder()); + pnInsercao = new JXCollapsiblePane(JXCollapsiblePane.Direction.DOWN); + pnInsercao.setLayout(new BorderLayout(5, 5)); + pnInsercao.setCollapsed(true); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnConsulta = new JPanel(new BorderLayout(5, 5)); + pnCbConsulta = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbConsulta.setBackground(new Color(255, 147, 147)); + pnConsultaSup = new JPanel(new GridLayout(1, 2)); + pnBtApagar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnPesquisa = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbInsercao = new JPanel(new BorderLayout()); + pnCbInsercao.setBackground(new Color(255, 147, 147)); + pnCbInsercao.setMaximumSize(new Dimension(90000, pnCbInsercao.getHeight())); + pnCentralInser = new JPanel(new GridLayout(2, 4, 10, 10)); + pnCentralCons = new JPanel(new GridLayout(1, 1)); + + lbTituloRegistro = new JLabel("Registro de Fornecedores"); + lbTituloRegistro.setForeground(Color.WHITE); + lbTituloConsulta = new JLabel("Lista de Fornecedores"); + lbTituloConsulta.setForeground(Color.WHITE); + lbImgLupa = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/search.png")))); + lbNome = new JLabel("Nome do Fornecedor: "); + lbNuit = new JLabel("Nuit: "); + lbEmail = new JLabel("Email: "); + lbEmail.setHorizontalAlignment(SwingConstants.CENTER); + lbCelular = new JLabel("Celular: "); + lbCelular.setHorizontalAlignment(SwingConstants.CENTER); + + tbFornecedores = new JTable(new DefaultTableModel()); + tbFornecedores.setShowGrid(false); + tbFornecedores.setSelectionBackground(new Color(136, 224, 200)); + tbFornecedores.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tbFornecedores.getTableHeader().setBackground(new Color(0, 183, 164)); + tbFornecedores.setShowHorizontalLines(true); + tbFornecedores.setRowHeight(25); + tbFornecedores.setAutoCreateRowSorter(true); + spTabela = new JScrollPane(tbFornecedores); + spTabela.setBorder(BorderFactory.createEmptyBorder()); + + txtNome = new JTextField(); + txtNome.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtCell = new JTextField(); + txtCell.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtPesquisar = new JTextArea(2, 15); + txtPesquisar.setLineWrap(true); + txtPesquisar.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtEmail = new JTextField(); + txtEmail.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtNuit = new JTextField(); + txtNuit.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + btApagar = new JButton("Apagar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/delete.png")))); + btApagar.setBackground(new Color(255, 129, 101)); + btApagar.setForeground(Color.WHITE); + btEditar = new JButton("Editar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/edit.png")))); + btEditar.setBackground(new Color(79, 195, 247)); + btEditar.setForeground(Color.WHITE); + btEditar.setEnabled(false); + btGravar = new JButton("Gravar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/save.png")))); + btGravar.setForeground(Color.WHITE); + btGravar.setBackground(new Color(0, 229, 202)); + btColapse = new JButton(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + btColapse.setBorderPainted(false); + btColapse.setBackground(new Color(255, 147, 147)); + btColapse.setHorizontalAlignment(SwingConstants.RIGHT); + + pnCbInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnCbInsercao.add(lbTituloRegistro, BorderLayout.CENTER); + pnCbInsercao.add(btColapse, BorderLayout.EAST); + + pnCentralInser.add(lbNome); + pnCentralInser.add(txtNome); + pnCentralInser.add(lbCelular); + pnCentralInser.add(txtCell); + pnCentralInser.add(lbNuit); + pnCentralInser.add(txtNuit); + pnCentralInser.add(lbEmail); + pnCentralInser.add(txtEmail); + + pnBt.add(btEditar); + pnBt.add(btGravar); + + pnInsercao.add(new JLabel(" "), BorderLayout.NORTH); + pnInsercao.add(pnCentralInser, BorderLayout.CENTER); + pnInsercao.add(new JLabel(" "), BorderLayout.EAST); + pnInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnInsercao.add(pnBt, BorderLayout.SOUTH); + + + pnCbConsulta.add(lbTituloConsulta); + pnPesquisa.add(txtPesquisar); + pnPesquisa.add(lbImgLupa); + pnBtApagar.add(btApagar); + pnConsultaSup.add(pnPesquisa); + pnConsultaSup.add(pnBtApagar); + + pnCentralCons.add(spTabela); + pnConsulta.add(new JLabel(" "), BorderLayout.SOUTH); + pnConsulta.add(pnCentralCons, BorderLayout.CENTER); + pnConsulta.add(pnConsultaSup, BorderLayout.NORTH); + pnConsulta.add(new JLabel(" "), BorderLayout.EAST); + pnConsulta.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbInsercao); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnInsercao); + pnPrincipal.add(pnCbConsulta); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnConsulta); + + this.add(spProdutos); + + btColapse.addMouseListener(this); + btColapse.addActionListener(pnInsercao.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)); + tbFornecedores.addMouseListener(this); + + } + + public void fecharPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + limparTxt(); + btEditar.setEnabled(false); + btGravar.setEnabled(true); + } + + public void abrirPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowUp.png")))); + btGravar.setEnabled(true); + } + public void hobilitarBtGravar(){btGravar.setEnabled(true);} + + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getSource() == btColapse) { + if (pnInsercao.isCollapsed()) { + fecharPnInsercao(); + } else { + abrirPnInsercao(); + + } + } + + if (e.getClickCount() == 2 && e.getSource() == tbFornecedores) { + codigo = Integer.parseInt((String) tbFornecedores.getValueAt(tbFornecedores.getSelectedRow(), 0)); + abrirPnInsercao(); + txtNome.setText((String) tbFornecedores.getValueAt(tbFornecedores.getSelectedRow(), 1)); + txtNuit.setText((String) tbFornecedores.getValueAt(tbFornecedores.getSelectedRow(), 2)); + txtCell.setText((String) tbFornecedores.getValueAt(tbFornecedores.getSelectedRow(), 3)); + txtEmail.setText((String) tbFornecedores.getValueAt(tbFornecedores.getSelectedRow(), 4)); + btEditar.setEnabled(true); + btGravar.setEnabled(false); + pnInsercao.setCollapsed(false); + } + + pnPrincipal.updateUI(); + + } + + public int getCodigo() { + return codigo; + } + + public void addAccaoBtEditar(ActionListener accao) { + btEditar.addActionListener(accao); + } + + public void desabilitarBtEditar() { + btEditar.setEnabled(false); + } + + public void addAccaoBtGravar(ActionListener action) { + btGravar.addActionListener(action); + } + + public void addAccaoBtApagar(ActionListener action) { + btApagar.addActionListener(action); + } + + public void addAccaoTxtPesquisar(KeyListener action) { + txtPesquisar.addKeyListener(action); + } + + public JTable getTbFornecedores() { + return tbFornecedores; + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + public void limparTxt() { + txtNome.setText(null); + txtEmail.setText(null); + txtCell.setText(null); + txtNuit.setText(null); + } + + public String getNome() { + return txtNome.getText().trim(); + } + + public String getEmail() { + return txtEmail.getText().trim(); + } + + public String getCell() { + return txtCell.getText().trim(); + } + + public long getNuit() throws NumberFormatException { + return Long.parseLong(txtNuit.getText().trim()); + } + + + public String getPesquisa() { + return txtPesquisar.getText().trim(); + } + + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} + diff --git a/src/View/TelaFornecimento.java b/src/View/TelaFornecimento.java new file mode 100755 index 0000000..365f145 --- /dev/null +++ b/src/View/TelaFornecimento.java @@ -0,0 +1,380 @@ +package View; + +import org.jdesktop.swingx.JXCollapsiblePane; +import org.jdesktop.swingx.JXDatePicker; +import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Date; +import java.util.Objects; + +public class TelaFornecimento extends JPanel implements MouseListener { + private final JLabel lbTituloRegistro; + private final JLabel lbTituloConsulta; + private final JLabel lbImgLupa; + private final JLabel lbProduto; + private final JLabel lbFornecedor; + private final JLabel lbQty; + private final JLabel lbData; + private final JTextField txtQty; + private final JTextArea txtPesquisar; + private final JComboBox cbProduto; + private final JComboBox cbFornecedor; + private final JPanel pnPrincipal; + private final JPanel pnBt; + private final JPanel pnTb; + private final JPanel pnBtTb; + private final JPanel pnLateralInser; + private final JPanel pnPesquisa; + private final JPanel pnCentralCons; + private final JPanel pnCentralInser; + private final JPanel pnExportar; + private final JPanel pnConsultaSup; + private final JPanel pnConsulta; + private final JPanel pnTbForn; + private final JPanel pnCbInsercao; + private final JPanel pnCbConsulta; + private final JPanel pntxt; + private final JButton btConfirmar; + private final JButton btExportar; + private final JButton btAdicionar; + private final JButton btCancelar; + private final JButton btColapse; + private final JButton btRemover; + private final JScrollPane spFornecimento; + private final JScrollPane spTabela; + private final JScrollPane spProdForn; + private final JTable tbFornecimento; + private final JTable tbProdForn; + private final JXDatePicker datePicker; + private final JXCollapsiblePane pnInsercao; + + public TelaFornecimento() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spFornecimento = new JScrollPane(pnPrincipal); + spFornecimento.setBorder(BorderFactory.createEmptyBorder()); + pnInsercao = new JXCollapsiblePane(JXCollapsiblePane.Direction.DOWN); + pnInsercao.setLayout(new BorderLayout(10, 5)); + pnInsercao.setCollapsed(true); + pntxt = new JPanel(new GridLayout(5, 2, 5, 40)); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnBtTb = new JPanel(new FlowLayout(FlowLayout.CENTER)); + pnTb = new JPanel(new FlowLayout(FlowLayout.CENTER)); + pnTbForn = new JPanel(new BorderLayout()); + pnConsulta = new JPanel(new BorderLayout(5, 5)); + pnCbConsulta = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbConsulta.setBackground(new Color(255, 147, 147)); + pnConsultaSup = new JPanel(new GridLayout(1, 2)); + pnPesquisa = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbInsercao = new JPanel(new BorderLayout()); + pnCbInsercao.setBackground(new Color(255, 147, 147)); + pnCbInsercao.setMaximumSize(new Dimension(90000, pnCbInsercao.getHeight())); + pnCentralInser = new JPanel(); + pnCentralInser.setLayout(new BoxLayout(pnCentralInser, BoxLayout.Y_AXIS)); + pnLateralInser = new JPanel(); + pnLateralInser.setLayout(new BorderLayout()); + pnCentralCons = new JPanel(new GridLayout(1, 1)); + pnExportar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + + lbTituloRegistro = new JLabel("Registro de Fornecimentos"); + lbTituloRegistro.setForeground(Color.WHITE); + lbTituloConsulta = new JLabel("Hstórico de Fornecimentos"); + lbTituloConsulta.setForeground(Color.WHITE); + lbImgLupa = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/search.png")))); + lbProduto = new JLabel("Produto: "); + lbFornecedor = new JLabel("Fornecedor: "); + lbQty = new JLabel("Qty Fornecida: "); + lbData = new JLabel("Data do Fornecimento: "); + + tbFornecimento = new JTable(new DefaultTableModel()); + tbFornecimento.setRowHeight(25); + estiloTabela(tbFornecimento); + tbProdForn = new JTable(new DefaultTableModel(new String[]{"Produto", "Quantidade"}, 0)) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + estiloTabela(tbProdForn); + spTabela = new JScrollPane(tbFornecimento); + spTabela.setBorder(BorderFactory.createEmptyBorder()); + spProdForn = new JScrollPane(tbProdForn); + spProdForn.setBorder(BorderFactory.createEmptyBorder()); + spProdForn.setBackground(Color.WHITE); + spProdForn.getViewport().setBackground(Color.WHITE); + + + txtPesquisar = new JTextArea(2, 15); + txtPesquisar.setLineWrap(true); + txtPesquisar.setSize(new Dimension(15, 20)); + txtPesquisar.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtQty = new JTextField(); + txtQty.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + cbProduto = new JComboBox<>(new String[]{"Seleccione o produto"}); + cbProduto.setEditable(true); + AutoCompleteDecorator.decorate(cbProduto); + cbProduto.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + cbProduto.setBackground(Color.WHITE); + cbFornecedor = new JComboBox<>(new String[]{"Seleccione o Fornecedor"}); + cbFornecedor.setEditable(true); + AutoCompleteDecorator.decorate(cbFornecedor); + cbFornecedor.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + cbFornecedor.setBackground(Color.WHITE); + datePicker = new JXDatePicker(new Date()); + datePicker.setFormats("MMMM, dd, yyyy"); + datePicker.getEditor().setEditable(false); + datePicker.getEditor().setBackground(Color.WHITE); + datePicker.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + btConfirmar = new JButton("Confirmar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/confirm.png")))); + btConfirmar.setForeground(Color.WHITE); + btConfirmar.setBackground(new Color(127, 232, 129)); + btAdicionar = new JButton("Adicionar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/add.png")))); + btAdicionar.setForeground(Color.WHITE); + btAdicionar.setBackground(new Color(0, 229, 202)); + btRemover = new JButton("Remover",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/remove.png")))); + btRemover.setForeground(Color.WHITE); + btRemover.setBackground(new Color(224, 79, 95)); + btCancelar = new JButton("Cancelar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/cancel.png")))); + btCancelar.setForeground(Color.WHITE); + btCancelar.setBackground(new Color(255, 129, 101)); + btColapse = new JButton(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + btColapse.setBorderPainted(false); + btColapse.setBackground(new Color(255, 147, 147)); + btColapse.setHorizontalAlignment(SwingConstants.RIGHT); + btExportar = new JButton("Exportar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/export.png")))); + btExportar.setForeground(Color.WHITE); + btExportar.setBackground(new Color(96, 125, 139)); + + + pnCbInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnCbInsercao.add(lbTituloRegistro, BorderLayout.CENTER); + pnCbInsercao.add(btColapse, BorderLayout.EAST); + + pnBt.add(btAdicionar); + + pntxt.add(lbProduto); + pntxt.add(cbProduto); + pntxt.add(lbFornecedor); + pntxt.add(cbFornecedor); + pntxt.add(lbQty); + pntxt.add(txtQty); + pntxt.add(lbData); + pntxt.add(datePicker); + pntxt.add(new JLabel()); + pntxt.add(pnBt); + + pnTbForn.add(spProdForn, BorderLayout.CENTER); + pnTbForn.add(pnBtTb, BorderLayout.SOUTH); + + + pnCentralInser.add(new JPanel()); + pnCentralInser.add(pntxt); + pnCentralInser.add(new JPanel()); + pnCentralInser.add(new JPanel()); + pnCentralInser.add(new JPanel()); + + pnTb.add(pnTbForn); + pnBtTb.add(btCancelar); + pnBtTb.add(btRemover); + pnBtTb.add(btConfirmar); + + pnLateralInser.add(pnTb, BorderLayout.CENTER); + + pnInsercao.add(pnCentralInser, BorderLayout.CENTER); + pnInsercao.add(pnLateralInser, BorderLayout.EAST); + pnInsercao.add(new JLabel(" "), BorderLayout.WEST); + + pnExportar.add(btExportar); + + pnCbConsulta.add(lbTituloConsulta); + pnPesquisa.add(txtPesquisar); + pnPesquisa.add(lbImgLupa); + pnConsultaSup.add(pnPesquisa); + pnConsultaSup.add(pnExportar); + + pnCentralCons.add(spTabela); + pnConsulta.add(new JLabel(" "), BorderLayout.SOUTH); + pnConsulta.add(pnCentralCons, BorderLayout.CENTER); + pnConsulta.add(pnConsultaSup, BorderLayout.NORTH); + pnConsulta.add(new JLabel(" "), BorderLayout.EAST); + pnConsulta.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbInsercao); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnInsercao); + pnPrincipal.add(pnCbConsulta); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnConsulta); + + this.add(spFornecimento); + + btColapse.addMouseListener(this); + btColapse.addActionListener(pnInsercao.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)); + + } + + private void estiloTabela(JTable tb) { + tb.setShowGrid(false); + tb.setSelectionBackground(new Color(136, 224, 200)); + tb.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tb.getTableHeader().setBackground(new Color(0, 183, 164)); + tb.setShowHorizontalLines(true); + tb.setAutoCreateRowSorter(true); + } + + public void fecharPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + } + + public void abrirPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowUp.png")))); + } + + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getSource() == btColapse) { + if (pnInsercao.isCollapsed()) { + fecharPnInsercao(); + } else { + abrirPnInsercao(); + + } + } + } + + public void addAccaoBtConfirmar(ActionListener action) { + btConfirmar.addActionListener(action); + } + + public void addAccaoBtRemover(ActionListener action) { + btRemover.addActionListener(action); + } + + public void addAccaoBtAdicionar(ActionListener action) { + btAdicionar.addActionListener(action); + } + + public void addAccaoBtCancelar(ActionListener action) { + btCancelar.addActionListener(action); + } + + public void addAccaoBtExportar(ActionListener action) { + btExportar.addActionListener(action); + } + + + public void addAccaoTxtPesquisar(KeyListener action) { + txtPesquisar.addKeyListener(action); + } + + public JTable getTbFornecimento() { + return tbFornecimento; + } + + public int getQty() throws NumberFormatException { + return Integer.parseInt(txtQty.getText().trim()); + } + + public Object getProduto() { + return cbProduto.getSelectedItem(); + } + + public Date getData() { + return datePicker.getDate(); + + } + + public Object getFornecedor() { + return cbFornecedor.getSelectedItem(); + } + + public DefaultTableModel getProForn() { + return (DefaultTableModel) tbProdForn.getModel(); + } + + public JTable getTbProdForn() { + return tbProdForn; + } + + public String getPesquisa() { + return txtPesquisar.getText().trim(); + } + + public void limparTxt() { + txtQty.setText(null); + } + + public void limparTb() { + tbProdForn.setModel(new DefaultTableModel(new String[]{"Produto", "Quantidade"}, 0)); + } + + public void addProduto(String produto) { + cbProduto.addItem(produto); + } + + public void addFornecedor(String fornecedor) { + cbFornecedor.addItem(fornecedor); + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} + diff --git a/src/View/TelaLogin.java b/src/View/TelaLogin.java new file mode 100755 index 0000000..b1ce259 --- /dev/null +++ b/src/View/TelaLogin.java @@ -0,0 +1,164 @@ +package View; + +import Controller.ControllerLogin; +import Model.User; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.FontFormatException; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.util.Objects; +import java.util.Vector; + +public class TelaLogin extends JFrame { + private final JLabel lbNome; + private final JLabel lbSenha; + private final JLabel lbImagem; + private final JLabel lbTitulo; + private final JLabel lbImg; + private final JTextField txtNome; + private final JPasswordField txtSenha; + private final JButton btEntrar; + private final JButton btCancelar; + private final JPanel pnCentral; + private final JPanel pnInsercao; + private final JPanel pnBt; + private final JPanel pnImagem; + private final JPanel pnCabecalho; + private final JPanel pnNome; + private final JPanel pnSenha; + + public TelaLogin() { + super("Login"); + this.setSize(400, 300); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setResizable(false); + this.setIconImage(new ImageIcon(Objects.requireNonNull(TelaLogin.class.getResource("/View/Icons/shop.png"))).getImage()); + this.setLocationRelativeTo(null); + this.setLayout(new BorderLayout(2, 10)); + + criarFonte(); + + pnInsercao = new JPanel(new GridLayout(3, 2, 0, 7)); + pnInsercao.setBackground(Color.WHITE); + pnCentral = new JPanel(new BorderLayout(5, 10)); + pnCentral.setBackground(Color.WHITE); + pnImagem = new JPanel(new GridLayout(1, 1)); + + pnImagem.setBackground(Color.WHITE); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5)); + pnBt.setBackground(Color.WHITE); + pnCabecalho = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCabecalho.setBackground(new Color(136, 224, 200)); + pnNome = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 0)); + pnNome.setBackground(Color.WHITE); + pnSenha = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 0)); + pnSenha.setBackground(Color.WHITE); + + lbImagem = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/login.png")))); + lbNome = new JLabel("Nome:"); + lbNome.setHorizontalAlignment(SwingConstants.CENTER); + lbSenha = new JLabel("Senha:"); + lbSenha.setHorizontalAlignment(SwingConstants.CENTER); + lbImg = new JLabel(new ImageIcon(System.getProperty("user.dir") + "/src/View/Icons/shop.png")); + lbTitulo = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/imgLogo2.png")))); + + txtNome = new JTextField(17); + txtNome.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtSenha = new JPasswordField(17); + txtSenha.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + btEntrar = new JButton("Entrar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/logIn.png")))); + btEntrar.setHorizontalTextPosition(SwingConstants.LEFT); + btEntrar.setForeground(Color.WHITE); + btEntrar.setBackground(new Color(74, 211, 149)); + btCancelar = new JButton("Cancelar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/cancel.png")))); + btCancelar.setHorizontalTextPosition(SwingConstants.LEFT); + btCancelar.setForeground(Color.WHITE); + btCancelar.setBackground(new Color(224, 79, 95)); + + pnBt.add(btCancelar); + pnBt.add(btEntrar); + + pnNome.add(lbNome); + pnNome.add(txtNome); + pnSenha.add(lbSenha); + pnSenha.add(txtSenha); + pnInsercao.add(pnNome); + pnInsercao.add(pnSenha); + + pnCabecalho.add(lbImg); + pnCabecalho.add(lbTitulo); + + pnImagem.add(lbImagem); + pnCentral.add(pnImagem, BorderLayout.NORTH); + pnCentral.add(new JLabel(), BorderLayout.EAST); + pnCentral.add(pnInsercao, BorderLayout.CENTER); + pnCentral.add(pnBt, BorderLayout.SOUTH); + pnCentral.add(new JLabel(), BorderLayout.WEST); + + this.add(pnCabecalho, BorderLayout.NORTH); + this.add(pnCentral, BorderLayout.CENTER); + + this.setVisible(true); + + } + + public void criarFonte() { + + try { + Font font = Font.createFont(Font.TRUETYPE_FONT, Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("View/Fonts/RobotoCondensed-Light.ttf"))).deriveFont(Font.BOLD, 13); + UIManager.put("Label.font", new Font(font.getFontName(), Font.PLAIN, 18)); + UIManager.put("TextField.font", new Font(font.getFontName(), Font.PLAIN, 15)); + UIManager.put("PasswordField.font", new Font(font.getFontName(), Font.PLAIN, 15)); + } catch (FontFormatException | IOException e) { + e.printStackTrace(); + } + } + + public String getSenha() { + return txtSenha.getText().trim(); + } + + public String getNome() { + return txtNome.getText().trim(); + } + + public void addAccaoBtEntrar(ActionListener action){ + btEntrar.addActionListener(action); + } + + public void addAccaoBtCancelar(ActionListener action){ + btCancelar.addActionListener(action); + } + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + public static void main(String[] args) { + TelaLogin tl = new TelaLogin(); + User user = new User(); + Vector users = user.getDao().ler(); + ControllerLogin uc = new ControllerLogin(tl, users); + + } +} diff --git a/src/View/TelaPrincipal.java b/src/View/TelaPrincipal.java new file mode 100755 index 0000000..4e34b65 --- /dev/null +++ b/src/View/TelaPrincipal.java @@ -0,0 +1,344 @@ +package View; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JMenuBar; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.SwingConstants; +import javax.swing.Timer; +import javax.swing.UIManager; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.FontFormatException; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Objects; + +public class TelaPrincipal extends JFrame implements MouseListener { + private final JLabel lbTitulo; + private final JLabel lbBack; + private final JLabel lbUser; + private final JLabel lbHora; + private final JLabel lbImgTitulo; + private final JLabel lbImgUser; + private final JPanel pnRodape; + private final JPanel pnCentral; + private final JPanel pnLateral; + private final JPanel pnLateralCentral; + private final JPanel pnCentral3; + private final JPanel pnCentral2; + private final JPanel pnTitulo; + private final JPanel pnUsuario; + private final JButton btNovaVenda; + private final JButton btUsers; + private final JButton btFornecedores; + private final JButton btEstatistica; + private final JButton btProdutos; + private final JButton btVendas; + private final JButton btFornecimento; + private final JButton btArmazens; + private final JButton btClientes; + private final JProgressBar pg; + private final JMenuBar pnCabecalho; + + public TelaPrincipal(String nomeUsuario,String nvAcesso) { + this.setTitle("Venda Fácil"); + this.setMinimumSize(new Dimension(1000, 500)); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setIconImage(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/shop.png"))).getImage()); + this.setLocationRelativeTo(null); + this.setLayout(new BorderLayout()); + + criarFonte(); + pnCabecalho = new JMenuBar(); + pnCabecalho.setLayout(new GridLayout(1, 2)); + pnCabecalho.setBackground(new Color(136, 224, 200)); + pnCabecalho.setBorderPainted(false); + this.setJMenuBar(pnCabecalho); + pnRodape = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnRodape.setBackground(new Color(136, 224, 200)); + pnUsuario = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnUsuario.setBackground(new Color(136, 224, 200)); + pnTitulo = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnTitulo.setBackground(new Color(136, 224, 200)); + pnCentral = new JPanel(new BorderLayout()); + pnCentral.setBackground(Color.WHITE); + pnLateral = new JPanel(new BorderLayout(5, 5)); + pnLateral.setBackground(Color.WHITE); + pnLateralCentral = new JPanel(); + pnLateralCentral.setLayout(new GridLayout(8,1,0,10)); + pnLateralCentral.setBackground(Color.WHITE); + pnCentral2 = new JPanel(new BorderLayout()); + pnCentral2.setBackground(Color.WHITE); + pnCentral3 = new JPanel(new GridLayout(1, 1)); + pnCentral3.setBackground(Color.WHITE); + pg = new JProgressBar(SwingConstants.HORIZONTAL); + pg.setBorderPainted(false); + pg.setBackground(Color.WHITE); + pg.setForeground(new Color(255, 147, 147)); + pg.setVisible(false); + pg.setMaximum(100); + + lbImgTitulo = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/shop.png")))); + lbTitulo = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/imgLogo.png")))); + lbBack = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/background.png")))); + lbImgUser = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/user.png")))); + lbUser = new JLabel(nomeUsuario); + lbHora = new JLabel(); + lbHora.setFont(new Font(lbHora.getName(), Font.BOLD, 13)); + + btNovaVenda = new JButton(); + aplicarEstiloBotao(btNovaVenda, "Nova Venda", "add-to-cart.png"); + btProdutos = new JButton(); + aplicarEstiloBotao(btProdutos, "Produtos", "product.png"); + btClientes = new JButton(); + aplicarEstiloBotao(btClientes, "Clientes", "people.png"); + btArmazens = new JButton(); + aplicarEstiloBotao(btArmazens, "Armazens", "warehouse.png"); + btFornecimento = new JButton(); + aplicarEstiloBotao(btFornecimento, "Fornecimentos", "supplier.png"); + btVendas = new JButton(); + aplicarEstiloBotao(btVendas, "Rel.Vendas", "sale-report.png"); + btFornecedores = new JButton(); + aplicarEstiloBotao(btFornecedores, "Fornecedores", "delivery.png"); + btEstatistica = new JButton(); + aplicarEstiloBotao(btEstatistica, "Estatísticas", "statistic.png"); + btUsers = new JButton(); + aplicarEstiloBotao(btUsers, "Usuários", "users.png"); + + Timer timer = new Timer(1000, new ClockListener()); + timer.start(); + + pnLateralCentral.add(btNovaVenda); + pnLateralCentral.add(btProdutos); + pnLateralCentral.add(btFornecimento); + pnLateralCentral.add(btFornecedores); + pnLateralCentral.add(btVendas); + pnLateralCentral.add(btEstatistica); + pnLateralCentral.add(btArmazens); + pnLateralCentral.add(btClientes); + if(nvAcesso.equals("Administrador")){ + pnLateralCentral.setLayout(new GridLayout(9,1,0,10)); + pnLateralCentral.add(btUsers); + } + + // pnLateral.add(new JLabel(), BorderLayout.NORTH); + pnLateral.add(pnLateralCentral, BorderLayout.CENTER); + pnLateral.add(new JLabel(), BorderLayout.SOUTH); + pnLateral.add(new JLabel(), BorderLayout.EAST); + pnLateral.add(new JLabel(), BorderLayout.WEST); + + pnTitulo.add(lbImgTitulo); + pnTitulo.add(lbTitulo); + + pnUsuario.add(lbImgUser); + pnUsuario.add(lbUser); + + pnCabecalho.add(pnTitulo); + pnCabecalho.add(pnUsuario); + pnRodape.add(pg); + pnRodape.add(lbHora); + + pnCentral3.add(lbBack); + pnCentral2.add(pnCentral3, BorderLayout.CENTER); + pnCentral2.add(pnRodape, BorderLayout.SOUTH); + + pnCentral.add(pnLateral, BorderLayout.WEST); + pnCentral.add(pnCentral2, BorderLayout.CENTER); + + + this.add(pnCentral, BorderLayout.CENTER); + + btFornecimento.addMouseListener(this); + btProdutos.addMouseListener(this); + btArmazens.addMouseListener(this); + btClientes.addMouseListener(this); + btNovaVenda.addMouseListener(this); + btFornecedores.addMouseListener(this); + btEstatistica.addMouseListener(this); + btVendas.addMouseListener(this); + btUsers.addMouseListener(this); + lbImgTitulo.addMouseListener(this); + + } + + public void aplicarEstiloBotao(JButton bt, String legenda, String imagem) { + bt.setText(legenda); + bt.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/" + imagem)))); + bt.setBackground(Color.WHITE); + bt.setBorderPainted(false); + bt.setHorizontalAlignment(SwingConstants.LEFT); + } + + public void criarFonte() { + + try { + + Font font = Font.createFont(Font.TRUETYPE_FONT, Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("View/Fonts/RobotoCondensed-Light.ttf"))).deriveFont(Font.BOLD, 13); + UIManager.put("Label.font", new Font(font.getFontName(), Font.PLAIN, 18)); + UIManager.put("Table.font", new Font(font.getFontName(), Font.PLAIN, 15)); + UIManager.put("ComboBox.font", new Font(font.getFontName(), Font.PLAIN, 15)); + UIManager.put("TextField.font", new Font(font.getFontName(), Font.PLAIN, 15)); + UIManager.put("TextArea.font", new Font(font.getFontName(), Font.PLAIN, 15)); + } catch (FontFormatException | IOException e) { + e.printStackTrace(); + } + } + + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getSource() == lbImgTitulo) { + pnCentral3.removeAll(); + pnCentral3.add(lbBack); + pnCentral3.updateUI(); + } + } + + @Override + public void mousePressed(MouseEvent e) { + if (e.getSource() instanceof JButton) { + ((JButton) e.getSource()).setBackground(new Color(136, 224, 200)); + mudarCor(((JButton) e.getSource())); + } + + } + + public void mudarCor(JButton bt) { + if (bt != btEstatistica) + btEstatistica.setBackground(Color.WHITE); + if (bt != btFornecimento) + btFornecimento.setBackground(Color.WHITE); + if (bt != btNovaVenda) + btNovaVenda.setBackground(Color.WHITE); + if (bt != btProdutos) + btProdutos.setBackground(Color.WHITE); + if (bt != btFornecedores) + btFornecedores.setBackground(Color.WHITE); + if (bt != btVendas) + btVendas.setBackground(Color.WHITE); + if (bt != btArmazens) + btArmazens.setBackground(Color.WHITE); + if (bt != btClientes) + btClientes.setBackground(Color.WHITE); + if (bt != btUsers) + btUsers.setBackground(Color.WHITE); + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + if (e.getSource() instanceof JButton) { + ((JButton) e.getSource()).setBackground(new Color(0, 183, 164)); + } + } + + @Override + public void mouseExited(MouseEvent e) { + if (e.getSource() instanceof JButton) { + Color c = new Color(0, 183, 164); + if (((JButton) e.getSource()).getBackground().equals(c)) { + ((JButton) e.getSource()).setBackground(Color.WHITE); + } + } + } + + public void addActionBtProdutos(ActionListener action) { + btProdutos.addActionListener(action); + } + + public void addActionBtArmazens(ActionListener action) { + btArmazens.addActionListener(action); + } + + public void addActionBtVendas(ActionListener action) { + btVendas.addActionListener(action); + } + + public void addActionBtNovaVenda(ActionListener action) { + btNovaVenda.addActionListener(action); + } + + public void addActionBtFornecedor(ActionListener action) { + btFornecedores.addActionListener(action); + } + + public void addActionBtEstatisticas(ActionListener action) { + btEstatistica.addActionListener(action); + } + + public void addActionBtClientes(ActionListener action) { + btClientes.addActionListener(action); + } + + public void addActionBtFornecimento(ActionListener action) { + btFornecimento.addActionListener(action); + } + + public void addActionBtUsers(ActionListener action) { + btUsers.addActionListener(action); + } + + public JProgressBar getPg() { + return pg; + } + + + public void addTela(JPanel pn) { + pnCentral3.removeAll(); + pnCentral3.add(pn); + pnCentral3.updateUI(); + } + + private class ClockListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + Date date = Calendar.getInstance().getTime(); + Calendar c = Calendar.getInstance(); + DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy | hh:mm:ss"); + String strDate = dateFormat.format(date); + lbHora.setText("Data: " + diaSemana(c.get(Calendar.DAY_OF_WEEK)) + " | " + strDate); + } + } + + public String diaSemana(int n) { + + switch (n) { + case 1: + return "Domingo"; + case 2: + return "Segunda-Feira"; + case 3: + return "Terça-Feira"; + case 4: + return "Quarta-Feira"; + case 5: + return "Quinta-Feira"; + case 6: + return "Sexta-Feira"; + case 7: + return "Sábado"; + default: + return null; + } + + } +} diff --git a/src/View/TelaProdutos.java b/src/View/TelaProdutos.java new file mode 100755 index 0000000..f482dcf --- /dev/null +++ b/src/View/TelaProdutos.java @@ -0,0 +1,349 @@ +package View; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Date; +import java.util.Objects; + +import org.jdesktop.swingx.JXCollapsiblePane; +import org.jdesktop.swingx.JXDatePicker; +import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; + +public class TelaProdutos extends JPanel implements MouseListener { + private final JLabel lbTituloRegistro; + private final JLabel lbTituloConsulta; + private final JLabel lbImgLupa; + private final JLabel lbValidade; + private final JLabel lbNome; + private final JLabel lbArmazem; + private final JLabel lbStockMinimo; + private final JLabel lbPrecoUnit; + private final JTextField txtNome; + private final JTextField txtPreco; + private final JTextField txtStockminimo; + private final JTextArea txtPesquisar; + private final JComboBox cbArmazem; + private final JPanel pnPrincipal; + private final JPanel pnBt; + private final JPanel pnBtApagar; + private final JPanel pnPesquisa; + private final JPanel pnCentralCons; + private final JPanel pnCentralInser; + private final JPanel pnConsultaSup; + private final JPanel pnConsulta; + private final JPanel pnCbInsercao; + private final JPanel pnCbConsulta; + private final JButton btGravar; + private final JButton btApagar; + private final JButton btEditar; + private final JButton btColapse; + private final JScrollPane spProdutos; + private final JScrollPane spTabela; + private final JTable tbProdutos; + private final JXCollapsiblePane pnInsercao; + private final JXDatePicker datePicker; + private int codigo; + + public TelaProdutos() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spProdutos = new JScrollPane(pnPrincipal); + spProdutos.setBorder(BorderFactory.createEmptyBorder()); + pnInsercao = new JXCollapsiblePane(JXCollapsiblePane.Direction.DOWN); + pnInsercao.setLayout(new BorderLayout(5, 5)); + pnInsercao.setCollapsed(true); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnConsulta = new JPanel(new BorderLayout(5, 5)); + pnCbConsulta = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbConsulta.setBackground(new Color(255, 147, 147)); + pnConsultaSup = new JPanel(new GridLayout(1, 2)); + pnBtApagar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnPesquisa = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbInsercao = new JPanel(new BorderLayout()); + pnCbInsercao.setBackground(new Color(255, 147, 147)); + pnCbInsercao.setMaximumSize(new Dimension(90000, pnCbInsercao.getHeight())); + pnCentralInser = new JPanel(new GridLayout(2, 5, 10, 10)); + pnCentralCons = new JPanel(new GridLayout(1, 1)); + + lbTituloRegistro = new JLabel("Registro de Produtos"); + lbTituloRegistro.setForeground(Color.WHITE); + lbTituloConsulta = new JLabel("Inventário"); + lbTituloConsulta.setForeground(Color.WHITE); + lbImgLupa = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/search.png")))); + lbNome = new JLabel("Nome do produto: "); + lbArmazem = new JLabel("Armazém: "); + lbArmazem.setHorizontalAlignment(SwingConstants.CENTER); + lbStockMinimo = new JLabel("Stock Mínimo: "); + lbStockMinimo.setHorizontalAlignment(SwingConstants.CENTER); + lbPrecoUnit = new JLabel("Preço Unitário: "); + lbPrecoUnit.setHorizontalAlignment(SwingConstants.CENTER); + lbValidade = new JLabel("Prazo de Validade: "); + + tbProdutos = new JTable(new DefaultTableModel()); + tbProdutos.setShowGrid(false); + tbProdutos.setShowHorizontalLines(true); + tbProdutos.setRowHeight(25); + tbProdutos.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tbProdutos.getTableHeader().setBackground(new Color(0, 183, 164)); + tbProdutos.setSelectionBackground(new Color(208, 247, 237)); + tbProdutos.setAutoCreateRowSorter(true); + spTabela = new JScrollPane(tbProdutos); + spTabela.setBorder(BorderFactory.createEmptyBorder()); + + txtNome = new JTextField(); + txtNome.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtPreco = new JTextField(); + txtPreco.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtPesquisar = new JTextArea(2, 15); + txtPesquisar.setLineWrap(true); + txtPesquisar.setSize(new Dimension(15, 20)); + txtPesquisar.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtStockminimo = new JTextField(); + txtStockminimo.setText("5"); + txtStockminimo.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + datePicker = new JXDatePicker(new Date()); + datePicker.setFormats("MMMM, dd, yyyy"); + datePicker.getEditor().setEditable(false); + datePicker.getEditor().setBackground(Color.WHITE); + datePicker.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + cbArmazem = new JComboBox<>(new String[]{"Escolha o Armazém"}); + cbArmazem.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + cbArmazem.setBackground(Color.WHITE); + cbArmazem.setEditable(true); + AutoCompleteDecorator.decorate(cbArmazem); + + btApagar = new JButton("Apagar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/delete.png")))); + btApagar.setBackground(new Color(255, 129, 101)); + btApagar.setForeground(Color.WHITE); + btEditar = new JButton("Editar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/edit.png")))); + btEditar.setBackground(new Color(79, 195, 247)); + btEditar.setForeground(Color.WHITE); + btEditar.setEnabled(false); + btGravar = new JButton("Gravar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/save.png")))); + btGravar.setForeground(Color.WHITE); + btGravar.setBackground(new Color(0, 229, 202)); + btColapse = new JButton(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + btColapse.setBorderPainted(false); + btColapse.setBackground(new Color(255, 147, 147)); + btColapse.setHorizontalAlignment(SwingConstants.RIGHT); + + pnCbInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnCbInsercao.add(lbTituloRegistro, BorderLayout.CENTER); + pnCbInsercao.add(btColapse, BorderLayout.EAST); + + pnCentralInser.add(lbNome); + pnCentralInser.add(txtNome); + pnCentralInser.add(lbPrecoUnit); + pnCentralInser.add(txtPreco); + pnCentralInser.add(lbArmazem); + pnCentralInser.add(cbArmazem); + pnCentralInser.add(lbStockMinimo); + pnCentralInser.add(txtStockminimo); + pnCentralInser.add(lbValidade); + pnCentralInser.add(datePicker); + pnCentralInser.add(new JLabel()); + pnCentralInser.add(new JLabel()); + + + pnBt.add(btEditar); + pnBt.add(btGravar); + + pnInsercao.add(new JLabel(" "), BorderLayout.NORTH); + pnInsercao.add(pnCentralInser, BorderLayout.CENTER); + pnInsercao.add(new JLabel(" "), BorderLayout.EAST); + pnInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnInsercao.add(pnBt, BorderLayout.SOUTH); + + + pnCbConsulta.add(lbTituloConsulta); + pnPesquisa.add(txtPesquisar); + pnPesquisa.add(lbImgLupa); + pnBtApagar.add(btApagar); + pnConsultaSup.add(pnPesquisa); + pnConsultaSup.add(pnBtApagar); + + pnCentralCons.add(spTabela); + pnConsulta.add(new JLabel(" "), BorderLayout.SOUTH); + pnConsulta.add(pnCentralCons, BorderLayout.CENTER); + pnConsulta.add(pnConsultaSup, BorderLayout.NORTH); + pnConsulta.add(new JLabel(" "), BorderLayout.EAST); + pnConsulta.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbInsercao); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnInsercao); + pnPrincipal.add(pnCbConsulta); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnConsulta); + + this.add(spProdutos); + btColapse.addMouseListener(this); + btColapse.addActionListener(pnInsercao.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)); + tbProdutos.addMouseListener(this); + + } + + public void fecharPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + limparTxt(); + btEditar.setEnabled(false); + btGravar.setEnabled(true); + } + + public void abrirPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowUp.png")))); + btGravar.setEnabled(true); + } + + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getSource() == btColapse) { + if (pnInsercao.isCollapsed()) { + fecharPnInsercao(); + } else { + abrirPnInsercao(); + + } + } + + if (e.getClickCount() == 2 && e.getSource() == tbProdutos) { + codigo = Integer.parseInt((String) tbProdutos.getValueAt(tbProdutos.getSelectedRow(), 0)); + abrirPnInsercao(); + txtNome.setText((String) tbProdutos.getValueAt(tbProdutos.getSelectedRow(), 1)); + txtPreco.setText((String) tbProdutos.getValueAt(tbProdutos.getSelectedRow(), 2)); + cbArmazem.setSelectedItem(tbProdutos.getValueAt(tbProdutos.getSelectedRow(), 3)); + txtStockminimo.setText((String) tbProdutos.getValueAt(tbProdutos.getSelectedRow(), 5)); + datePicker.getEditor().setText((String) tbProdutos.getValueAt(tbProdutos.getSelectedRow(), 6)); + btGravar.setEnabled(false); + btEditar.setEnabled(true); + pnInsercao.setCollapsed(false); + } + + pnPrincipal.updateUI(); + + } + + public int getCodigo() { + return codigo; + } + + public void addAccaoBtEditar(ActionListener accao) { + btEditar.addActionListener(accao); + } + + public void desabilitarBtEditar() { + btEditar.setEnabled(false); + } + + public void addAccaoBtGravar(ActionListener action) { + btGravar.addActionListener(action); + } + + public void addAccaoBtApagar(ActionListener action) { + btApagar.addActionListener(action); + } + + public void addAccaoTxtPesquisar(KeyListener action) { + txtPesquisar.addKeyListener(action); + } + + public JTable getTbProdutos() { + return tbProdutos; + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + + public void limparTxt() { + txtNome.setText(null); + txtStockminimo.setText("5"); + txtPreco.setText(null); + cbArmazem.setSelectedIndex(0); + } + + public String getNome() { + return txtNome.getText().trim(); + } + + public int getStockMinimo() throws NumberFormatException { + return Integer.parseInt(txtStockminimo.getText().trim()); + } + + public double getPreco() throws NumberFormatException { + return Double.parseDouble(txtPreco.getText().trim()); + } + + public Object getArmazem() { + return cbArmazem.getSelectedItem(); + } + + public String getPesquisa() { + return txtPesquisar.getText().trim(); + } + + public void addArmazem(String armazem) { + cbArmazem.addItem(armazem); + } + + public Date getData() { + return datePicker.getDate(); + + } + public void hobilitarBtGravar(){btGravar.setEnabled(true);} + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} diff --git a/src/View/TelaRelatorioVendas.java b/src/View/TelaRelatorioVendas.java new file mode 100755 index 0000000..af94040 --- /dev/null +++ b/src/View/TelaRelatorioVendas.java @@ -0,0 +1,161 @@ +package View; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Objects; + +public class TelaRelatorioVendas extends JPanel implements MouseListener { + private final JLabel lbTituloConsulta; + private final JLabel lbImgLupa; + private final JTextArea txtPesquisar; + private final JPanel pnPrincipal; + private final JPanel pnExportar; + private final JPanel pnPesquisa; + private final JPanel pnCentralCons; + private final JPanel pnConsultaSup; + private final JPanel pnConsulta; + private final JPanel pnCbConsulta; + private final JScrollPane spRelVendas; + private final JScrollPane spTabela; + private final JTable tbRelVendas; + private final JButton btExportar; + + public TelaRelatorioVendas() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spRelVendas = new JScrollPane(pnPrincipal); + spRelVendas.setBorder(BorderFactory.createEmptyBorder()); + pnConsulta = new JPanel(new BorderLayout(5, 5)); + pnCbConsulta = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbConsulta.setBackground(new Color(255, 147, 147)); + pnConsultaSup = new JPanel(new GridLayout(1, 2)); + pnPesquisa = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCentralCons = new JPanel(new GridLayout(1, 1)); + pnExportar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + + lbTituloConsulta = new JLabel("Relatório de Vendas"); + lbTituloConsulta.setForeground(Color.WHITE); + lbImgLupa =new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/search.png")))); + + tbRelVendas = new JTable(new DefaultTableModel()); + tbRelVendas.setRowHeight(25); + estiloTabela(tbRelVendas); + + btExportar = new JButton("Exportar",new ImageIcon(Objects.requireNonNull(this.getClass().getResource("/View/Icons/export.png")))); + btExportar.setForeground(Color.WHITE); + btExportar.setBackground(new Color(96, 125, 139)); + + spTabela = new JScrollPane(tbRelVendas); + spTabela.setBorder(BorderFactory.createEmptyBorder()); + + txtPesquisar = new JTextArea(2, 15); + txtPesquisar.setLineWrap(true); + txtPesquisar.setSize(new Dimension(15, 20)); + txtPesquisar.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + pnExportar.add(btExportar); + + pnCbConsulta.add(lbTituloConsulta); + pnPesquisa.add(txtPesquisar); + pnPesquisa.add(lbImgLupa); + pnConsultaSup.add(pnPesquisa); + pnConsultaSup.add(pnExportar); + + pnCentralCons.add(spTabela); + pnConsulta.add(new JLabel(" "), BorderLayout.SOUTH); + pnConsulta.add(pnCentralCons, BorderLayout.CENTER); + pnConsulta.add(pnConsultaSup, BorderLayout.NORTH); + pnConsulta.add(new JLabel(" "), BorderLayout.EAST); + pnConsulta.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbConsulta); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnConsulta); + + this.add(spRelVendas); + } + + private void estiloTabela(JTable tb) { + tb.setShowGrid(false); + tb.setSelectionBackground(new Color(136, 224, 200)); + tb.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tb.getTableHeader().setBackground(new Color(0, 183, 164)); + tb.setShowHorizontalLines(true); + tb.setAutoCreateRowSorter(true); + } + + @Override + public void mouseClicked(MouseEvent e) { + + } + + public void addAccaoTxtPesquisar(KeyListener action) { + txtPesquisar.addKeyListener(action); + } + + public void addAccaoBtExportar(ActionListener action){ + btExportar.addActionListener(action); + } + + public JTable getTbRelVendas() { + return tbRelVendas; + } + + public String getPesquisa() { + return txtPesquisar.getText(); + } + + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} diff --git a/src/View/TelaUsuario.java b/src/View/TelaUsuario.java new file mode 100755 index 0000000..83dba1d --- /dev/null +++ b/src/View/TelaUsuario.java @@ -0,0 +1,309 @@ +package View; + +import org.jdesktop.swingx.JXCollapsiblePane; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Objects; + +public class TelaUsuario extends JPanel implements MouseListener { + private final JLabel lbTituloRegistro; + private final JLabel lbTituloConsulta; + private final JLabel lbImgLupa; + private final JLabel lbNome; + private final JLabel lbSenha; + private final JLabel lbNvAcesso; + private final JTextField txtNomeUser; + private final JTextField txtSenha; + private final JTextArea txtPesquisar; + private final JComboBox cbNvAcesso; + private final JPanel pnPrincipal; + private final JPanel pnBt; + private final JPanel pnBtApagar; + private final JPanel pnPesquisa; + private final JPanel pnCentralCons; + private final JPanel pnCentralInser; + private final JPanel pnConsultaSup; + private final JPanel pnConsulta; + private final JPanel pnCbInsercao; + private final JPanel pnCbConsulta; + private final JButton btGravar; + private final JButton btApagar; + private final JButton btEditar; + private final JButton btColapse; + private final JScrollPane spUsers; + private final JScrollPane spTabela; + private final JTable tbUsuarios; + private final JXCollapsiblePane pnInsercao; + private int codigo; + + public TelaUsuario() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spUsers = new JScrollPane(pnPrincipal); + spUsers.setBorder(BorderFactory.createEmptyBorder()); + pnInsercao = new JXCollapsiblePane(JXCollapsiblePane.Direction.DOWN); + pnInsercao.setCollapsed(true); + pnInsercao.setLayout(new BorderLayout(5, 5)); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnConsulta = new JPanel(new BorderLayout(5, 5)); + pnCbConsulta = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbConsulta.setBackground(new Color(255, 147, 147)); + pnConsultaSup = new JPanel(new GridLayout(1, 2)); + pnBtApagar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnPesquisa = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnCbInsercao = new JPanel(new BorderLayout()); + pnCbInsercao.setBackground(new Color(255, 147, 147)); + pnCbInsercao.setMaximumSize(new Dimension(90000, pnCbInsercao.getHeight())); + pnCentralInser = new JPanel(new GridLayout(2, 4, 10, 10)); + pnCentralCons = new JPanel(new GridLayout(1, 1)); + + lbTituloRegistro = new JLabel("Registro de Usuários"); + lbTituloRegistro.setForeground(Color.WHITE); + lbTituloConsulta = new JLabel("Lista de Usuários"); + lbTituloConsulta.setForeground(Color.WHITE); + lbImgLupa = new JLabel(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/search.png")))); + lbNome = new JLabel("Nome do Usuário: "); + lbSenha = new JLabel("Senha: "); + lbSenha.setHorizontalAlignment(SwingConstants.CENTER); + lbNvAcesso = new JLabel("Nível de acesso: "); + + + tbUsuarios = new JTable(new DefaultTableModel()); + tbUsuarios.setShowGrid(false); + tbUsuarios.setSelectionBackground(new Color(136, 224, 200)); + tbUsuarios.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tbUsuarios.getTableHeader().setBackground(new Color(0, 183, 164)); + tbUsuarios.setShowHorizontalLines(true); + tbUsuarios.setRowHeight(25); + tbUsuarios.setAutoCreateRowSorter(true); + spTabela = new JScrollPane(tbUsuarios); + spTabela.setBorder(BorderFactory.createEmptyBorder()); + + txtNomeUser = new JTextField(); + + txtNomeUser.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtSenha = new JTextField(); + txtSenha.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + txtPesquisar = new JTextArea(2, 15); + txtPesquisar.setLineWrap(true); + txtPesquisar.setSize(new Dimension(15, 20)); + txtPesquisar.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + cbNvAcesso = new JComboBox<>(new String[]{"Normal", "Administrador"}); + cbNvAcesso.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + cbNvAcesso.setBackground(Color.WHITE); + cbNvAcesso.setEditable(true); + + btApagar = new JButton("Apagar", new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/delete.png")))); + btApagar.setBackground(new Color(255, 129, 101)); + btApagar.setForeground(Color.WHITE); + btEditar = new JButton("Editar", new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/edit.png")))); + btEditar.setBackground(new Color(79, 195, 247)); + btEditar.setForeground(Color.WHITE); + btEditar.setEnabled(false); + btGravar = new JButton("Gravar", new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/save.png")))); + btGravar.setForeground(Color.WHITE); + btGravar.setBackground(new Color(0, 229, 202)); + btColapse = new JButton(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + btColapse.setBorderPainted(false); + btColapse.setBackground(new Color(255, 147, 147)); + btColapse.setHorizontalAlignment(SwingConstants.RIGHT); + + pnCbInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnCbInsercao.add(lbTituloRegistro, BorderLayout.CENTER); + pnCbInsercao.add(btColapse, BorderLayout.EAST); + + pnCentralInser.add(lbNome); + pnCentralInser.add(txtNomeUser); + pnCentralInser.add(lbSenha); + pnCentralInser.add(txtSenha); + pnCentralInser.add(lbNvAcesso); + pnCentralInser.add(cbNvAcesso); + pnCentralInser.add(new JLabel()); + pnCentralInser.add(new JLabel()); + + pnBt.add(btEditar); + pnBt.add(btGravar); + + pnInsercao.add(new JLabel(" "), BorderLayout.NORTH); + pnInsercao.add(pnCentralInser, BorderLayout.CENTER); + pnInsercao.add(new JLabel(" "), BorderLayout.EAST); + pnInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnInsercao.add(pnBt, BorderLayout.SOUTH); + + + pnCbConsulta.add(lbTituloConsulta); + pnPesquisa.add(txtPesquisar); + pnPesquisa.add(lbImgLupa); + pnBtApagar.add(btApagar); + pnConsultaSup.add(pnPesquisa); + pnConsultaSup.add(pnBtApagar); + + pnCentralCons.add(spTabela); + pnConsulta.add(new JLabel(" "), BorderLayout.SOUTH); + pnConsulta.add(pnCentralCons, BorderLayout.CENTER); + pnConsulta.add(pnConsultaSup, BorderLayout.NORTH); + pnConsulta.add(new JLabel(" "), BorderLayout.EAST); + pnConsulta.add(new JLabel(" "), BorderLayout.WEST); + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbInsercao); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnInsercao); + pnPrincipal.add(pnCbConsulta); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnConsulta); + + this.add(spUsers); + btColapse.addMouseListener(this); + btColapse.addActionListener(pnInsercao.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)); + tbUsuarios.addMouseListener(this); + + } + + public void fecharPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowDown.png")))); + limparTxt(); + btEditar.setEnabled(false); + btGravar.setEnabled(true); + } + + public void abrirPnInsercao() { + btColapse.setIcon(new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/triangle-arrowUp.png")))); + btGravar.setEnabled(true); + } + + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getSource() == btColapse) { + if (pnInsercao.isCollapsed()) { + fecharPnInsercao(); + } else { + abrirPnInsercao(); + + } + } + + if (e.getClickCount() == 2 && e.getSource() == tbUsuarios) { + codigo = Integer.parseInt((String) tbUsuarios.getValueAt(tbUsuarios.getSelectedRow(), 0)); + abrirPnInsercao(); + txtNomeUser.setText((String) tbUsuarios.getValueAt(tbUsuarios.getSelectedRow(), 1)); + txtSenha.setText((String) tbUsuarios.getValueAt(tbUsuarios.getSelectedRow(), 2)); + cbNvAcesso.setSelectedItem(tbUsuarios.getValueAt(tbUsuarios.getSelectedRow(), 3)); + btEditar.setEnabled(true); + btGravar.setEnabled(false); + pnInsercao.setCollapsed(false); + } + + pnPrincipal.updateUI(); + + } + + public int getCodigo() { + return codigo; + } + + public void addAccaoBtEditar(ActionListener accao) { + btEditar.addActionListener(accao); + } + + public void desabilitarBtEditar() { + btEditar.setEnabled(false); + } + + public void addActionBtGravar(ActionListener action) { + btGravar.addActionListener(action); + } + + public void addActionBtApagar(ActionListener action) { + btApagar.addActionListener(action); + } + + public void addActionTxtPesquisar(KeyListener action) { + txtPesquisar.addKeyListener(action); + } + + public String getPesquisa() { + return txtPesquisar.getText(); + } + public void hobilitarBtGravar(){btGravar.setEnabled(true);} + + public String getNome() { + return txtNomeUser.getText().trim(); + } + + public String getSenha() { + return txtSenha.getText().trim(); + } + + public String getNvAcesso() { + return (String) cbNvAcesso.getSelectedItem(); + } + + public JTable getTbUsuarios() { + return tbUsuarios; + } + + public void limparTxt() { + txtNomeUser.setText(null); + txtSenha.setText(null); + cbNvAcesso.setSelectedIndex(0); + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} diff --git a/src/View/TelaVenda.java b/src/View/TelaVenda.java new file mode 100755 index 0000000..cde12fc --- /dev/null +++ b/src/View/TelaVenda.java @@ -0,0 +1,356 @@ +package View; + +import org.jdesktop.swingx.JXDatePicker; +import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Date; +import java.util.Objects; + +public class TelaVenda extends JPanel implements MouseListener { + private final JLabel lbMTLiq; + private final JLabel lbIvaMoeda; + private final JLabel lbTituloRegistro; + private final JLabel lbTLiq; + private final JLabel lbTLiqNr; + private final JLabel lbIva; + private final JLabel lbIvaNr; + private final JLabel lbTotal; + private final JLabel lbTotalNr; + private final JLabel lbMoeda; + private final JLabel lbProduto; + private final JLabel lbCliente; + private final JLabel lbQty; + private final JLabel lbData; + private final JTextField txtQty; + private final JComboBox cbProduto; + private final JComboBox cbCliente; + private final JPanel pnPrincipal; + private final JPanel pnTotal; + private final JPanel pnIVA; + private final JPanel pnBt; + private final JPanel pnTb; + private final JPanel pnTLiq; + private final JPanel pnInsercao; + private final JPanel pnBtTb; + private final JPanel pnLateralInser; + private final JPanel pnCentralInser; + private final JPanel pnTbVenda; + private final JPanel pnCbInsercao; + private final JPanel pntxt; + private final JButton btConfirmar; + private final JButton btAdicionar; + private final JButton btCancelar; + private final JButton btRemover; + private final JScrollPane spProdVenda; + private final JScrollPane spVenda; + private final JTable tbProdVenda; + private final JXDatePicker datePicker; + + public TelaVenda() { + this.setLayout(new GridLayout(1, 1)); + + pnPrincipal = new JPanel(); + pnPrincipal.setLayout(new BoxLayout(pnPrincipal, BoxLayout.Y_AXIS)); + spVenda = new JScrollPane(pnPrincipal); + spVenda.setBorder(BorderFactory.createEmptyBorder()); + pnInsercao = new JPanel(new BorderLayout(10, 5)); + pntxt = new JPanel(new GridLayout(5, 2, 5, 40)); + pnBt = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + pnBtTb = new JPanel(new FlowLayout(FlowLayout.CENTER)); + pnTb = new JPanel(new FlowLayout(FlowLayout.CENTER)); + pnIVA = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnIVA.setBackground(Color.WHITE); + pnTLiq = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnTotal = new JPanel(new FlowLayout(FlowLayout.LEFT)); + pnTbVenda = new JPanel(); + pnTbVenda.setLayout(new BoxLayout(pnTbVenda, BoxLayout.Y_AXIS)); + pnCbInsercao = new JPanel(new BorderLayout()); + pnCbInsercao.setBackground(new Color(255, 147, 147)); + pnCbInsercao.setMaximumSize(new Dimension(90000, 30)); + pnCbInsercao.setPreferredSize(new Dimension(0, 30)); + pnCentralInser = new JPanel(); + pnCentralInser.setLayout(new BoxLayout(pnCentralInser, BoxLayout.Y_AXIS)); + pnLateralInser = new JPanel(); + pnLateralInser.setLayout(new BorderLayout()); + + lbTituloRegistro = new JLabel("Nova Venda"); + lbTituloRegistro.setForeground(Color.WHITE); + lbProduto = new JLabel("Produto: "); + lbCliente = new JLabel("Cliente: "); + lbQty = new JLabel("Quantidade: "); + lbData = new JLabel("Data da Venda: "); + lbTotal = new JLabel("Total: "); + estiloLabel(lbTotal, 35); + lbTotalNr = new JLabel("0,00"); + estiloLabel(lbTotalNr, 35); + lbMoeda = new JLabel("MT"); + estiloLabel(lbMoeda, 35); + lbMTLiq = new JLabel("MT"); + estiloLabel(lbMTLiq, 35); + lbIva = new JLabel("Total IVA: "); + estiloLabel(lbIva, 20); + lbIvaNr = new JLabel("0,00"); + estiloLabel(lbIvaNr, 20); + lbIvaMoeda = new JLabel("MT"); + estiloLabel(lbIvaMoeda, 20); + lbTLiq = new JLabel("T.Líquido: "); + estiloLabel(lbTLiq, 35); + lbTLiqNr = new JLabel("0,00"); + estiloLabel(lbTLiqNr, 35); + + tbProdVenda = new JTable(new DefaultTableModel(new String[]{"Produto", "Quantidade", "P/unidade", "Preço"}, 0)) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + estiloTabela(tbProdVenda); + spProdVenda = new JScrollPane(tbProdVenda); + spProdVenda.setBorder(BorderFactory.createEmptyBorder()); + spProdVenda.setBackground(Color.WHITE); + spProdVenda.getViewport().setBackground(Color.WHITE); + + txtQty = new JTextField(); + txtQty.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + cbProduto = new JComboBox<>(new String[]{"Seleccione o produto"}); + cbProduto.setEditable(true); + AutoCompleteDecorator.decorate(cbProduto); + cbProduto.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + cbProduto.setBackground(Color.WHITE); + cbCliente = new JComboBox<>(new String[]{"Seleccione o Cliente"}); + cbCliente.setEditable(true); + AutoCompleteDecorator.decorate(cbCliente); + cbCliente.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + cbCliente.setBackground(Color.WHITE); + datePicker = new JXDatePicker(new Date()); + datePicker.setFormats("MMMM, dd, yyyy"); + datePicker.getEditor().setEditable(false); + datePicker.getEditor().setBackground(Color.WHITE); + datePicker.setBorder(BorderFactory.createLineBorder(new Color(25, 103, 95))); + + btConfirmar = new JButton("Confirmar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/confirm.png")))); + btConfirmar.setForeground(Color.WHITE); + btConfirmar.setBackground(new Color(127, 232, 129)); + btAdicionar = new JButton("Adicionar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/add.png")))); + btAdicionar.setForeground(Color.WHITE); + btAdicionar.setBackground(new Color(0, 229, 202)); + btRemover = new JButton("Remover",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/remove.png")))); + btRemover.setForeground(Color.WHITE); + btRemover.setBackground(new Color(224, 79, 95)); + btCancelar = new JButton("Cancelar",new ImageIcon(Objects.requireNonNull(TelaPrincipal.class.getResource("/View/Icons/cancel.png")))); + btCancelar.setForeground(Color.WHITE); + btCancelar.setBackground(new Color(255, 129, 101)); + + pnCbInsercao.add(new JLabel(" "), BorderLayout.WEST); + pnCbInsercao.add(lbTituloRegistro, BorderLayout.CENTER); + + pnBt.add(btAdicionar); + + pntxt.add(lbProduto); + pntxt.add(cbProduto); + pntxt.add(lbCliente); + pntxt.add(cbCliente); + pntxt.add(lbQty); + pntxt.add(txtQty); + pntxt.add(lbData); + pntxt.add(datePicker); + pntxt.add(new JLabel()); + pntxt.add(pnBt); + + pnIVA.add(lbIva); + pnIVA.add(lbIvaNr); + pnIVA.add(lbIvaMoeda); + + pnTbVenda.add(spProdVenda); + pnTbVenda.add(pnIVA); + pnTbVenda.add(pnBtTb); + + pnTotal.add(lbTotal); + pnTotal.add(lbTotalNr); + pnTotal.add(lbMoeda); + + pnTLiq.add(lbTLiq); + pnTLiq.add(lbTLiqNr); + pnTLiq.add(lbMTLiq); + + pnCentralInser.add(new JPanel()); + pnCentralInser.add(pntxt); + pnCentralInser.add(new JPanel()); + pnCentralInser.add(pnTotal); + pnCentralInser.add(pnTLiq); + + pnTb.add(pnTbVenda); + pnBtTb.add(btCancelar); + pnBtTb.add(btRemover); + pnBtTb.add(btConfirmar); + + pnLateralInser.add(pnTb, BorderLayout.CENTER); + + pnInsercao.add(pnCentralInser, BorderLayout.CENTER); + pnInsercao.add(pnLateralInser, BorderLayout.EAST); + pnInsercao.add(new JLabel(" "), BorderLayout.WEST); + + + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnCbInsercao); + pnPrincipal.add(new JLabel(" ")); + pnPrincipal.add(pnInsercao); + pnPrincipal.add(new JLabel(" ")); + + this.add(spVenda); + + } + + private void estiloLabel(JLabel lb, int tamanho) { + lb.setForeground(new Color(255, 5, 5)); + lb.setFont(new Font(lbCliente.getFont().getFontName(), Font.BOLD, tamanho)); + } + + private void estiloTabela(JTable tb) { + tb.setShowGrid(false); + tb.setSelectionBackground(new Color(136, 224, 200)); + tb.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(0, 183, 164))); + tb.getTableHeader().setBackground(new Color(0, 183, 164)); + tb.setShowHorizontalLines(true); + tb.setAutoCreateRowSorter(true); + } + + + @Override + public void mouseClicked(MouseEvent e) { + + } + + public void addAccaoBtConfirmar(ActionListener action) { + btConfirmar.addActionListener(action); + } + + public void addAccaoBtRemover(ActionListener action) { + btRemover.addActionListener(action); + } + + public void addAccaoBtAdicionar(ActionListener action) { + btAdicionar.addActionListener(action); + } + + public void addAccaoBtCancelar(ActionListener action) { + btCancelar.addActionListener(action); + } + + + public int getQty() throws NumberFormatException { + return Integer.parseInt(txtQty.getText().trim()); + } + + public Object getProduto() { + return cbProduto.getSelectedItem(); + } + + public Date getData() { + return datePicker.getDate(); + + } + + public Object getCliente() { + return cbCliente.getSelectedItem(); + } + + public JTable getTbProdVenda() { + return tbProdVenda; + } + + + public void limparTxt() { + txtQty.setText(null); + cbProduto.setSelectedIndex(0); + } + public void limparCalc(){ + setLbTotalNr(0.00); + setLbTotalLiq(0.00); + setLbIvaNr(0.00); + } + + public void limparTb() { + tbProdVenda.setModel(new DefaultTableModel(new String[]{"Produto", "Quantidade", "P/unidade", "Preço"}, 0)); + } + + public void addProduto(String produto) { + cbProduto.addItem(produto); + } + + public void addCliente(String cliente) { + cbCliente.addItem(cliente); + } + + public void setLbTotalNr(double nr) { + lbTotalNr.setText(String.format("%.2f", nr)); + } + + public void setLbTotalLiq(double nr) { + lbTLiqNr.setText(String.format("%.2f", nr)); + } + + public void setLbIvaNr(double nr) { + + lbIvaNr.setText(String.format("%.2f", nr)); + } + + public void message(String message) { + JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE); + } + + public void errorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); + } + + public void warningMassage(String message){ + JOptionPane.showMessageDialog(this, message, "Ateção", JOptionPane.WARNING_MESSAGE); + } + + public int confirmationMessage(String message) { + return JOptionPane.showConfirmDialog(this, message, "Confirmação", JOptionPane.YES_NO_OPTION); + } + + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} diff --git a/swingx-all-1.6.4.jar b/swingx-all-1.6.4.jar new file mode 100755 index 0000000..3078bb6 Binary files /dev/null and b/swingx-all-1.6.4.jar differ