Criar um formulário de Pesquisa(FILTRO)

25/03/2019

0

Olá boa tarde, sou iniciante no Delphi, estou utilizando o banco DBExpress, firebird, gostaria de saber como faço para criar um filtro de pesquisa utilizando o Jvdbcombobox...
Octavio

Octavio

Responder

Posts

25/03/2019

Octavio

Resolvido, solução:
procedure TfrmPesquisar.btnBuscarClick(Sender: TObject);
begin
case cbFiltro.ItemIndex of
0: try
dtmDados.CdCliente.Close;
dtmDados.CdCliente.CommandText:= 'select * from cliente where cod_cliente like :pcod_cliente';
dtmDados.CdCliente.ParamByName('pcod_cliente').Value := '%' + edtPesquisa.Text + '%';
dtmDados.CdCliente.Open;
finally
end;

1: try
dtmDados.CdCliente.Close;
dtmDados.CdCliente.CommandText:= 'select * from cliente where nome like :pnome';
dtmDados.CdCliente.ParamByName('pnome').Value := '%' + edtPesquisa.Text + '%';
dtmDados.CdCliente.Open;
finally
end;

2: try
dtmDados.CdCliente.Close;
dtmDados.CdCliente.CommandText:= 'select * from cliente where fantasia like :pfantasia';
dtmDados.CdCliente.ParamByName('pfantasia').Value := '%' + edtPesquisa.Text + '%';
dtmDados.CdCliente.Open;
finally
end;
end;

end;
Responder

31/03/2019

Hélio Devmedia

Olá Otávio,

Seu código está corretíssimo, mas seria bom você otimizar o seu código por exemplo:

begin
  dtmDados.CdCliente.Close;

  try
    case cbFiltro.ItemIndex of
    0:
      begin
        dtmDados.CdCliente.CommandText:= 'select * from cliente where cod_cliente like :pcod_cliente';
        dtmDados.CdCliente.ParamByName('pcod_cliente').Value := '%' + edtPesquisa.Text + '%';
      end;
    1:
      begin
        dtmDados.CdCliente.CommandText:= 'select * from cliente where nome like :pnome';
        dtmDados.CdCliente.ParamByName('pnome').Value := '%' + edtPesquisa.Text + '%';
      end;

    2:
      begin
        dtmDados.CdCliente.CommandText:= 'select * from cliente where fantasia like :pfantasia';
        dtmDados.CdCliente.ParamByName('pfantasia').Value := '%' + edtPesquisa.Text + '%';
      end;
    end;

    dtmDados.CdCliente.Open;
  finally

  end;
end;


Espero ter ajudado, um forte abraço e fique com Deus.
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar