This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
ItemPageUnit.pas
122 lines (103 loc) · 2.8 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
unit ItemPageUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, DB,
MyDataModule, Menus, JvExComCtrls, JvListView,
FireDAC.Comp.Client;
type
TItemPageForm = class(TForm)
Panel1: TPanel;
btOK: TButton;
btCancel: TButton;
PageControl1: TPageControl;
tsSearch: TTabSheet;
pnSearch: TPanel;
edPageID: TLabeledEdit;
btSearch: TButton;
lvPageItem: TJvListView;
MyQuery: TFDQuery;
edText: TLabeledEdit;
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 *.dfm}
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.