source: cprs/branches/tmg-cprs/CPRS-Chart/TMG_Extra/fPtQuery.pas@ 1681

Last change on this file since 1681 was 809, checked in by Kevin Toppenberg, 14 years ago

Corrected HTML line feed

File size: 7.5 KB
Line 
1unit fPtQuery;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, Buttons, ExtCtrls,ORNet, ORFn,ComCtrls,Trpcb, ORCtrls,
8 uLogic, ImgList
9 ;
10
11type
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
53var
54 frmPtQuery: TfrmPtQuery;
55
56implementation
57
58{$R *.dfm}
59
60uses
61 frmRPCtest, SearchAnimationU, frmSearchResults;
62
63const
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 CallBroker;
109 if RPCBrokerV.Results.Count > 0 then begin
110 RPCResult := RPCBrokerV.Results[0]
111 end else RPCResult := '';
112 if piece(RPCBrokerV.Results[0],'^',1) = '-1' then begin
113 MessageDlg('Error: ' + piece(RPCBrokerV.Results[0],'^',2),mtError,[mbOK],0);
114 Result := false;
115 end;
116 end;
117
118
119 function TfrmPtQuery.LaunchSearch(SearchString : string) : string;
120 var
121 cmd, RPCResult : string;
122 begin
123 RPCBrokerV.remoteprocedure := 'TMG SEARCH CHANNEL';
124 RPCBrokerV.Param[0].Value := '.X';
125 RPCBrokerV.param[0].ptype := list;
126 cmd := 'LAUNCH';
127 cmd := cmd + '^' + SearchFileNumber + '^' + SearchString;
128 RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
129 CallBroker;
130 if RPCBrokerV.Results.Count > 0 then begin
131 RPCResult := RPCBrokerV.Results[0]
132 end else RPCResult := '';
133 if piece(RPCBrokerV.Results[0],'^',1) = '1' then begin
134 Result := piece(RPCBrokerV.Results[0],'^',2);
135 end else begin
136 MessageDlg('Search failed.',mtError,[mbOK],0);
137 Result := '';
138 end;
139 end;
140
141 procedure TfrmPtQuery.RetrieveResults(JobNumber, FldNum : string);
142 //Get job results
143 var
144 tempStr, cmd : string;
145 i : integer;
146 begin
147 RPCBrokerV.remoteprocedure := 'TMG SEARCH CHANNEL';
148 RPCBrokerV.param[0].ptype := list;
149 RPCBrokerV.Param[0].Value := '.X';
150 cmd := 'RESULTS';
151 cmd := cmd + '^' + JobNumber + '^' + FldNum;
152 RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
153 CallBroker;
154
155 frmRPCResults.listRPCResults.Clear;
156 for i := 1 to RPCBrokerV.Results.Count-1 do begin
157 tempStr := RPCBrokerV.Results[i];
158 frmRPCResults.listRPCResults.Items.Add(tempStr);
159 end;
160
161 frmRPCResults.ShowModal;
162 end;
163
164
165 {***************EVENT PROCEDURES*******************}
166 procedure TfrmPtQuery.btnLaunchSearchClick(Sender: TObject);
167 var JobNumber,Count, Fields : string;
168 begin
169 if FLastJobNumber <> '' then begin
170 if ClearLastSearch(FLastJobNumber) = false then exit;
171 end;
172 JobNumber := LaunchSearch(edtSearchString.Text);
173 FLastJobNumber := JobNumber;
174 if JobNumber = '' then exit;
175 if frmTMGServerSearch.ActivateForm(JobNumber) = mrCancel then Exit;
176 Count := frmTMGServerSearch.FoundRecsCount;
177 if (Count = '0') or (Count = '-1') then begin
178 MessageDlg('Sorry, no matches found.' + #13#10 +
179 'This could be due to a search that is too narrow,' + #13#10 +
180 'or a technical limitation of this function.' +#10#13 +
181 'Please try a different search.', mtInformation, [mbOK],0);
182 exit;
183 end;
184 Fields := '.01'; //do something different if 8925...
185 if frmSrchResults.PrepForm(JobNumber, SearchFileName, Count, Fields) = false then begin
186 Exit;
187 end;
188 if frmSrchResults.ShowModal = mrOK then begin
189 FSelectedIEN := frmSrchResults.SelectedIEN;
190 FSelectedName := frmSrchResults.SelectedName;
191 ModalResult := mrOK; //should result in form being closed.
192
193 {MessageDlg('User Selected ' + frmSrchResults.SelectedName
194 + ' (' + frmSrchResults.SelectedIEN + ')',
195 mtInformation,[mbOK],0); }
196 end;
197 end;
198
199 procedure TfrmPtQuery.btnCancelClick(Sender: TObject);
200 begin
201 if FLastJobNumber <> '' then begin
202 if ClearLastSearch(FLastJobNumber) = false then exit;
203 end;
204 ModalResult := mrCancel;
205 //Close;
206 end;
207
208 procedure TfrmPtQuery.TabControlChange(Sender: TObject);
209 var IsSimpleMode : boolean;
210 begin
211 IsSimpleMode := (TabControl.TabIndex <> 1);
212 LogicSet.SimpleMode := IsSimpleMode;
213 lblAdvancedMode.Visible := not IsSimpleMode;
214 end;
215
216 procedure TfrmPtQuery.FormCreate(Sender: TObject);
217 begin
218 LogicSet := TLogicSet.Create(SearchFileNumber,SearchFileName,sbContainer,Self);
219 LogicSet.SearchStringEdit := edtSearchString;
220 //Give LogicSet the column labels, so it can move them when indenting.
221 LogicSet.lblFile := lblFile;
222 LogicSet.lblField := lblField;
223 LogicSet.lblOperator := lblOperator;
224 LogicSet.lblValue := lblValue;
225 GlyphImageList.GetBitmap(0, LogicSet.DelBitmap);
226 GlyphImageList.GetBitmap(1, LogicSet.btnAddSrchField.Glyph);
227 LogicSet.AddRow;
228 TabControlChange(Self);
229 end;
230
231 procedure TfrmPtQuery.FormDestroy(Sender: TObject);
232 //Free all runtime created objects
233 begin
234 LogicSet.Free;
235 end;
236
237end.
238
Note: See TracBrowser for help on using the repository browser.