-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAdvancedSearchForm.pas
254 lines (226 loc) · 8.88 KB
/
AdvancedSearchForm.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
unit AdvancedSearchForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,
InflatablesList_Types,
InflatablesList_Manager;
type
TfAdvancedSearchForm = class(TForm)
leTextToFind: TLabeledEdit;
btnSearch: TButton;
grbSearchSettings: TGroupBox;
cbPartialMatch: TCheckBox;
cbCaseSensitive: TCheckBox;
cbTextsOnly: TCheckBox;
cbEditablesOnly: TCheckBox;
cbSearchCalculated: TCheckBox;
cbIncludeUnits: TCheckBox;
cbSearchShops: TCheckBox;
cbDeepScan: TCheckBox;
bvlHorSplit: TBevel;
lblSearchResults: TLabel;
meSearchResults: TMemo;
btnSaveReport: TButton;
diaReportSave: TSaveDialog;
procedure FormShow(Sender: TObject);
procedure leTextToFindKeyPress(Sender: TObject; var Key: Char);
procedure btnSearchClick(Sender: TObject);
procedure cbSearchShopsClick(Sender: TObject);
procedure meSearchResultsKeyPress(Sender: TObject; var Key: Char);
procedure btnSaveReportClick(Sender: TObject);
private
{ Private declarations }
fILManager: TILManager;
procedure CreateReport(SearchResults: TILAdvSearchResults);
public
{ Public declarations }
procedure Initialize(ILManager: TILManager);
procedure Finalize;
procedure ShowAdvancedSearch;
end;
var
fAdvancedSearchForm: TfAdvancedSearchForm;
implementation
uses
InflatablesList_Utils;
{$R *.dfm}
procedure TfAdvancedSearchForm.CreateReport(SearchResults: TILAdvSearchResults);
var
i,j: Integer;
ISR: TILAdvItemSearchResult;
SSR: TILAdvShopSearchResult;
Temp: String;
begin
Screen.Cursor := crHourGlass;
try
meSearchResults.Lines.BeginUpdate;
try
meSearchResults.Lines.Add(IL_Format('Search report %s',[IL_FormatDateTime('yyyy-mm-dd hh:nn:ss',Now)]));
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(IL_Format(' Searched string: "%s"',[leTextToFind.Text]));
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(' Search settings:');
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(IL_Format(' %s Allow partial match',[IL_BoolToStr(cbPartialMatch.Checked,'-','+')]));
meSearchResults.Lines.Add(IL_Format(' %s Case sensitive comparisons',[IL_BoolToStr(cbCaseSensitive.Checked,'-','+')]));
meSearchResults.Lines.Add(IL_Format(' %s Search only textual values',[IL_BoolToStr(cbTextsOnly.Checked,'-','+')]));
meSearchResults.Lines.Add(IL_Format(' %s Search only editable values',[IL_BoolToStr(cbEditablesOnly.Checked,'-','+')]));
meSearchResults.Lines.Add(IL_Format(' %s Search calculated values',[IL_BoolToStr(cbSearchCalculated.Checked,'-','+')]));
meSearchResults.Lines.Add(IL_Format(' %s Include unit symbols',[IL_BoolToStr(cbIncludeUnits.Checked,'-','+')]));
meSearchResults.Lines.Add(IL_Format(' %s Search item shops',[IL_BoolToStr(cbSearchShops.Checked,'-','+')]));
meSearchResults.Lines.Add(IL_Format(' %s Deep scan',[IL_BoolToStr(cbDeepScan.Checked,'-','+')]));
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(IL_Format('Found in %d item(s)...',[Length(SearchResults)]));
meSearchResults.Lines.Add('');
If Length(SearchResults) > 0 then
meSearchResults.Lines.Add(IL_StringOfChar('-',60));
For i := Low(SearchResults) to High(SearchResults) do
begin
If i > 0 then
begin
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(IL_StringOfChar('-',60));
end;
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(IL_Format('[%d] Item #%d - %s',
[i,SearchResults[i].ItemIndex + 1,fILManager[SearchResults[i].ItemIndex].TitleStr]));
// item values
If SearchResults[i].ItemValue <> [] then
begin
meSearchResults.Lines.Add('');
Temp := '';
For ISR := Low(TILAdvItemSearchResult) to High(TILAdvItemSearchResult) do
If ISR in SearchResults[i].ItemValue then
begin
If Length(Temp) > 0 then
Temp := IL_Format('%s, %s',[Temp,fILManager.DataProvider.GetAdvancedItemSearchResultString(ISR)])
else
Temp := fILManager.DataProvider.GetAdvancedItemSearchResultString(ISR);
end;
meSearchResults.Lines.Add(' ' + Temp);
end;
// item shop values
If Length(SearchResults[i].Shops) > 0 then
begin
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(IL_Format('Found in shops(%d):',[Length(SearchResults[i].Shops)]));
meSearchResults.Lines.Add('');
For j := Low(SearchResults[i].Shops) to High(SearchResults[i].Shops) do
begin
If j > 0 then
meSearchResults.Lines.Add('');
meSearchResults.Lines.Add(IL_Format(' [%d] Shop #%d - %s',[j,SearchResults[i].Shops[j].ShopIndex,
fILManager[SearchResults[i].ItemIndex][SearchResults[i].Shops[j].ShopIndex].Name]));
If SearchResults[i].Shops[j].ShopValue <> [] then
begin
meSearchResults.Lines.Add('');
Temp := '';
// values
For SSR := Low(TILAdvShopSearchResult) to High(TILAdvShopSearchResult) do
If SSR in SearchResults[i].Shops[j].ShopValue then
begin
If Length(Temp) > 0 then
Temp := IL_Format('%s, %s',[Temp,fILManager.DataProvider.GetAdvancedShopSearchResultString(SSR)])
else
Temp := fILManager.DataProvider.GetAdvancedShopSearchResultString(SSR);
end;
meSearchResults.Lines.Add(' ' + Temp);
end;
end;
end;
end;
finally
meSearchResults.Lines.EndUpdate;
end;
finally
Screen.Cursor := crDefault;
end;
end;
//==============================================================================
procedure TfAdvancedSearchForm.Initialize(ILManager: TILManager);
begin
fILManager := ILManager;
end;
//------------------------------------------------------------------------------
procedure TfAdvancedSearchForm.Finalize;
begin
// nothing to do atm.
end;
//------------------------------------------------------------------------------
procedure TfAdvancedSearchForm.ShowAdvancedSearch;
begin
ShowModal;
end;
//==============================================================================
procedure TfAdvancedSearchForm.FormShow(Sender: TObject);
begin
leTextToFind.SetFocus;
end;
//------------------------------------------------------------------------------
procedure TfAdvancedSearchForm.leTextToFindKeyPress(Sender: TObject; var Key: Char);
begin
If Key = #13{return} then
begin
Key := #0;
btnSearch.OnClick(nil);
end;
end;
//------------------------------------------------------------------------------
procedure TfAdvancedSearchForm.btnSearchClick(Sender: TObject);
var
SearchSettings: TILAdvSearchSettings;
SearchResults: TILAdvSearchResults;
begin
If Length(leTextToFind.Text) > 0 then
begin
// create in-place search settings
SearchSettings.Text := leTextToFind.Text;
SearchSettings.PartialMatch := cbPartialMatch.Checked;
SearchSettings.CaseSensitive := cbCaseSensitive.Checked;
SearchSettings.TextsOnly := cbTextsOnly.Checked;
SearchSettings.EditablesOnly := cbEditablesOnly.Checked;
SearchSettings.SearchCalculated := cbSearchCalculated.Checked;
SearchSettings.IncludeUnits := cbIncludeUnits.Checked;
SearchSettings.SearchShops := cbSearchShops.Checked;
SearchSettings.DeepScan := cbDeepScan.Checked;
// init result array
SetLength(SearchResults,0);
// do the search
Screen.Cursor := crHourGlass;
try
fILManager.FindAll(SearchSettings,SearchResults);
finally
Screen.Cursor := crDefault;
end;
// show the results
meSearchResults.Lines.Clear;
If Length(SearchResults) > 0 then
CreateReport(SearchResults)
else
MessageDlg('No match was found.',mtInformation,[mbOk],0);
end
else MessageDlg('Cannot search for an empty string.',mtInformation,[mbOk],0);
end;
//------------------------------------------------------------------------------
procedure TfAdvancedSearchForm.cbSearchShopsClick(Sender: TObject);
begin
cbDeepScan.Enabled := cbSearchShops.Checked;
end;
//------------------------------------------------------------------------------
procedure TfAdvancedSearchForm.meSearchResultsKeyPress(Sender: TObject;
var Key: Char);
begin
If Key = ^A then
begin
meSearchResults.SelectAll;
Key := #0;
end;
end;
//------------------------------------------------------------------------------
procedure TfAdvancedSearchForm.btnSaveReportClick(Sender: TObject);
begin
If diaReportSave.Execute then
meSearchResults.Lines.SaveToFile(diaReportSave.FileName);
end;
end.