SHARE
TWEET

Untitled

a guest Jan 16th, 2020 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure TFrmFrameBarraPesquisa.Pesquisa(qtdRegistros: Integer; nomeCampo, strPesquisa, strTabela, strTipoCliente: string; qry: TFDQuery);
  2. var
  3.   Operador: String;
  4.   Coringa: string;
  5. begin
  6.   Coringa := '';
  7.  
  8.   case cbbOperador.ItemIndex of
  9.     0:
  10.       begin
  11.         Operador := 'LIKE'; // Igual
  12.         Coringa  := '%';
  13.       end;
  14.     1:
  15.       Operador := '<>'; // Diferente
  16.     2:
  17.       Operador := '>'; // Maior
  18.     3:
  19.       Operador := '<'; // Menor
  20.   end;
  21.  
  22.   try
  23.     qry.close;
  24.     qry.SQL.Clear;
  25.  
  26.     if qtdRegistros > 0 then
  27.       qry.SQL.Add('SELECT FIRST ' + IntToStr(qtdRegistros) + ' *')
  28.     else
  29.       qry.SQL.Add('SELECT *');
  30.  
  31.     qry.SQL.Add('FROM ' + strTabela);
  32.     qry.SQL.Add('WHERE');
  33.     qry.SQL.Add(nomeCampo + ' ' + Operador + ' ' + QuotedStr(strPesquisa + Coringa));
  34.  
  35.     if strTipoCliente = '' then
  36.       qry.SQL.Add('AND EMPRESA = ' + IntToStr(FParametros.Empresa.Codigo));
  37.  
  38.     if strTipoCliente = 'F' then
  39.     begin
  40.       qry.SQL.Add('AND CLASSIFICACAO =' + QuotedStr('F'));
  41.       qry.SQL.Add('AND TIPO =' + QuotedStr('CLIENTE'));
  42.     end;
  43.  
  44.     if strTipoCliente = 'J' then
  45.     begin
  46.       qry.SQL.Add('AND CLASSIFICACAO =' + QuotedStr('J'));
  47.       qry.SQL.Add('AND TIPO =' + QuotedStr('CLIENTE'));
  48.     end;
  49.  
  50.     if strTipoCliente = 'FORNECEDOR' then
  51.       qry.SQL.Add('AND TIPO =' + QuotedStr('FORNECEDOR'));
  52.  
  53.     if strTipoCliente = 'VENDEDOR' then
  54.       qry.SQL.Add('AND TIPO =' + QuotedStr('VENDEDOR'));
  55.  
  56.     case cbbExibirInativos.ItemIndex of
  57.       0:
  58.         qry.SQL.Add('AND ATIVO = ' + QuotedStr('S'));
  59.       1:
  60.         qry.SQL.Add('AND ATIVO = ' + QuotedStr('N'));
  61.     end;
  62.  
  63.     if qtdRegistros = -1 then
  64.       qry.SQL.Add('AND CODIGO = ' + QuotedStr('-1'));
  65.  
  66.     qry.SQL.Add('ORDER BY ' + nomeCampo + ' ASC');
  67.     qry.Open();
  68.  
  69.  
  70.   Except
  71.     raise Exception.Create('Sua pesquisa não atende os parametros');
  72.   end;
  73. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top