1 | unit fPtQuery;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, StdCtrls, Buttons, ExtCtrls,ORNet, ORFn,ComCtrls,Trpcb, ORCtrls,
|
---|
8 | uLogic, ImgList
|
---|
9 | ;
|
---|
10 |
|
---|
11 | type
|
---|
12 | TfrmPtQuery = class(TForm)
|
---|
13 | sbContainer: TScrollBox;
|
---|
14 | lblField: TLabel;
|
---|
15 | lblOperator: TLabel;
|
---|
16 | lblValue: TLabel;
|
---|
17 | pnlBottom: TPanel;
|
---|
18 | lblFile: TLabel;
|
---|
19 | edtSearchString: TEdit;
|
---|
20 | pnlTop: TPanel;
|
---|
21 | lblSearchForEntryInFile: TLabel;
|
---|
22 | lblFileName: TLabel;
|
---|
23 | btnCancel: TBitBtn;
|
---|
24 | btnLaunchSearch: TBitBtn;
|
---|
25 | imgSearch: TImage;
|
---|
26 | GlyphImageList: TImageList;
|
---|
27 | TabControl: TTabControl;
|
---|
28 | lblAdvancedMode: TLabel;
|
---|
29 | procedure FormShow(Sender: TObject);
|
---|
30 | procedure btnLaunchSearchClick(Sender: TObject);
|
---|
31 | procedure btnCancelClick(Sender: TObject);
|
---|
32 | procedure TabControlChange(Sender: TObject);
|
---|
33 | procedure FormCreate(Sender: TObject);
|
---|
34 | procedure FormDestroy(Sender: TObject);
|
---|
35 | private
|
---|
36 | { Private declarations }
|
---|
37 | LogicSet : TLogicSet;
|
---|
38 | FLastJobNumber : string;
|
---|
39 | SearchFileName : string;
|
---|
40 | SearchFileNumber: String;
|
---|
41 | FSelectedIEN, FSelectedName : String;
|
---|
42 | procedure RetrieveResults(JobNumber: string; FldNum : string='');
|
---|
43 | function LaunchSearch(SearchString : string) : string;
|
---|
44 | function ClearLastSearch(JobNumber : string) : boolean;
|
---|
45 | public
|
---|
46 | { Public declarations }
|
---|
47 | Function ConnectToRPCBroker : boolean;
|
---|
48 | procedure InitializeForm(FileName : string; FileNumber: integer);
|
---|
49 | property SelectedIEN : String read FSelectedIEN;
|
---|
50 | property SelectedName : String read FSelectedName;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | var
|
---|
54 | frmPtQuery: TfrmPtQuery;
|
---|
55 |
|
---|
56 | implementation
|
---|
57 |
|
---|
58 | {$R *.dfm}
|
---|
59 |
|
---|
60 | uses
|
---|
61 | frmRPCtest, SearchAnimationU, frmSearchResults;
|
---|
62 |
|
---|
63 | const
|
---|
64 | RPC_CONTEXT = 'TMG RPC CONTEXT TEMP';
|
---|
65 |
|
---|
66 | (***********************************************************************)
|
---|
67 | (***********************************************************************)
|
---|
68 |
|
---|
69 | function TfrmPtQuery.ConnectToRPCBroker : boolean;
|
---|
70 | //Returns if login succeeded.
|
---|
71 | //Used for stand-alone application
|
---|
72 | begin
|
---|
73 | Result := true;
|
---|
74 | if not ORNet.ConnectToServer(RPC_CONTEXT) then begin
|
---|
75 | Messagedlg('Login Failed.',mtError,[mbOK],0);
|
---|
76 | Result := false;
|
---|
77 | end;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | procedure TfrmPtQuery.InitializeForm(FileName : string; FileNumber: integer);
|
---|
81 | begin
|
---|
82 | SearchFileName := FileName;
|
---|
83 | SearchFileNumber := IntToStr(FileNumber);
|
---|
84 | lblFileName.Caption := SearchFileName;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TfrmPtQuery.FormShow(Sender: TObject);
|
---|
88 | begin
|
---|
89 | LogicSet.Clear;
|
---|
90 | LogicSet.SetFile(SearchFileNumber, SearchFileName);
|
---|
91 | TabControl.TabIndex := 0;
|
---|
92 | TabControlChange(Self);
|
---|
93 | end;
|
---|
94 |
|
---|
95 | function TfrmPtQuery.ClearLastSearch(JobNumber : string) : boolean;
|
---|
96 | //Returns TRUE if OK, or FALSE if problem.
|
---|
97 | var
|
---|
98 | cmd, RPCResult : string;
|
---|
99 | begin
|
---|
100 | Result := True;
|
---|
101 | RPCBrokerV.remoteprocedure := 'TMG SEARCH CHANNEL';
|
---|
102 | RPCBrokerV.Param[0].Value := '.X';
|
---|
103 | RPCBrokerV.param[0].ptype := list;
|
---|
104 | cmd := 'CLEAR';
|
---|
105 | cmd := cmd + '^' + JobNumber;
|
---|
106 | RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
|
---|
107 | RPCBrokerV.Call;
|
---|
108 | if RPCBrokerV.Results.Count > 0 then begin
|
---|
109 | RPCResult := RPCBrokerV.Results[0]
|
---|
110 | end else RPCResult := '';
|
---|
111 | if piece(RPCBrokerV.Results[0],'^',1) = '-1' then begin
|
---|
112 | MessageDlg('Error: ' + piece(RPCBrokerV.Results[0],'^',2),mtError,[mbOK],0);
|
---|
113 | Result := false;
|
---|
114 | end;
|
---|
115 | end;
|
---|
116 |
|
---|
117 |
|
---|
118 | function TfrmPtQuery.LaunchSearch(SearchString : string) : string;
|
---|
119 | var
|
---|
120 | cmd, RPCResult : string;
|
---|
121 | begin
|
---|
122 | RPCBrokerV.remoteprocedure := 'TMG SEARCH CHANNEL';
|
---|
123 | RPCBrokerV.Param[0].Value := '.X';
|
---|
124 | RPCBrokerV.param[0].ptype := list;
|
---|
125 | cmd := 'LAUNCH';
|
---|
126 | cmd := cmd + '^' + SearchFileNumber + '^' + SearchString;
|
---|
127 | RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
|
---|
128 | RPCBrokerV.Call;
|
---|
129 | if RPCBrokerV.Results.Count > 0 then begin
|
---|
130 | RPCResult := RPCBrokerV.Results[0]
|
---|
131 | end else RPCResult := '';
|
---|
132 | if piece(RPCBrokerV.Results[0],'^',1) = '1' then begin
|
---|
133 | Result := piece(RPCBrokerV.Results[0],'^',2);
|
---|
134 | end else begin
|
---|
135 | MessageDlg('Search failed.',mtError,[mbOK],0);
|
---|
136 | Result := '';
|
---|
137 | end;
|
---|
138 | end;
|
---|
139 |
|
---|
140 | procedure TfrmPtQuery.RetrieveResults(JobNumber, FldNum : string);
|
---|
141 | //Get job results
|
---|
142 | var
|
---|
143 | tempStr, cmd : string;
|
---|
144 | i : integer;
|
---|
145 | begin
|
---|
146 | RPCBrokerV.remoteprocedure := 'TMG SEARCH CHANNEL';
|
---|
147 | RPCBrokerV.param[0].ptype := list;
|
---|
148 | RPCBrokerV.Param[0].Value := '.X';
|
---|
149 | cmd := 'RESULTS';
|
---|
150 | cmd := cmd + '^' + JobNumber + '^' + FldNum;
|
---|
151 | RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
|
---|
152 | RPCBrokerV.Call;
|
---|
153 |
|
---|
154 | frmRPCResults.listRPCResults.Clear;
|
---|
155 | for i := 1 to RPCBrokerV.Results.Count-1 do begin
|
---|
156 | tempStr := RPCBrokerV.Results[i];
|
---|
157 | frmRPCResults.listRPCResults.Items.Add(tempStr);
|
---|
158 | end;
|
---|
159 |
|
---|
160 | frmRPCResults.ShowModal;
|
---|
161 | end;
|
---|
162 |
|
---|
163 |
|
---|
164 | {***************EVENT PROCEDURES*******************}
|
---|
165 | procedure TfrmPtQuery.btnLaunchSearchClick(Sender: TObject);
|
---|
166 | var JobNumber,Count, Fields : string;
|
---|
167 | begin
|
---|
168 | if FLastJobNumber <> '' then begin
|
---|
169 | if ClearLastSearch(FLastJobNumber) = false then exit;
|
---|
170 | end;
|
---|
171 | JobNumber := LaunchSearch(edtSearchString.Text);
|
---|
172 | FLastJobNumber := JobNumber;
|
---|
173 | if JobNumber = '' then exit;
|
---|
174 | if frmTMGServerSearch.ActivateForm(JobNumber) = mrCancel then Exit;
|
---|
175 | Count := frmTMGServerSearch.FoundRecsCount;
|
---|
176 | if (Count = '0') or (Count = '-1') then begin
|
---|
177 | MessageDlg('Sorry, no matches found.' + #13#10 +
|
---|
178 | 'This could be due to a search that is too narrow,' + #13#10 +
|
---|
179 | 'or a technical limitation of this function.' +#10#13 +
|
---|
180 | 'Please try a different search.', mtInformation, [mbOK],0);
|
---|
181 | exit;
|
---|
182 | end;
|
---|
183 | Fields := '.01'; //do something different if 8925...
|
---|
184 | if frmSrchResults.PrepForm(JobNumber, SearchFileName, Count, Fields) = false then begin
|
---|
185 | Exit;
|
---|
186 | end;
|
---|
187 | if frmSrchResults.ShowModal = mrOK then begin
|
---|
188 | FSelectedIEN := frmSrchResults.SelectedIEN;
|
---|
189 | FSelectedName := frmSrchResults.SelectedName;
|
---|
190 | ModalResult := mrOK; //should result in form being closed.
|
---|
191 |
|
---|
192 | {MessageDlg('User Selected ' + frmSrchResults.SelectedName
|
---|
193 | + ' (' + frmSrchResults.SelectedIEN + ')',
|
---|
194 | mtInformation,[mbOK],0); }
|
---|
195 | end;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | procedure TfrmPtQuery.btnCancelClick(Sender: TObject);
|
---|
199 | begin
|
---|
200 | if FLastJobNumber <> '' then begin
|
---|
201 | if ClearLastSearch(FLastJobNumber) = false then exit;
|
---|
202 | end;
|
---|
203 | ModalResult := mrCancel;
|
---|
204 | //Close;
|
---|
205 | end;
|
---|
206 |
|
---|
207 | procedure TfrmPtQuery.TabControlChange(Sender: TObject);
|
---|
208 | var IsSimpleMode : boolean;
|
---|
209 | begin
|
---|
210 | IsSimpleMode := (TabControl.TabIndex <> 1);
|
---|
211 | LogicSet.SimpleMode := IsSimpleMode;
|
---|
212 | lblAdvancedMode.Visible := not IsSimpleMode;
|
---|
213 | end;
|
---|
214 |
|
---|
215 | procedure TfrmPtQuery.FormCreate(Sender: TObject);
|
---|
216 | begin
|
---|
217 | LogicSet := TLogicSet.Create(SearchFileNumber,SearchFileName,sbContainer,Self);
|
---|
218 | LogicSet.SearchStringEdit := edtSearchString;
|
---|
219 | //Give LogicSet the column labels, so it can move them when indenting.
|
---|
220 | LogicSet.lblFile := lblFile;
|
---|
221 | LogicSet.lblField := lblField;
|
---|
222 | LogicSet.lblOperator := lblOperator;
|
---|
223 | LogicSet.lblValue := lblValue;
|
---|
224 | GlyphImageList.GetBitmap(0, LogicSet.DelBitmap);
|
---|
225 | GlyphImageList.GetBitmap(1, LogicSet.btnAddSrchField.Glyph);
|
---|
226 | LogicSet.AddRow;
|
---|
227 | TabControlChange(Self);
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TfrmPtQuery.FormDestroy(Sender: TObject);
|
---|
231 | //Free all runtime created objects
|
---|
232 | begin
|
---|
233 | LogicSet.Free;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | end.
|
---|
237 |
|
---|