-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupesquisa.pas
107 lines (90 loc) · 2.44 KB
/
upesquisa.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
unit upesquisa;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, db, Forms, Controls, Graphics, Dialogs, DBGrids, StdCtrls,
ZConnection, ZDataset;
type
{ TfrmPesquisa }
TfrmPesquisa = class(TForm)
btnPesquisa: TButton;
cbCampos: TComboBox;
cbFiltro: TComboBox;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
edtResultado: TEdit;
edtBusca: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ZConnection1: TZConnection;
ZQuery1: TZQuery;
procedure btnPesquisaClick(Sender: TObject);
procedure DBGrid1DblClick(Sender: TObject);
private
cCampos, cCampoRetorno, cTabela : string;
public
constructor Create(AOwner : TComponent; par_lstCampos : Array of string;par_cTabela, par_cCampoResult :string);
end;
var
frmPesquisa: TfrmPesquisa;
implementation
{$R *.lfm}
{ TfrmPesquisa }
procedure TfrmPesquisa.btnPesquisaClick(Sender: TObject);
begin
if ZQuery1.Active then
ZQuery1.Close;
with ZQuery1.sql do
begin
Clear;
add('select '+cCampos);
add('from '+cTabela);
add('where '+trim(cbCampos.Text)+' like :cParametro');
end;
if trim(cbFiltro.Text) = 'parte' then
ZQuery1.ParamByName('cParametro').AsString:='%'+trim(edtBusca.text)+'%'
else if trim(cbFiltro.Text) = 'igual' then
ZQuery1.ParamByName('cParametro').AsString:=trim(edtBusca.text)
else if trim(cbFiltro.Text) = 'inicio' then
ZQuery1.ParamByName('cParametro').AsString:=trim(edtBusca.text)+'%' ;
ZQuery1.Open;
edtResultado.Text:='';
end;
procedure TfrmPesquisa.DBGrid1DblClick(Sender: TObject);
begin
edtResultado.Text:=ZQuery1.FieldByName(cCampoRetorno).AsVariant;
ZQuery1.Close;
ZConnection1.Disconnect;
frmPesquisa.ModalResult:=mrYes;
end;
constructor TfrmPesquisa.Create(AOwner: TComponent;
par_lstCampos: array of string; par_cTabela, par_cCampoResult: string);
var
n : Integer;
begin
inherited Create(AOwner);
ZConnection1.Connect;
cCampoRetorno:=par_cCampoResult;
cCampos:='';
cTabela:=par_cTabela;
for n := 0 to Length(par_lstCampos) -1 do
begin
cbCampos.Items.Add(par_lstCampos[n]);
if n = 0 then
cCampos := par_lstCampos[n]
else
cCampos := cCampos +','+ par_lstCampos[n];
end;
cbCampos.ItemIndex:=1;
if ZQuery1.Active then
ZQuery1.Close;
with ZQuery1.sql do
begin
Clear;
add('select '+cCampos);
add('from '+cTabela);
end;
ZQuery1.Open;
end;
end.