Exemplo n.º 1
0
  public void editCliente(Cliente cliente) {
    String sql =
        "update cliente"
            + "set nome = ?, rg = ?, dataNasc = ?, telefone = ?, celular = ?, "
            + "email = ?, cep = ?, rua = ?, numero = ?, bairro = ?, cidade = ?, uf = ?"
            + "where idCpfCliente = ?";

    try {
      PreparedStatement stmt = conexao.prepareStatement(sql);

      stmt.setString(1, cliente.getNome());
      stmt.setString(2, cliente.getRg());
      stmt.setDate(3, new Date(cliente.getDataNasc().getTimeInMillis()));
      stmt.setString(4, cliente.getTelefone());
      stmt.setString(5, cliente.getCelular());
      stmt.setString(6, cliente.getEmail());
      stmt.setInt(7, cliente.getCep());
      stmt.setString(8, cliente.getRua());
      stmt.setInt(9, cliente.getNumero());
      stmt.setString(10, cliente.getBairro());
      stmt.setString(11, cliente.getCidade());
      stmt.setString(12, cliente.getUf());
      stmt.setLong(13, cliente.getIdCpfCliente());
      stmt.execute();
      stmt.close();

    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 2
0
  public void addCliente(Cliente cliente) {
    String sql =
        "insert into cliente"
            + "(idCpfCliente, nome, rg, dataNasc, telefone, celular, email, cep, rua, numero, bairro, cidade, uf)"
            + "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

    try {
      PreparedStatement stmt = conexao.prepareStatement(sql);

      stmt.setLong(1, cliente.getIdCpfCliente());
      stmt.setString(2, cliente.getNome());
      stmt.setString(3, cliente.getRg());
      stmt.setDate(4, new Date(cliente.getDataNasc().getTimeInMillis()));
      stmt.setString(5, cliente.getTelefone());
      stmt.setString(6, cliente.getCelular());
      stmt.setString(7, cliente.getEmail());
      stmt.setInt(8, cliente.getCep());
      stmt.setString(9, cliente.getRua());
      stmt.setInt(10, cliente.getNumero());
      stmt.setString(11, cliente.getBairro());
      stmt.setString(12, cliente.getCidade());
      stmt.setString(13, cliente.getUf());
      stmt.execute();
      stmt.close();

    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 3
0
 public void excluir(Cliente c) {
   PreparedStatement ps;
   try {
     ps = con.prepareStatement("DELETE FROM CLIENTE WHERE ID =" + c.getId());
     int res = ps.executeUpdate();
     ps.close();
     JOptionPane.showMessageDialog(null, "( " + res + " ) cliente" + "\nExcluido com sucesso.");
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(null, "Erro ao deletar dados do cliente \n->" + c.getNome());
   }
 }
Exemplo n.º 4
0
 /**
  * Metodo que pesquisa clientes dentro de uma agencia
  *
  * @param agencia Codigo da agencia a ser pesquisada
  * @param cliente Nome do cliente a ser pesquisado
  * @return Mensagem de retorno
  */
 public static String pesquisaClienteNaAgencia(int agencia, String cliente) {
   Agencia aux = new Agencia();
   Cliente c = new Cliente();
   String informações = new String();
   for (int cont = 0; cont < listaAgencia.size(); cont++) {
     aux = listaAgencia.get(cont);
     if (aux.getId() == agencia) {
       for (int cont2 = 0; cont2 < aux.size(); cont2++) {
         c = aux.get(cont2);
         if (c.getNome().equals(cliente)) {
           informações += c.toString() + "\n";
         }
       }
       return "As informações encontradas para pessoas com este nome foi:\n" + informações;
     }
   }
   return "Não foi possível localizar alguma agência com este nome";
 }
Exemplo n.º 5
0
  public void iserir(Cliente c) {
    PreparedStatement ps;
    try {
      ps =
          con.prepareStatement(
              "INSERT INTO CLIENTE (id,nome,endereco,telefone,cidade,uf) VALUES (? , ?, ?, ?, ?, ?)");
      ps.setInt(1, c.getId());
      ps.setString(2, c.getNome());
      ps.setString(3, c.getEndereco());
      ps.setString(4, c.getTelefone());
      ps.setString(5, c.getCidade());
      ps.setObject(6, c.getUf().getNome());
      ps.executeUpdate();
      ps.close();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 6
0
  public void atualizar(Cliente c) {
    PreparedStatement ps;
    try {
      ps =
          con.prepareStatement(
              "UPDATE CLIENTE SET NOME = ?,ENDERECO = ?,TELEFONE = ?,UF = ? WHERE ID ="
                  + c.getId());
      ps.setInt(1, c.getId());
      ps.setString(2, c.getNome() + "");
      ps.setString(3, c.getEndereco() + "");
      ps.setString(4, c.getTelefone() + "");
      ps.setString(5, c.getCidade() + "");
      ps.setObject(6, c.getUf() + "");
      ps.executeUpdate();
      ps.close();

    } catch (SQLException e) {
      JOptionPane.showMessageDialog(null, "Erro ao atualizar dados do cliente!");
    }
  }
  @Override
  public String toString() {

    String result = "";

    result =
        "Vendedor: "
            + vendedor.getNome()
            + "\n"
            + "Cliente: "
            + cliente.getNome()
            + "\n"
            + "ComDescontoDe: "
            + desconto.getPorcetagem()
            + "%"
            + "\n"
            + "OsProdutos: \n";

    for (Produto p : produtos.getProdutos()) {
      result += "--> " + p.getNome() + " \n";
    }
    return result;
  }
Exemplo n.º 8
0
 public void setCliente(String value, String tipo, Database x) // email ou telefone
     {
   this.c = x.search(value, tipo).get(0);
   nomeCliente = c.getNome();
 }
Exemplo n.º 9
0
  public String toString() {
    DateFormat dtF = DateFormat.getDateInstance(DateFormat.DEFAULT);

    return cliente.getNome() + " - " + dtF.format(dataCompra.getTime());
  }
  CadastrarCliente() {
    setTitle("Cadastrar Clientes");
    setLayout(null);
    posicionaObjeto(jlbPesquisar, 10, 10, 100, 25);
    posicionaObjeto(jrbCodigo, 10, 30, 100, 25);
    posicionaObjeto(jrbNome, 10, 50, 150, 25);
    posicionaObjeto(jtfPesquisar, 160, 30, 300, 25);
    scpRolagem.setBounds(10, 80, 550, 300);
    scpRolagem.add(jtbTabela);
    getContentPane().add(scpRolagem);
    posicionaObjeto(jbtPesquisar, 470, 20, 100, 25);
    posicionaObjeto(jbtMostrar, 460, 50, 120, 25);
    posicionaObjeto(jbtNovo, 20, 400, 70, 25);
    posicionaObjeto(jbtConsultar, 110, 400, 100, 25);
    posicionaObjeto(jbtAlterar, 230, 400, 100, 25);
    posicionaObjeto(jbtExcluir, 350, 400, 100, 25);
    posicionaObjeto(jbtSair, 460, 400, 90, 25);

    jrbCodigo.setBackground(Color.white);
    jrbNome.setBackground(Color.white);

    btgEscolha.add(jrbCodigo);
    btgEscolha.add(jrbNome);

    jtbTabela.setModel(dtmTabela);

    dtmTabela.setColumnCount(3);
    dtmTabela.setRowCount(n);
    dtmTabela.setValueAt("Código", 0, 0);
    dtmTabela.setValueAt("Cliente", 0, 1);
    dtmTabela.setValueAt("Telefone", 0, 2);

    dtmTodos.setColumnCount(3);
    dtmTodos.setRowCount(1);
    ObjectSet<Cliente> clientes = bancoDeDados.query(Cliente.class);
    int linha = 1;
    for (Cliente cliente : clientes) {
      dtmTabela.setRowCount(dtmTabela.getRowCount() + 1);
      dtmTabela.setValueAt(cliente.getCodigo(), linha, 0);
      dtmTabela.setValueAt(cliente.getNome(), linha, 1);
      dtmTabela.setValueAt(cliente.getTelefone(), linha, 2);
      linha++;
    }

    jbtPesquisar.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            if (jrbNome.isSelected()) {
              if (jtfPesquisar.getText().isEmpty()) {
                JOptionPane.showMessageDialog(
                    null, "Digite o nome do cliente que deseja pesquisar");
              } else {
                ObjectSet<Cliente> clientes = bancoDeDados.query(Cliente.class);
                int aux = 0, linha = 1;
                dtmTabela.setRowCount(1);
                for (Cliente cliente1 : clientes) {
                  if (cliente1.getNome().equals(jtfPesquisar.getText())) {
                    dtmTabela.setRowCount(dtmTabela.getRowCount() + 1);
                    dtmTabela.setValueAt(cliente1.getCodigo(), linha, 0);
                    dtmTabela.setValueAt(cliente1.getNome(), linha, 1);
                    dtmTabela.setValueAt(cliente1.getTelefone(), linha, 2);
                    linha++;
                    aux = 1;
                  }
                }
                if (aux == 0 || jtfPesquisar.getText().isEmpty()) {
                  JOptionPane.showMessageDialog(null, "Nenhum Cliente Encontrado");
                }
              }
            } else if (jrbCodigo.isSelected()) {
              if (jtfPesquisar.getText().isEmpty()) {
                JOptionPane.showMessageDialog(
                    null, "Digite o código do cliente que deseja pesquisar");
              } else {
                ObjectSet<Cliente> clientes = bancoDeDados.query(Cliente.class);
                int aux = 0, linha = 1;
                dtmTabela.setRowCount(1);
                for (Cliente cliente1 : clientes) {
                  if (cliente1.getCodigo().equals(Integer.valueOf(jtfPesquisar.getText()))) {
                    dtmTabela.setRowCount(dtmTabela.getRowCount() + 1);
                    dtmTabela.setValueAt(cliente1.getCodigo(), linha, 0);
                    dtmTabela.setValueAt(cliente1.getNome(), linha, 1);
                    dtmTabela.setValueAt(cliente1.getTelefone(), linha, 2);
                    linha++;
                    aux = 1;
                  }
                }
                if (aux == 0 || jtfPesquisar.getText().isEmpty()) {
                  JOptionPane.showMessageDialog(null, "Nenhum Cliente Encontrado");
                }
              }
            } else {
              JOptionPane.showMessageDialog(null, "Selecione uma opção para pesquisar");
            }
          }
        });
    jbtNovo.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            bancoDeDados.close();
            dispose();
            new NovoCliente();
          }
        });
    jbtConsultar.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            selecionado = jtbTabela.getSelectedRow();

            if (selecionado == 0) {
              JOptionPane.showMessageDialog(null, "Não pode Visualizar essa linha");
            } else if (selecionado == -1) {
              JOptionPane.showMessageDialog(null, "Selecione o cliente que deseja Visualizar");
            } else {
              if (aux == 1) selecionado = procurar;
              bancoDeDados.close();
              VisualizarCliente tela = new VisualizarCliente();
              tela.setValor1(selecionado - 1);
              dispose();
            }
          }
        });
    jbtAlterar.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            selecionado = jtbTabela.getSelectedRow();
            if (selecionado == 0) {
              JOptionPane.showMessageDialog(null, "Não pode alterar essa linha");
            } else if (selecionado == -1) {
              JOptionPane.showMessageDialog(null, "Selecione o cliente que deseja alterar");
            } else {
              if (aux == 1) selecionado = procurar;
              bancoDeDados.close();
              AlterarCliente tela = new AlterarCliente();
              tela.setValor1(selecionado - 1);
              dispose();
            }
          }
        });
    jbtMostrar.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            bancoDeDados.close();
            dispose();
            new CadastrarCliente();
          }
        });
    jbtExcluir.addActionListener(
        new ActionListener() {
          ObjectSet<ContaAReceber> contas = bancoDeDados.query(ContaAReceber.class);

          public void actionPerformed(ActionEvent arg0) {
            selecionado = jtbTabela.getSelectedRow();
            if (selecionado == 0) {
              JOptionPane.showMessageDialog(null, "Não pode excluir essa linha");
            } else if (selecionado == -1) {
              JOptionPane.showMessageDialog(null, "Selecione o cliente que deseja excluir");
            } else {
              if (aux == 1) selecionado = procurar;
              Integer auxx = 0;
              ObjectSet<Cliente> clientes = bancoDeDados.query(Cliente.class);
              for (ContaAReceber conta : contas) {
                if (conta.getCliente().getNome().equals(clientes.get(selecionado - 1).getNome())) {
                  if (conta.getDataVencimento() != null) {
                    auxx = 1;
                  }
                }
              }
              if (auxx == 1) {
                JOptionPane.showMessageDialog(null, "Você Não Pode Excluir esse Cliente");
                JOptionPane.showMessageDialog(null, "Há Conta(s) a Receber Pendente(s)");
              } else {
                for (ContaAReceber conta : contas) {
                  if (conta
                      .getCliente()
                      .getNome()
                      .equals(clientes.get(selecionado - 1).getNome())) {
                    bancoDeDados.delete(conta);
                  }
                }
                bancoDeDados.delete(clientes.get(selecionado - 1));
              }
              bancoDeDados.close();
              dispose();
              new CadastrarCliente();
            }
          }
        });
    jbtSair.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            bancoDeDados.close();
            dispose();
          }
        });

    setSize(600, 600);
    setLocationRelativeTo(null);
    this.getContentPane().setBackground(Color.white);
    this.setResizable(false);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    setVisible(true);
  }