unit uFormPesqClientes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uFormModelodePesquisa, Grids, DBGrids, StdCtrls, daEdit, ExtCtrls,
  FMTBcd, SqlExpr, Provider, DB, DBClient, Mask, MaskUtils, Buttons;

type
  TfrmPesqClientes = class(TfrmModelodePesquisa)
    DSPesqClientes: TDataSource;
    CDSPesqClientes: TClientDataSet;
    DSPPesqClientes: TDataSetProvider;
    SDSPesqClientes: TSQLDataSet;
    CDSPesqClientesID_CLIENTE: TIntegerField;
    CDSPesqClientesNOME: TStringField;
    CDSPesqClientesFANTASIA: TStringField;
    CDSPesqClientesCPFCNPJ: TStringField;
    CDSPesqClientesTIPO: TStringField;
    procedure FormShow(Sender: TObject);
    procedure edtPesquisaChange(Sender: TObject);
    procedure CDSPesqClientesCPFCNPJGetText(Sender: TField; var Text: string;
      DisplayText: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPesqClientes: TfrmPesqClientes;

implementation

uses uDM;

{$R *.dfm}

procedure TfrmPesqClientes.CDSPesqClientesCPFCNPJGetText(Sender: TField;
  var Text: string; DisplayText: Boolean);
begin
  inherited;
  if CDSPesqClientesTIPO.AsString = 'F' then
     Text := FormatMaskText( '000.000.000-00;0;_', Sender.asString)
  else if CDSPesqClientesTIPO.AsString = 'J' then
     Text := FormatMaskText('00.000.000/0000-00;0;_', Sender.asString)
end;

procedure TfrmPesqClientes.edtPesquisaChange(Sender: TObject);
begin
  inherited;
  if Length(edtPesquisa.Text) = 1 then

  if edtPesquisa.Text[1] in ['A'..'Z'] then
  begin
    CDSPesqClientes.IndexFieldNames := 'NOME';
  end
  ELSE
  IF edtPesquisa.Text[1] in ['0'..'9'] then
  begin
    CDSPesqClientes.IndexFieldNames := 'CPFCNPJ';
  end;
  CDSPesqClientes.FindNearest([edtPesquisa.Text]);
end;

procedure TfrmPesqClientes.FormShow(Sender: TObject);
begin
  inherited;
  CDSPesqClientes.Open;
end;

end.
