-
Notifications
You must be signed in to change notification settings - Fork 1
/
ItemPageUnit.pas
160 lines (140 loc) · 3.3 KB
/
ItemPageUnit.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
unit ItemPageUnit;
interface
uses
System.SysUtils,
System.Types,
System.UITypes,
System.Classes,
System.Variants,
System.IniFiles,
Data.DB,
FMX.Types,
FMX.Controls,
FMX.Forms,
FMX.Dialogs,
FMX.Objects,
FMX.Menus,
FMX.Grid,
FMX.ExtCtrls,
FMX.ListBox,
FMX.TreeView,
FMX.Memo,
FMX.TabControl,
FMX.Layouts,
FMX.Edit,
FMX.Platform,
FMX.Bind.DBEngExt,
FMX.Bind.Editors,
FMX.Bind.DBLinks,
FMX.Bind.Navigator,
Data.Bind.EngExt,
Data.Bind.Components,
Data.Bind.DBScope,
Data.Bind.DBLinks,
Datasnap.DBClient,
Fmx.Bind.Grid,
System.Rtti,
System.Bindings.Outputs,
Data.Bind.Grid,
Fmx.StdCtrls,
FMX.Header,
FMX.Graphics,
MyDataModule;
type
TItemPageForm = class(TForm)
Panel1: TPanel;
btOK: TButton;
btCancel: TButton;
PageControl1: TTabControl;
tsSearch: TTabItem;
pnSearch: TPanel;
edPageID: TEdit;
edPageID_LBL: TLabel;
btSearch: TButton;
lvPageItem: TJvListView;
MyQuery: TFDQuery;
edText: TEdit;
edText_LBL: TLabel;
procedure btSearchClick(Sender: TObject);
procedure lvPageItemChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure lvPageItemDblClick(Sender: TObject);
private
procedure Search;
public
procedure Prepare(Text: string);
end;
implementation
uses MainUnit;
{$R *.FMX}
procedure TItemPageForm.btSearchClick(Sender: TObject);
begin
Search;
with lvPageItem do if Items.Count>0 then begin SetFocus; Selected:=Items[0]; end;
end;
procedure TItemPageForm.Prepare(Text: string);
begin
edPageID.Text:=Text;
Search;
end;
procedure TItemPageForm.Search;
var
ID, Name, QueryStr, WhereStr: string;
begin
ID:= edPageID.Text;
Name:=edText.Text;
Name:=StringReplace(Name, '''', '\''', [rfReplaceAll]);
Name:=StringReplace(Name, ' ', '%', [rfReplaceAll]);
Name:='%'+Name+'%';
QueryStr:='';
WhereStr:='';
if ID<>'' then
WhereStr:=Format('WHERE (`entry` = %s)',[ID]);
if Name<>'' then
begin
if WhereStr<> '' then
WhereStr:=Format('%s AND (`text` LIKE ''%s'')',[WhereStr, Name])
else
WhereStr:=Format('WHERE (`text` LIKE ''%s'')',[Name]);
end;
QueryStr:=Format('SELECT * FROM `page_text` %s',[WhereStr]);
MyQuery.SQL.Text:=QueryStr;
lvPageItem.Items.BeginUpdate;
try
MyQuery.Open;
lvPageItem.Clear;
while not MyQuery.Eof do
begin
with lvPageItem.Items.Add do
begin
Caption:=MyQuery.FieldByName('entry').AsString;
SubItems.Add(MyQuery.FieldByName('text').AsString);
MyQuery.Next;
end;
end;
finally
lvPageItem.Items.EndUpdate;
MyQuery.Close;
end;
end;
procedure TItemPageForm.lvPageItemChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
btOK.Enabled:=Assigned(lvPageItem.Selected);
end;
procedure TItemPageForm.lvPageItemDblClick(Sender: TObject);
begin
if Assigned(TJvListView(Sender).Selected) then ModalResult:=mrOk;
end;
procedure TItemPageForm.FormShow(Sender: TObject);
begin
with lvPageItem do if Items.Count>0 then begin SetFocus; Selected:=Items[0]; end;
end;
procedure TItemPageForm.FormCreate(Sender: TObject);
begin
dmMain.Translate.CreateDefaultTranslation(TForm(Self));
dmMain.Translate.TranslateForm(TForm(Self));
end;
end.