Module

fRemCoverSheet

Path

C:\CPRS\CPRS30\fRemCoverSheet.pas

Last Modified

7/15/2014 3:26:38 PM

Units Used in Interface

Name Comments
fBase508Form -
mImgText -

Units Used in Implementation

Name Comments
fRemCoverPreview -
rCore -
rProbs -
rReminders -
rTIU -
uCore -
uPCE -
uReminders -

Classes

Name Comments
TfrmRemCoverSheet -

Procedures

Name Owner Declaration Scope Comments
ActiveControlChanged TfrmRemCoverSheet procedure ActiveControlChanged(Sender: TObject); Private -
btnAddClick TfrmRemCoverSheet procedure btnAddClick(Sender: TObject); Public/Published -
btnApplyClick TfrmRemCoverSheet procedure btnApplyClick(Sender: TObject); Public/Published -
btnLockClick TfrmRemCoverSheet procedure btnLockClick(Sender: TObject); Public/Published -
btnOKClick TfrmRemCoverSheet procedure btnOKClick(Sender: TObject); Public/Published -
btnOKExit TfrmRemCoverSheet procedure btnOKExit(Sender: TObject); Public/Published -
btnRemoveClick TfrmRemCoverSheet procedure btnRemoveClick(Sender: TObject); Public/Published -
btnViewClick TfrmRemCoverSheet procedure btnViewClick(Sender: TObject); Public/Published -
btnViewExit TfrmRemCoverSheet procedure btnViewExit(Sender: TObject); Public/Published -
cbEditLevelClick TfrmRemCoverSheet procedure cbEditLevelClick(Sender: TObject); Public/Published -
cbSystemExit TfrmRemCoverSheet procedure cbSystemExit(Sender: TObject); Public/Published -
cbxClassChange TfrmRemCoverSheet procedure cbxClassChange(Sender: TObject); Public/Published -
cbxClassNeedData TfrmRemCoverSheet procedure cbxClassNeedData(Sender: TObject; const StartFrom: String; Direction, InsertAt: Integer); Public/Published -
cbxDivisionChange TfrmRemCoverSheet procedure cbxDivisionChange(Sender: TObject); Public/Published -
cbxDivisionKeyDown TfrmRemCoverSheet procedure cbxDivisionKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cbxDropDownClose TfrmRemCoverSheet procedure cbxDropDownClose(Sender: TObject); Public/Published -
cbxLocationChange TfrmRemCoverSheet procedure cbxLocationChange(Sender: TObject); Public/Published -
cbxLocationNeedData TfrmRemCoverSheet procedure cbxLocationNeedData(Sender: TObject; const StartFrom: String; Direction, InsertAt: Integer); Public/Published -
cbxServiceChange TfrmRemCoverSheet procedure cbxServiceChange(Sender: TObject); Public/Published -
cbxServiceNeedData TfrmRemCoverSheet procedure cbxServiceNeedData(Sender: TObject; const StartFrom: String; Direction, InsertAt: Integer); Public/Published -
cbxUserChange TfrmRemCoverSheet procedure cbxUserChange(Sender: TObject); Public/Published -
cbxUserLocExit TfrmRemCoverSheet procedure cbxUserLocExit(Sender: TObject); Public/Published -
cbxUserNeedData TfrmRemCoverSheet procedure cbxUserNeedData(Sender: TObject; const StartFrom: String; Direction, InsertAt: Integer); Public/Published -
ChangeStatus TfrmRemCoverSheet procedure ChangeStatus(Code: string); Private -
compAccessCopyLeftCaptionQuery TfrmRemCoverSheet procedure compAccessCopyLeftCaptionQuery(Sender: TObject; var Text: string); Public/Published -
compAccessCopyRightCaptionQuery TfrmRemCoverSheet procedure compAccessCopyRightCaptionQuery(Sender: TObject; var Text: string); Public/Published -
EditCoverSheetReminderList - procedure EditCoverSheetReminderList(AsUser: boolean); Interfaced -
edtSeqChange TfrmRemCoverSheet procedure edtSeqChange(Sender: TObject); Public/Published -
edtSeqKeyPress TfrmRemCoverSheet procedure edtSeqKeyPress(Sender: TObject; var Key: Char); Public/Published -
FormCreate TfrmRemCoverSheet procedure FormCreate(Sender: TObject); Public/Published -
FormDestroy TfrmRemCoverSheet procedure FormDestroy(Sender: TObject); Public/Published -
GetAllChildren - procedure GetAllChildren(PNode: TTreeNode; const ASeq, ASortID: string); Local -
GetUserInfo TfrmRemCoverSheet procedure GetUserInfo(AUser: Int64); Private -
Init TfrmRemCoverSheet procedure Init(AsUser: boolean); Public TfrmRemCoverSheet
lblCACExit TfrmRemCoverSheet procedure lblCACExit(Sender: TObject); Public/Published -
LockButtonUpdate TfrmRemCoverSheet procedure LockButtonUpdate(data, FNAME, hint: string); Private -
lvCoverChange TfrmRemCoverSheet procedure lvCoverChange(Sender: TObject; Item: TListItem; Change: TItemChange); Public/Published -
lvCoverColumnClick TfrmRemCoverSheet procedure lvCoverColumnClick(Sender: TObject; Column: TListColumn); Public/Published -
lvCoverCompare TfrmRemCoverSheet procedure lvCoverCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer); Public/Published -
lvCoverDblClick TfrmRemCoverSheet procedure lvCoverDblClick(Sender: TObject); Public/Published -
lvCoverKeyDown TfrmRemCoverSheet procedure lvCoverKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
lvViewChange TfrmRemCoverSheet procedure lvViewChange(Sender: TObject; Item: TListItem; Change: TItemChange); Public/Published -
lvViewColumnClick TfrmRemCoverSheet procedure lvViewColumnClick(Sender: TObject; Column: TListColumn); Public/Published -
lvViewCompare TfrmRemCoverSheet procedure lvViewCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer); Public/Published -
lvViewExit TfrmRemCoverSheet procedure lvViewExit(Sender: TObject); Public/Published -
lvViewSelectItem TfrmRemCoverSheet procedure lvViewSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); Public/Published -
MarkListAsChanged TfrmRemCoverSheet procedure MarkListAsChanged; Private -
SaveData TfrmRemCoverSheet procedure SaveData(FromApply: boolean); Private -
sbCopyLeftClick TfrmRemCoverSheet procedure sbCopyLeftClick(Sender: TObject); Public/Published -
sbCopyRightClick TfrmRemCoverSheet procedure sbCopyRightClick(Sender: TObject); Public/Published -
sbCopyRightExit TfrmRemCoverSheet procedure sbCopyRightExit(Sender: TObject); Public/Published -
sbDownClick TfrmRemCoverSheet procedure sbDownClick(Sender: TObject); Public/Published -
sbUpClick TfrmRemCoverSheet procedure sbUpClick(Sender: TObject); Public/Published -
SetButtonHints TfrmRemCoverSheet procedure SetButtonHints; Private
This procedure sets the Lock, Add, and Remove button hints based on the
 selected parameter level
SetSeq TfrmRemCoverSheet procedure SetSeq(Item: TListItem; const Value: string); Private -
SetupItem TfrmRemCoverSheet procedure SetupItem(Item: TListItem; const Data: string; Level: TRemCoverDataLevel; IEN: Int64); overload; Private -
SetupItem TfrmRemCoverSheet procedure SetupItem(Item: TListItem; const Data: string); overload; Private -
tvAllChange TfrmRemCoverSheet procedure tvAllChange(Sender: TObject; Node: TTreeNode); Public/Published -
tvAllDblClick TfrmRemCoverSheet procedure tvAllDblClick(Sender: TObject); Public/Published -
tvAllExpanded TfrmRemCoverSheet procedure tvAllExpanded(Sender: TObject; Node: TTreeNode); Public/Published -
tvAllExpanding TfrmRemCoverSheet procedure tvAllExpanding(Sender: TObject; Node: TTreeNode; var AllowExpansion: Boolean); Public/Published -
udSeqChangingEx TfrmRemCoverSheet procedure udSeqChangingEx(Sender: TObject; var AllowChange: Boolean; NewValue: Smallint; Direction: TUpDownDirection); Public/Published -
UpdateButtons TfrmRemCoverSheet procedure UpdateButtons; Private -
UpdateMasterListView TfrmRemCoverSheet procedure UpdateMasterListView; Private -
UpdateView TfrmRemCoverSheet procedure UpdateView; Private -

Functions

Name Owner Declaration Scope Comments
GetCatInfo TfrmRemCoverSheet function GetCatInfo(CatIEN: string): TORStringList; Private -
GetCoverSheetLvlData TfrmRemCoverSheet function GetCoverSheetLvlData(ALevel, AClass: string): TStrings; Private -
GetCurrent TfrmRemCoverSheet function GetCurrent(IEN: Int64; Level: TRemCoverDataLevel; Show: boolean; Add: boolean = FALSE): TORStringList; Private -
GetExternalName TfrmRemCoverSheet function GetExternalName(Level: TRemCoverDataLevel; IEN: Int64): string; Private -
GetIndex TfrmRemCoverSheet function GetIndex(List: TORStringList; Item: TListItem): integer; Private -
GetNameFromList - function GetNameFromList(List: TORStringList; IEN: Int64; FileNum: Double): string; Local -
ListHasData TfrmRemCoverSheet function ListHasData(Seq: string; SubIdx: integer): boolean; Private -
RPad TfrmRemCoverSheet function RPad(Str: String): String; Private -

Constants

Name Declaration Scope Comments
AddLockHint 'Add and Lock a Reminder to prevent it''s removal from a lower' Global -
CVAddCode 'N' Global -
CVCatCode 'C' Global -
CVLockCode 'L' Global -
CVRemCode 'R' Global -
CVRemoveCode 'R' Global -
DataCode array[TRemCoverDataLevel] of string[1] = Global -
DataName array[TRemCoverDataLevel] of string = Global -
DivisionCode 'D' Global -
dlDivision TRemCoverDataLevel Interfaced -
dlLocation TRemCoverDataLevel Interfaced -
dlPackage TRemCoverDataLevel Interfaced -
dlService TRemCoverDataLevel Interfaced -
dlSystem TRemCoverDataLevel Interfaced -
dlUser TRemCoverDataLevel Interfaced -
dlUserClass TRemCoverDataLevel Interfaced -
DummyNode '^@Dummy Node@^' Global -
IdxAdd 5 Global -
IdxIEN 6 Global -
IdxLvl 1 Global -
IdxLvl2 4 Global -
IdxSeq 0 Global -
IdxTIEN 3 Global -
IdxType 2 Global -
InternalName array[TRemCoverDataLevel] of string = Global -
LockHint 'Lock a Reminder to prevent it''s removal from a lower' Global -
sdLvl TSortData Global -
sdOther TSortData Global -
sdRem TSortData Global -
sdSeq TSortData Global -
ServiceCode 'S' Global -
UnlockHint 'Unlock a Reminder, reverting it''s status back to Added' Global -
UserClassCode 'C' Global -


Module Source

1     unit fRemCoverSheet;
2     
3     interface
4     
5     uses
6       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7       ORCtrls, StdCtrls, ExtCtrls, ComCtrls, ImgList, mImgText, Buttons, ORClasses, fBase508Form,
8       VA508AccessibilityManager, VA508ImageListLabeler;
9     
10    type
11      TRemCoverDataLevel = (dlPackage, dlSystem, dlDivision, dlService, dlLocation, dlUserClass, dlUser);
12    
13      TfrmRemCoverSheet = class(TfrmBase508Form)
14        pnlBottom: TORAutoPanel;
15        pnlUser: TPanel;
16        cbxUserLoc: TORComboBox;
17        lblRemLoc: TLabel;
18        pnlMiddle: TPanel;
19        pnlRight: TPanel;
20        pnlCAC: TORAutoPanel;
21        imgMain: TImageList;
22        sbUp: TBitBtn;
23        sbDown: TBitBtn;
24        btnAdd: TBitBtn;
25        btnRemove: TBitBtn;
26        btnLock: TBitBtn;
27        pnlBtns: TPanel;
28        btnOK: TButton;
29        btnCancel: TButton;
30        edtSeq: TCaptionEdit;
31        udSeq: TUpDown;
32        lblSeq: TLabel;
33        btnApply: TButton;
34        cbSystem: TORCheckBox;
35        cbDivision: TORCheckBox;
36        cbService: TORCheckBox;
37        cbxService: TORComboBox;
38        cbxDivision: TORComboBox;
39        cbLocation: TORCheckBox;
40        cbUserClass: TORCheckBox;
41        cbUser: TORCheckBox;
42        cbxUser: TORComboBox;
43        cbxClass: TORComboBox;
44        cbxLocation: TORComboBox;
45        lblEdit: TLabel;
46        pnlInfo: TPanel;
47        pnlTree: TPanel;
48        tvAll: TORTreeView;
49        lblTree: TLabel;
50        pnlCover: TPanel;
51        lvCover: TCaptionListView;
52        pblMoveBtns: TPanel;
53        sbCopyRight: TBitBtn;
54        sbCopyLeft: TBitBtn;
55        splMain: TSplitter;
56        btnView: TButton;
57        lblLegend: TLabel;
58        imgLblRemCoverSheet: TVA508ImageListLabeler;
59        compAccessCopyRight: TVA508ComponentAccessibility;
60        compAccessCopyLeft: TVA508ComponentAccessibility;
61        pnlTopLeft: TPanel;
62        lvView: TCaptionListView;
63        lblView: TLabel;
64        lblCAC: TVA508StaticText;
65        VA508ImageListLabeler1: TVA508ImageListLabeler;
66        lblCategory: TLabel;
67        imgCategory: TImage;
68        lblReminder: TLabel;
69        imgReminder: TImage;
70        lblAdd: TLabel;
71        imgAdd: TImage;
72        lblRemove: TLabel;
73        imgRemove: TImage;
74        lblLock: TLabel;
75        imgLock: TImage;
76        procedure cbxLocationNeedData(Sender: TObject; const StartFrom: String;
77          Direction, InsertAt: Integer);
78        procedure cbxServiceNeedData(Sender: TObject; const StartFrom: String;
79          Direction, InsertAt: Integer);
80        procedure cbxUserNeedData(Sender: TObject; const StartFrom: String;
81          Direction, InsertAt: Integer);
82        procedure cbxClassNeedData(Sender: TObject; const StartFrom: String;
83          Direction, InsertAt: Integer);
84        procedure FormDestroy(Sender: TObject);
85        procedure cbxDivisionChange(Sender: TObject);
86        procedure cbxServiceChange(Sender: TObject);
87        procedure cbxLocationChange(Sender: TObject);
88        procedure cbxClassChange(Sender: TObject);
89        procedure cbxUserChange(Sender: TObject);
90        procedure cbxDropDownClose(Sender: TObject);
91        procedure cbEditLevelClick(Sender: TObject);
92        procedure tvAllExpanding(Sender: TObject; Node: TTreeNode;
93          var AllowExpansion: Boolean);
94        procedure edtSeqChange(Sender: TObject);
95        procedure tvAllExpanded(Sender: TObject; Node: TTreeNode);
96        procedure tvAllChange(Sender: TObject; Node: TTreeNode);
97        procedure lvCoverChange(Sender: TObject; Item: TListItem;
98          Change: TItemChange);
99        procedure btnAddClick(Sender: TObject);
100       procedure btnRemoveClick(Sender: TObject);
101       procedure btnLockClick(Sender: TObject);
102       procedure lvViewColumnClick(Sender: TObject; Column: TListColumn);
103       procedure lvCoverColumnClick(Sender: TObject; Column: TListColumn);
104       procedure lvViewCompare(Sender: TObject; Item1, Item2: TListItem;
105         Data: Integer; var Compare: Integer);
106       procedure lvCoverCompare(Sender: TObject; Item1, Item2: TListItem;
107         Data: Integer; var Compare: Integer);
108       procedure sbUpClick(Sender: TObject);
109       procedure sbDownClick(Sender: TObject);
110       procedure sbCopyRightClick(Sender: TObject);
111       procedure udSeqChangingEx(Sender: TObject; var AllowChange: Boolean;
112         NewValue: Smallint; Direction: TUpDownDirection);
113       procedure sbCopyLeftClick(Sender: TObject);
114       procedure tvAllDblClick(Sender: TObject);
115       procedure btnApplyClick(Sender: TObject);
116       procedure btnOKClick(Sender: TObject);
117       procedure lvCoverDblClick(Sender: TObject);
118       procedure btnViewClick(Sender: TObject);
119       procedure lvCoverKeyDown(Sender: TObject; var Key: Word;
120         Shift: TShiftState);
121       procedure edtSeqKeyPress(Sender: TObject; var Key: Char);
122       procedure cbxDivisionKeyDown(Sender: TObject; var Key: Word;
123         Shift: TShiftState);
124       procedure FormCreate(Sender: TObject);
125       procedure compAccessCopyRightCaptionQuery(Sender: TObject;
126         var Text: string);
127       procedure compAccessCopyLeftCaptionQuery(Sender: TObject; var Text: string);
128       procedure lvViewChange(Sender: TObject; Item: TListItem;
129         Change: TItemChange);
130       procedure lvViewSelectItem(Sender: TObject; Item: TListItem;
131         Selected: Boolean);
132       procedure lvViewExit(Sender: TObject);
133       procedure btnViewExit(Sender: TObject);
134       procedure lblCACExit(Sender: TObject);
135       procedure cbxUserLocExit(Sender: TObject);
136       procedure cbSystemExit(Sender: TObject);
137       procedure sbCopyRightExit(Sender: TObject);
138       procedure btnOKExit(Sender: TObject);
139     private
140       FData: TORStringList;     // DataCode IEN ^ Modified Flag  Object=TStringList
141       FUserInfo: TORStringList; // C^User Class, D^Division
142       FUser: Int64;
143       FUserMode: boolean;
144       FInitialized: boolean;
145       FCurDiv: Integer;
146       FCurSer:Integer;
147       FCurLoc: Integer;
148       FCurClass: Integer;
149       FCurUser: Int64;
150       FDivisions: TORStringList;
151       FServices: TORStringList;
152       FLocations: TORStringList;
153       FClasses: TORStringList;
154       FUsers: TORStringList;
155       FMasterList: TORStringList;
156       FUpdatePending: TORCheckBox;
157       FCatInfo: TORStringList;
158       FEditingLevel: TRemCoverDataLevel;
159       FEditingIEN: Int64;
160       FUpdating: boolean;
161       FTopSortTag: integer;
162       FTopSortUp: boolean;
163       FBottomSortTag: integer;
164       FBottomSortUp: boolean;
165       FDataSaved: boolean;
166       FUpdatingView: boolean;
167       FInternalExpansion: boolean;
168       FSavePause: integer;
169       FSelection: boolean;
170       fOldFocusChanged: TNotifyEvent;
171       procedure ActiveControlChanged(Sender: TObject);
172       procedure SetButtonHints;
173       procedure GetUserInfo(AUser: Int64);
174       function GetCurrent(IEN: Int64; Level: TRemCoverDataLevel; Show: boolean;
175                           Add: boolean = FALSE): TORStringList;
176       procedure UpdateView;
177       procedure SetupItem(Item: TListItem; const Data: string); overload;
178       procedure SetupItem(Item: TListItem; const Data: string;
179                           Level: TRemCoverDataLevel; IEN: Int64); overload;
180       function GetExternalName(Level: TRemCoverDataLevel; IEN: Int64): string;
181       procedure UpdateMasterListView;
182       procedure UpdateButtons;
183       function GetCatInfo(CatIEN: string): TORStringList;
184       procedure MarkListAsChanged;
185       function GetIndex(List: TORStringList; Item: TListItem): integer;
186       procedure ChangeStatus(Code: string);
187       procedure SetSeq(Item: TListItem; const Value: string);
188       function ListHasData(Seq: string; SubIdx: integer): boolean;
189       procedure SaveData(FromApply: boolean);
190       function RPad(Str: String): String;
191       function GetCoverSheetLvlData(ALevel, AClass: string): TStrings;
192       procedure LockButtonUpdate(data, FNAME, hint: string);
193     public
194        procedure Init(AsUser: boolean);
195     end;
196   
197   procedure EditCoverSheetReminderList(AsUser: boolean);
198   
199   implementation
200   
201   uses rCore, uCore, uPCE, rProbs, rTIU, ORFn, rReminders, uReminders,
202     fRemCoverPreview, VAUtils, VA508AccessibilityRouter;
203   
204   {$R *.DFM}
205   {$R sremcvr}
206   
207   const
208     DataCode: array[TRemCoverDataLevel] of string[1] =
209         { dlPackage   } ('P',
210         { dlSystem    }  'S',
211         { dlDivision  }  'D',
212         { dlService   }  'R',
213         { dlLocation  }  'L',
214         { dlUserClass }  'C',
215         { dlUser      }  'U');
216   
217     DataName: array[TRemCoverDataLevel] of string =
218         { dlPackage   } ('Package',
219         { dlSystem    }  'System',
220         { dlDivision  }  'Division',
221         { dlService   }  'Service',
222         { dlLocation  }  'Location',
223         { dlUserClass }  'User Class',
224         { dlUser      }  'User');
225   
226     InternalName: array[TRemCoverDataLevel] of string =
227         { dlPackage   } ('PKG',
228         { dlSystem    }  'SYS',
229         { dlDivision  }  'DIV',
230         { dlService   }  'SRV',
231         { dlLocation  }  'LOC',
232         { dlUserClass }  'CLASS',
233         { dlUser      }  'USR');
234   
235   
236     UserClassCode = 'C';
237     DivisionCode = 'D';
238     ServiceCode = 'S';
239   
240     CVLockCode   = 'L';
241     CVAddCode    = 'N';
242     CVRemoveCode = 'R';
243     CVCatCode    = 'C';
244     CVRemCode    = 'R';
245   
246     DummyNode = '^@Dummy Node@^';
247     IdxSeq  = 0;
248     IdxLvl  = 1;
249     IdxType = 2;
250     IdxTIEN = 3;
251     IdxLvl2 = 4;
252     IdxAdd  = 5;
253     IdxIEN  = 6;
254   
255     UnlockHint = 'Unlock a Reminder, reverting it''s status back to Added';
256     LockHint = 'Lock a Reminder to prevent it''s removal from a lower'
257           + CRLF + 'level Coversheet display.  For example, if you lock'
258           + CRLF + 'a Reminder at the Service level, then that Reminder'
259           + CRLF + 'can not be removed from the coversheet display at'
260           + CRLF + 'the Location, User Class, or User levels.';
261     AddLockHint = 'Add and Lock a Reminder to prevent it''s removal from a lower'
262           + CRLF + 'level Coversheet display.  For example, if you lock'
263           + CRLF + 'a Reminder at the Service level, then that Reminder'
264           + CRLF + 'can not be removed from the coversheet display at'
265           + CRLF + 'the Location, User Class, or User levels.';
266   
267   procedure EditCoverSheetReminderList(AsUser: boolean);
268   var
269     frmRemCoverSheet: TfrmRemCoverSheet;
270   
271   begin
272     frmRemCoverSheet := TfrmRemCoverSheet.Create(Application);
273     try
274       frmRemCoverSheet.Init(AsUser);
275       frmRemCoverSheet.ShowModal;
276       if frmRemCoverSheet.FDataSaved then
277         ResetReminderLoad;
278     finally
279       frmRemCoverSheet.Free;
280     end;
281   end;
282   
283   { TfrmRemCoverSheet }
284   
285   procedure TfrmRemCoverSheet.Init(AsUser: boolean);
286   const
287     RemClsCode = ' NVL';
288     RemClsText:array[1..4] of string = ('','National','VISN','Local');
289   
290   var
291     LocCombo: TORComboBox;
292     i, idx: integer;
293     tmp, tmp2, tmp3: string;
294     Node: TORTreeNode;
295   
296   begin
297     FTopSortTag := 3;
298     FTopSortUp  := TRUE;
299     FBottomSortTag := 2;
300     FBottomSortUp := TRUE;
301     FEditingLevel := dlPackage;
302   
303     ResizeAnchoredFormToFont(self);
304     pnlBtns.Top := pnlBottom.Top + pnlBottom.Height;
305   
306     FCatInfo := TORStringList.Create;
307     FData := TORStringList.Create;
308     FUserInfo := TORStringList.Create;
309     FDivisions := TORStringList.Create;
310     FServices := TORStringList.Create;
311     FLocations := TORStringList.Create;
312     FClasses := TORStringList.Create;
313     FUsers := TORStringList.Create;
314     FMasterList := TORStringList.Create;
315     //FMasterList.Assign(GetAllRemindersAndCategories);
316     FastAssign(GetAllRemindersAndCategories, FMasterList);
317     for i := 0 to FMasterList.Count-1 do
318     begin
319       tmp := FMasterList[i];
320       tmp2 := piece(tmp,U,4);
321       if tmp2 = piece(tmp,U,3) then
322         tmp2 := '';
323       tmp3 := piece(tmp,U,5);
324       if tmp3 = '' then tmp3 := ' ';
325       idx := pos(tmp3,RemClsCode);
326       if idx > 0 then
327         tmp3 := RemClsText[idx]
328       else
329         tmp3 := '';
330       if tmp3 <> '' then
331       begin
332         if tmp2 <> '' then
333           tmp2 := tmp2 + ' - ';
334         tmp2 := tmp2 + tmp3;
335       end;
336       if tmp2 <> '' then
337         tmp2 := ' (' + tmp2 + ')';
338       tmp := Piece(tmp,U,1) + Pieces(tmp,U,2,3) + tmp2 + U + tmp2;
339       FMasterList[i] := tmp;
340     end;
341   
342     FUserMode := AsUser;
343     FCurUser := User.DUZ;
344     GetUserInfo(User.DUZ);
345     FCurLoc := Encounter.Location;
346     idx := FUserInfo.IndexOfPiece(DivisionCode);
347     if idx >= 0 then
348       FCurDiv := StrToIntDef(Piece(FUserInfo[idx],U,2),0)
349     else
350       FCurDiv := 0;
351     idx := FUserInfo.IndexOfPiece(ServiceCode);
352     if idx >= 0 then
353       FCurSer := StrToIntDef(Piece(FUserInfo[idx],U,2),0)
354     else
355       FCurSer := User.Service;
356     cbxUser.InitLongList(User.Name);
357     cbxUser.SelectByIEN(FCurUser);
358     GetPCECodes(FDivisions, TAG_HISTLOC);
359     FDivisions.Delete(0);
360     FCurClass := 0;
361     if AsUser then
362     begin
363       pnlCAC.Visible := FALSE;
364       LocCombo := cbxUserLoc;
365       btnLock.Visible := FALSE;
366     end
367     else
368     begin
369       pnlUser.Visible := FALSE;
370       LocCombo := cbxLocation;
371       //cbxDivision.Items.Assign(FDivisions);
372       FastAssign(Fdivisions, cbxDivision.Items);
373       cbxDivision.SelectByIEN(FCurDiv);
374       cbxService.InitLongList(GetExternalName(dlService, FCurSer));
375       cbxService.SelectByIEN(FCurSer);
376       cbxClass.InitLongList('');
377       if FCurClass <> 0 then
378         cbxClass.SelectByIEN(FCurClass);
379     end;
380     LocCombo.InitLongList(Encounter.LocationName);
381     LocCombo.SelectByIEN(FCurLoc);
382     if AsUser then
383       cbUser.Checked := TRUE;
384   
385     tvAll.Items.BeginUpdate;
386     try
387       for i := 0 to FMasterList.Count-1 do
388       begin
389         Node := TORTreeNode(tvAll.Items.Add(nil,''));
390         Node.StringData := FMasterList[i];
391         if copy(FMasterList[i],1,1) = CVCatCode then
392         begin
393           idx := 1;
394           tvAll.Items.AddChild(Node, DummyNode);
395         end
396         else
397           idx := 0;
398         Node.ImageIndex := idx;
399         Node.SelectedIndex := idx;
400       end;
401     finally
402       tvAll.Items.EndUpdate;
403     end;
404     
405     FInitialized := TRUE;
406     UpdateView;
407     UpdateButtons;
408   end;
409   
410   procedure TfrmRemCoverSheet.lblCACExit(Sender: TObject);
411   begin
412     inherited;
413     //TDP - CQ#19733 Corrected tabbing issues
414     if TabIsPressed() then
415     begin
416       if pnlUser.Visible then cbxUserLoc.SetFocus
417       else cbSystem.SetFocus;
418     end;
419     if ShiftTabIsPressed() then btnView.SetFocus;
420   end;
421   
422   procedure TfrmRemCoverSheet.cbxLocationNeedData(Sender: TObject;
423     const StartFrom: String; Direction, InsertAt: Integer);
424   begin
425     TORComboBox(Sender).ForDataUse(SubSetOfLocations(StartFrom, Direction));
426   end;
427   
428   procedure TfrmRemCoverSheet.cbxServiceNeedData(Sender: TObject;
429     const StartFrom: String; Direction, InsertAt: Integer);
430   begin
431     cbxService.ForDataUse(ServiceSearch(StartFrom, Direction, TRUE));
432   end;
433   
434   procedure TfrmRemCoverSheet.cbxUserNeedData(Sender: TObject;
435     const StartFrom: String; Direction, InsertAt: Integer);
436   begin
437     cbxUser.ForDataUse(SubSetOfPersons(StartFrom, Direction));
438   end;
439   
440   procedure TfrmRemCoverSheet.cbxClassNeedData(Sender: TObject;
441     const StartFrom: String; Direction, InsertAt: Integer);
442   begin
443     cbxClass.ForDataUse(SubSetOfUserClasses(StartFrom, Direction));
444   end;
445   
446   procedure TfrmRemCoverSheet.FormDestroy(Sender: TObject);
447   begin
448     Screen.OnActiveControlChange := fOldFocusChanged;
449     FMasterList.Free;
450     FUsers.Free;
451     FClasses.Free;
452     FLocations.Free;
453     FServices.Free;
454     FDivisions.Free;
455     FUserInfo.Free;
456     FData.KillObjects;
457     FData.Free;
458     FCatInfo.KillObjects;
459     FCatInfo.Free;
460     Application.HintHidePause := FSavePause  //Reset Hint pause to original setting
461   end;
462   
463   procedure TfrmRemCoverSheet.GetUserInfo(AUser: Int64);
464   begin
465     if FUser <> AUser then
466     begin
467       FUser := AUser;
468       //FUserInfo.Assign(UserDivClassInfo(FUser));
469       FastAssign(UserDivClassInfo(FUser), FUserInfo);
470     end;
471   end;
472   
473   function TfrmRemCoverSheet.GetCurrent(IEN: Int64; Level: TRemCoverDataLevel;
474                              Show: boolean; Add: boolean = FALSE): TORStringList;
475   var
476     lvl, cls, sIEN: string;
477     tmpSL: TORStringList;
478     i, idx: integer;
479   
480   begin
481     idx := FData.IndexOfPiece(DataCode[Level] + IntToStr(IEN));
482     if idx < 0 then
483     begin
484       if (IEN = 0) and (not (Level in [dlPackage, dlSystem])) then
485       begin
486         Result := nil;
487         exit;
488       end;
489       cls := '';
490       sIEN := IntToStr(IEN);
491       lvl := InternalName[Level];
492       case Level of
493         dlDivision, dlService, dlLocation, dlUser:
494           lvl := lvl + '.`' + sIEN;
495         dlUserClass:
496           cls := sIEN;
497       end;
498       if (lvl <> '') then
499       begin
500         tmpSL := TORStringList.Create;
501         try
502           //tmpSL.Assign(GetCoverSheetLvlData(lvl, cls));
503           FastAssign(GetCoverSheetLvlData(lvl, cls),  tmpSL);
504           if (not Add) and (tmpSL.Count = 0) then
505             FreeAndNil(tmpSL);
506           idx := FData.AddObject(DataCode[Level] + IntToStr(IEN), tmpSL);
507         except
508           tmpSL.Free;
509           raise;
510         end;
511       end;
512     end;
513     if idx >= 0 then
514     begin
515       tmpSL := TORStringList(FData.Objects[idx]);
516       if Add and (not assigned(tmpSL)) then
517       begin
518         tmpSL := TORStringList.Create;
519         FData.Objects[idx] := tmpSL;
520       end;
521     end
522     else
523       tmpSL := nil;
524     if Show and assigned(tmpSL) then
525     begin
526       for i := 0 to tmpSL.Count-1 do
527         SetupItem(lvView.Items.Add, tmpSL[i], Level, IEN);
528     end;
529     Result := tmpSL;
530   end;
531   
532   procedure TfrmRemCoverSheet.UpdateView;
533   var
534     idx: integer;
535   
536   begin
537     if FInitialized and (not FUpdatingView) then
538     begin
539       lvView.Items.BeginUpdate;
540       try
541         lvView.Items.Clear;
542         GetCurrent(0, dlPackage, TRUE);
543         GetCurrent(0, dlSystem, TRUE);
544         GetCurrent(FCurDiv, dlDivision, TRUE);
545         GetCurrent(FCurSer, dlService, TRUE);
546         GetCurrent(FCurLoc, dlLocation, TRUE);
547         if FCurClass > 0 then
548           GetCurrent(FCurClass, dlUserClass, TRUE)
549         else
550         begin
551           idx := -1;
552           repeat
553             idx := FUserInfo.IndexOfPiece(UserClassCode,U,1,idx);
554             if idx >= 0 then
555               GetCurrent(StrToIntDef(Piece(FUserInfo[idx],U,2),0), dlUserClass, TRUE)
556           until(idx < 0);
557         end;
558         GetCurrent(FCurUser, dlUser, TRUE);
559       finally
560         lvView.Items.EndUpdate;
561       end;
562     end;
563   end;
564   
565   procedure TfrmRemCoverSheet.compAccessCopyLeftCaptionQuery(Sender: TObject;
566     var Text: string);
567   begin
568     Text := 'Remove Reminder from ' + DataName[FEditingLevel] + ' Level Reminders List';
569   end;
570   
571   procedure TfrmRemCoverSheet.compAccessCopyRightCaptionQuery(
572     Sender: TObject; var Text: string);
573   begin
574     Text := 'Copy Reminder into ' + DataName[FEditingLevel] + ' Level Reminders List';
575   end;
576   
577   procedure TfrmRemCoverSheet.SetupItem(Item: TListItem; const Data: string);
578   var
579     AddCode, RemCode, rIEN, Seq: string;
580   
581   begin
582     Seq := Piece(Data,U,1);
583     rIEN := Piece(Data,U,2);
584     Item.Caption := Piece(Data,U,3);
585     AddCode := copy(rIEN,1,1);
586     RemCode := copy(rIEN,2,1);
587     delete(rIEN,1,1);
588     if AddCode = CVLockCode then
589       Item.StateIndex := 5
590     else
591     if AddCode = CVRemoveCode then
592       Item.StateIndex := 4
593     else
594     if AddCode = CVAddCode then
595       Item.StateIndex := 3;
596     if RemCode = CVCatCode then
597       Item.ImageIndex := 1
598     else
599     if RemCode = CVRemCode then
600       Item.ImageIndex := 0
601     else
602       Item.ImageIndex := -1;
603     Item.SubItems.Clear;
604     Item.SubItems.Add(Seq);     // IdxSeq  = 0
605     Item.SubItems.Add('');      // IdxLvl  = 1
606     Item.SubItems.Add('');      // IdxType = 2
607     Item.SubItems.Add('');      // IdxTIEN = 3
608     Item.SubItems.Add('');      // IdxLvl2 = 4
609     Item.SubItems.Add(AddCode); // IdxAdd  = 5
610     Item.SubItems.Add(rIEN);    // IdxIEN  = 6
611   end;
612   
613   procedure TfrmRemCoverSheet.SetupItem(Item: TListItem; const Data: string;
614                            Level: TRemCoverDataLevel; IEN: Int64);
615   begin
616     SetupItem(Item, Data);
617     Item.SubItems[IdxLvl]  := DataName[Level];
618     Item.SubItems[IdxType] := GetExternalName(Level, IEN);
619     Item.SubItems[IdxTIEN] := IntToStr(IEN);
620     Item.SubItems[IdxLvl2] := IntToStr(ord(Level));
621   end;
622   
623   function TfrmRemCoverSheet.GetExternalName(Level: TRemCoverDataLevel; IEN: Int64): string;
624   
625     function GetNameFromList(List: TORStringList; IEN: Int64; FileNum: Double): string;
626     var
627       idx: integer;
628   
629     begin
630       idx := List.IndexOfPiece(IntToStr(IEN));
631       if idx < 0 then
632         idx := List.Add(IntToStr(IEN) + U + ExternalName(IEN, FileNum));
633         Result := piece(List[idx],U,2);
634     end;
635   
636   begin
637     case Level of
638       dlDivision:  Result := GetNameFromList(FDivisions, IEN, 4);
639       dlService:   Result := GetNameFromList(FServices, IEN, 49);
640       dlLocation:  Result := GetNameFromList(FLocations, IEN, 44);
641       dlUserClass: Result := GetNameFromList(FClasses, IEN, 8930);
642       dlUser:      Result := GetNameFromList(FUsers, IEN, 200);
643       else         Result := '';
644     end;
645   end;
646   
647   procedure TfrmRemCoverSheet.cbxDivisionChange(Sender: TObject);
648   begin
649     FCurDiv := cbxDivision.ItemIEN;
650     If FCurDiv < 1  then   //No value in Division combobox
651     begin
652       sbCopyLeft.Enabled := false;
653       sbCopyRight.Enabled := false;
654       FSelection := false;
655     end
656     else
657       FSelection := true;
658     FUpdatePending := cbDivision;
659     if not cbxDivision.DroppedDown then
660       cbxDropDownClose(nil);
661   end;
662   
663   procedure TfrmRemCoverSheet.cbxServiceChange(Sender: TObject);
664   begin
665     FCurSer := cbxService.ItemIEN;
666     If FCurSer < 1  then   //No value in Service combobox
667     begin
668       sbCopyLeft.Enabled := false;
669       sbCopyRight.Enabled := false;
670       FSelection := false;
671     end
672     else
673       FSelection := true;
674     FUpdatePending := cbService;
675     if not cbxService.DroppedDown then
676       cbxDropDownClose(nil);
677   end;
678   
679   procedure TfrmRemCoverSheet.cbxLocationChange(Sender: TObject);
680   begin
681     FCurLoc := TORComboBox(Sender).ItemIEN;
682     If FCurLoc < 1  then   //No value in Location combobox
683     begin
684       sbCopyLeft.Enabled := false;
685       sbCopyRight.Enabled := false;
686       FSelection := false;
687     end
688     else
689       FSelection := true;
690     FUpdatePending := cbLocation;
691     if not TORComboBox(Sender).DroppedDown then
692       cbxDropDownClose(nil);
693   end;
694   
695   procedure TfrmRemCoverSheet.cbxClassChange(Sender: TObject);
696   begin
697     FCurClass := cbxClass.ItemIEN;
698     If FCurClass < 1  then   //No value in User Class combobox
699     begin
700       sbCopyLeft.Enabled := false;
701       sbCopyRight.Enabled := false;
702       FSelection := false;
703     end
704     else
705       FSelection := true;
706     FUpdatePending := cbUserClass;
707     if not cbxClass.DroppedDown then
708       cbxDropDownClose(nil);
709   end;
710   
711   procedure TfrmRemCoverSheet.cbxUserChange(Sender: TObject);
712   var
713     NewVal, idx: integer;
714   
715   begin
716     FCurUser := cbxUser.ItemIEN;
717     If FCurUser < 1  then   //No value in User combobox
718     begin
719       sbCopyLeft.Enabled := false;
720       sbCopyRight.Enabled := false;
721       FSelection := false;
722     end
723     else
724       FSelection := true;
725     GetUserInfo(FCurUser);
726     idx := FUserInfo.IndexOfPiece(DivisionCode);
727     if idx >= 0 then
728     begin
729       NewVal := StrToIntDef(Piece(FUserInfo[idx],U,2),0);
730       if NewVal <> FCurDiv then
731       begin
732         FCurDiv := NewVal;
733         cbxDivision.InitLongList(GetExternalName(dlDivision, NewVal));
734         cbxDivision.SelectByIEN(NewVal);
735       end;
736     end;
737     idx := FUserInfo.IndexOfPiece(ServiceCode);
738     if idx >= 0 then
739     begin
740       NewVal := StrToIntDef(Piece(FUserInfo[idx],U,2),0);
741       if NewVal <> FCurSer then
742       begin
743         FCurSer := NewVal;
744         cbxService.InitLongList(GetExternalName(dlService, NewVal));
745         cbxService.SelectByIEN(NewVal);
746       end;
747     end;
748     FCurClass := 0;
749     cbxClass.ItemIndex := -1;
750     FUpdatePending := cbUser;
751     if not cbxUser.DroppedDown then
752       cbxDropDownClose(nil);
753   end;
754   
755   procedure TfrmRemCoverSheet.cbxUserLocExit(Sender: TObject);
756   begin
757     inherited;
758     //TDP - CQ#19733 Corrected tabbing issues
759     if ShiftTabIsPressed() then
760     begin
761       if ScreenReaderSystemActive then lblCAC.SetFocus
762       else btnView.SetFocus;
763     end;
764   end;
765   
766   procedure TfrmRemCoverSheet.cbxDropDownClose(Sender: TObject);
767   begin
768     if assigned(FUpdatePending) then
769     begin
770       UpdateView;
771       if FInitialized and (not FUserMode) then
772       begin
773         if FUpdatePending.Checked then
774           cbEditLevelClick(FUpdatePending)
775         else
776           FUpdatePending.Checked := TRUE;
777       end;
778       FUpdatePending := nil;
779     end;
780   end;
781   
782   procedure TfrmRemCoverSheet.cbEditLevelClick(Sender: TObject);
783   var
784     cb: TORCheckBox;
785     tmp: string;
786   
787   begin
788     cb := TORCheckBox(Sender);
789     if cb.Checked then
790     begin
791       FEditingLevel := TRemCoverDataLevel(cb.Tag);
792       if FEditingLevel <> dlUserClass then
793       begin
794         FCurClass := 0;
795         cbxClass.ItemIndex := -1;
796       end;
797       case FEditingLevel of
798         dlDivision:  FEditingIEN := FCurDiv;
799         dlService:   FEditingIEN := FCurSer;
800         dlLocation:  FEditingIEN := FCurLoc;
801         dlUserClass: FEditingIEN := FCurClass;
802         dlUser:      FEditingIEN := FCurUser;
803         else         FEditingIEN := 0;
804       end;
805       if FEditingIEN = 0 then
806       begin
807         tmp := ' ';
808         IF FEditingLevel = dlSystem then
809           FSelection := true
810         else
811         begin
812           sbCopyLeft.Enabled := false;
813           sbCopyRight.Enabled := false;
814           FSelection := false;
815         end;
816       end
817       else
818       begin
819         tmp := ': ';
820         FSelection := true;
821       end;
822       lblEdit.Caption := '  Editing Cover Sheet Reminders for ' + DataName[FEditingLevel] +
823                           tmp + GetExternalName(FEditingLevel, FEditingIEN);
824       lvCover.Columns[0].Caption := DataName[FEditingLevel] + ' Level Reminders';
825   
826       SetButtonHints;   {Setup hints for Lock, Add, Remove buttons based on
827                          Parameter Level}
828       UpdateView;
829       UpdateMasterListView;
830     end
831     else
832     begin
833       FSelection := false;
834       sbCopyLeft.Enabled := false;
835       sbCopyRight.Enabled := false;
836       FEditingLevel := dlPackage;
837       FEditingIEN := 0;
838       lblEdit.Caption := '';
839       lvCover.Items.BeginUpdate;
840       try
841         lvCover.Items.Clear;
842       finally
843         lvCover.Items.EndUpdate;
844       end;
845     end;
846   
847   end;
848   
849   procedure TfrmRemCoverSheet.cbSystemExit(Sender: TObject);
850   begin
851     inherited;
852     //TDP - CQ#19733 Corrected tabbing issues
853     if ShiftTabIsPressed() then
854     begin
855       if ScreenReaderSystemActive then lblCAC.SetFocus
856       else btnView.SetFocus;
857     end;
858   end;
859   
860   procedure TfrmRemCoverSheet.UpdateMasterListView;
861   var
862     i: integer;
863     tmpSL: TStringList;
864     itm: TListItem;
865   
866   begin
867     lvCover.Items.BeginUpdate;
868     try
869       lvCover.Items.Clear;
870       if FEditingLevel <> dlPackage then
871       begin
872         tmpSL := GetCurrent(FEditingIEN, FEditingLevel, FALSE);
873         if assigned(tmpSL) then
874         begin
875           for i := 0 to tmpSL.Count-1 do
876           begin
877             itm := lvCover.Items.Add;
878             SetupItem(itm, tmpSL[i]);
879           end;
880         end;
881       end;
882     finally
883       lvCover.Items.EndUpdate;
884     end;
885     UpdateButtons;
886   end;
887   
888   procedure TfrmRemCoverSheet.UpdateButtons;
889   var
890     FocusOK, ok: boolean;
891     i, idx: integer;
892     Current, Lowest, Highest: integer;
893     tmp: string;
894     tmpSL: TORstringlist;
895     doDownButton, doUpButton: boolean;
896   
897   begin
898     lvCover.Enabled := (FEditingLevel <> dlPackage);
899     ok := assigned(tvAll.Selected) and (FEditingLevel <> dlPackage) and (FSelection);
900     sbCopyRight.Enabled := ok;
901   
902     ok := assigned(lvCover.Selected) and (FEditingLevel <> dlPackage) and (FSelection);
903     sbCopyLeft.Enabled := ok;
904   
905     ok := assigned(lvCover.Selected);
906     lblSeq.Enabled := ok;
907     edtSeq.Enabled := ok;
908   
909     FUpdating := TRUE;
910     try
911       udSeq.Enabled := ok;
912       if ok then
913         udSeq.Position := StrToIntDef(lvCover.Selected.SubItems[IdxSeq],1)
914       else
915         udSeq.Position := 1;
916     finally
917       FUpdating := FALSE;
918     end;
919   
920     FocusOK := lvCover.Focused or sbUp.Focused or sbDown.Focused or edtSeq.Focused or
921                udSeq.Focused or btnAdd.Focused or btnRemove.Focused or btnLock.Focused or
922                btnOK.Focused; // add btnOK so you can shift-tab backwards into list
923     btnAdd.Enabled := ok and FocusOK;
924     btnRemove.Enabled := ok and (FEditingLevel <> dlSystem) and FocusOK;
925     btnLock.Enabled := ok and (FEditingLevel <> dlUser) and FocusOK;
926     if ok then
927     begin
928       tmpSL := GetCurrent(FEditingIEN, FEditingLevel, FALSE);
929       if assigned(tmpSL) then
930       begin
931         Idx := GetIndex(tmpSL, lvCover.Selected);
932         if Idx >= 0 then
933         begin
934           tmp := tmpSL[idx];
935           tmp := piece(tmp,u,2);
936           tmp := copy(tmp,1,1);
937           if tmp = 'L' then
938           begin
939             LockButtonUpdate('Unlock', 'BMP_UNLOCK', UnlockHint);
940           end;
941           if tmp = 'N' then
942           begin
943             LockButtonUpdate('Lock', 'BMP_LOCK', LockHint);
944           end;
945           if tmp = 'R' then
946           begin
947             LockButtonUpdate('Add && Lock', 'BMP_LOCK', AddLockHint);
948           end;
949         end;
950       end;
951       ok :=(lvCover.Items.Count > 1);
952     end;
953     Lowest := 99999;
954     Highest := -1;
955     if ok then
956     begin
957       for i := 0 to lvCover.Items.Count-1 do
958       begin
959         Current := StrToIntDef(lvCover.Items[i].SubItems[IdxSeq], 0);
960         if Lowest > Current then
961           Lowest := Current;
962         if Highest < Current then
963           Highest := Current;
964       end;
965       Current := StrToIntDef(lvCover.Selected.SubItems[IdxSeq], 0);
966     end
967     else
968       Current := 0;
969     doDownButton := (sbUp.Focused and (Current = Lowest));
970     doUpButton := (sbDown.Focused and (Current = Highest));
971     sbUp.Enabled := ok and (Current > Lowest);
972     sbDown.Enabled := ok and (Current < Highest);
973     if doDownButton and sbDown.enabled then sbDown.SetFocus;
974     if doUpButton and sbUp.enabled then sbUp.SetFocus;
975   end;
976   
977   procedure TfrmRemCoverSheet.tvAllExpanding(Sender: TObject;
978     Node: TTreeNode; var AllowExpansion: Boolean);
979   var
980     List: TORStringList;
981     i, idx: integer;
982     CNode: TORTreeNode;
983   
984   begin
985     if Node.GetFirstChild.Text = DummyNode then
986     begin
987       Node.DeleteChildren;
988       List := GetCatInfo(copy(piece(TORTreeNode(Node).StringData,U,1),2,99));
989       if assigned(List) then
990       begin
991         for i := 0 to List.Count-1 do
992         begin
993           CNode := TORTreeNode(tvAll.Items.AddChild(Node,''));
994           CNode.StringData := List[i];
995           if copy(List[i],1,1) = CVCatCode then
996           begin
997             idx := 1;
998             tvAll.Items.AddChild(CNode, DummyNode);
999           end
1000          else
1001            idx := 0;
1002          CNode.ImageIndex := idx;
1003          CNode.SelectedIndex := idx;
1004        end;
1005      end;
1006    end;
1007    if FInternalExpansion then
1008      AllowExpansion := FALSE
1009    else
1010      AllowExpansion := Node.HasChildren;
1011  end;
1012  
1013  function TfrmRemCoverSheet.GetCatInfo(CatIEN: string): TORStringList;
1014  var
1015    i, j, idx: integer;
1016    tmp: string;
1017    tmpSL: TStrings;
1018  
1019  begin
1020    idx := FCatInfo.IndexOf(CatIEN);
1021    if idx < 0 then
1022    begin
1023      Result := TORStringList.Create;
1024      try
1025        tmpSL := GetCategoryItems(StrToIntDef(CatIEN,0));
1026        for i := 0 to tmpSL.Count-1 do
1027        begin
1028          tmp := copy(tmpSL[i],1,1);
1029          if tmp = CVCatCode then
1030            idx := 3
1031          else
1032            idx := 4;
1033          tmp := tmp + Piece(tmpSL[i],U,2) + U + Piece(tmpSL[i],U,idx);
1034          j := FMasterList.IndexOfPiece(piece(tmp,U,1));
1035          if j >= 0 then
1036            tmp := tmp + piece(FMasterList[j],U,3);
1037          Result.Add(tmp);
1038        end;
1039        FCatInfo.AddObject(CatIEN, Result);
1040      except
1041        Result.Free;
1042        raise;
1043      end;
1044    end
1045    else
1046      Result := TORStringList(FCatInfo.Objects[idx]);
1047  end;
1048  
1049  procedure TfrmRemCoverSheet.MarkListAsChanged;
1050  var
1051    tmp: string;
1052    idx: integer;
1053  
1054  begin
1055    idx := FData.IndexOfPiece(DataCode[FEditingLevel] + IntToStr(FEditingIEN));
1056    if idx >= 0 then
1057    begin
1058      tmp := FData[idx];
1059      SetPiece(Tmp,U,2,BoolChar[TRUE]);
1060      FData[idx] := tmp;
1061      btnApply.Enabled := TRUE;
1062      UpdateView;
1063    end;
1064  end;
1065  
1066  procedure TfrmRemCoverSheet.edtSeqChange(Sender: TObject);
1067  begin
1068    if FUpdating or (not FInitialized) then exit;
1069    if FBottomSortTag <> 2 then
1070    begin
1071      FBottomSortTag := 2;
1072      lvCover.CustomSort(nil, 0);
1073    end;
1074    SetSeq(lvCover.Selected, IntToStr(udSeq.Position));
1075    lvCover.CustomSort(nil, 0);
1076    UpdateButtons;
1077  end;
1078  
1079  procedure TfrmRemCoverSheet.tvAllExpanded(Sender: TObject;
1080    Node: TTreeNode);
1081  var
1082    idx: integer;
1083  
1084  begin
1085    if Node.Expanded then
1086      idx := 2
1087    else
1088      idx := 1;
1089    Node.ImageIndex := idx;
1090    Node.SelectedIndex := idx;
1091  end;
1092  
1093  procedure TfrmRemCoverSheet.tvAllChange(Sender: TObject; Node: TTreeNode);
1094  begin
1095    UpdateButtons;
1096  end;
1097  
1098  procedure TfrmRemCoverSheet.lvCoverChange(Sender: TObject; Item: TListItem;
1099    Change: TItemChange);
1100  begin
1101    UpdateButtons;
1102  end;
1103  
1104  function TfrmRemCoverSheet.GetIndex(List: TORStringList;
1105    Item: TListItem): integer;
1106  var
1107    IEN: string;
1108  
1109  begin
1110    if assigned(Item) and assigned(List) then
1111    begin
1112      IEN := Item.SubItems[IdxAdd] + Item.SubItems[IdxIEN];
1113      Result := List.IndexOfPiece(IEN,U,2);
1114    end
1115    else
1116      Result := -1;
1117  end;
1118  
1119  procedure TfrmRemCoverSheet.ChangeStatus(Code: string);
1120  var
1121    tmpSL: TORStringList;
1122    Idx: integer;
1123    tmp,p: string;
1124  
1125  begin
1126    tmpSL := GetCurrent(FEditingIEN, FEditingLevel, FALSE);
1127    if assigned(tmpSL) then
1128    begin
1129      Idx := GetIndex(tmpSL, lvCover.Selected);
1130      if Idx >= 0 then
1131      begin
1132        tmp := tmpSL[idx];
1133        p := Piece(tmp,U,2);
1134        SetPiece(tmp,U,2,Code + copy(p,2,MaxInt));
1135        tmpSL[idx] := tmp;
1136        MarkListAsChanged;
1137        SetupItem(lvCover.Selected, tmp);
1138        tmp := piece(tmp,u,2);
1139        tmp := copy(tmp,1,1);
1140        if tmp = 'L' then
1141        begin
1142          LockButtonUpdate('Unlock', 'BMP_UNLOCK', UnlockHint);
1143        end;
1144        if tmp = 'N' then
1145        begin
1146          LockButtonUpdate('Lock', 'BMP_LOCK', LockHint);
1147        end;
1148        if tmp = 'R' then
1149        begin
1150          LockButtonUpdate('Add && Lock', 'BMP_LOCK', AddLockHint);
1151        end;
1152      end;
1153    end;
1154  end;
1155  
1156  procedure TfrmRemCoverSheet.btnAddClick(Sender: TObject);
1157  begin
1158    ChangeStatus(CVAddCode);
1159  end;
1160  
1161  procedure TfrmRemCoverSheet.btnRemoveClick(Sender: TObject);
1162  begin
1163    ChangeStatus(CVRemoveCode);
1164  end;
1165  
1166  procedure TfrmRemCoverSheet.btnLockClick(Sender: TObject);
1167  begin
1168    ChangeStatus(CVLockCode);
1169  end;
1170  
1171  procedure TfrmRemCoverSheet.lvViewColumnClick(Sender: TObject;
1172    Column: TListColumn);
1173  begin
1174    if FTopSortTag = Column.Tag then
1175      FTopSortUp := not FTopSortUp
1176    else
1177      FTopSortTag := Column.Tag;
1178    lvView.CustomSort(nil, 0);
1179  end;
1180  
1181  type
1182    TSortData = (sdRem, sdSeq, sdLvl, sdOther);
1183  
1184  procedure TfrmRemCoverSheet.lvCoverColumnClick(Sender: TObject;
1185    Column: TListColumn);
1186  begin
1187    if FBottomSortTag = Column.Tag then
1188      FBottomSortUp := not FBottomSortUp
1189    else
1190      FBottomSortTag := Column.Tag;
1191    lvCover.CustomSort(nil, 0);
1192  end;
1193  
1194  procedure TfrmRemCoverSheet.lvViewCompare(Sender: TObject; Item1,
1195    Item2: TListItem; Data: Integer; var Compare: Integer);
1196  var
1197    i: integer;
1198    odr: array[1..4] of TSortData;
1199    s1, s2: string;
1200  
1201  begin
1202    odr[1] := TSortData(FTopSortTag-1);
1203    case FTopSortTag of
1204      1: begin
1205           odr[2] := sdSeq;
1206           odr[3] := sdLvl;
1207           odr[4] := sdOther;
1208         end;
1209  
1210      2: begin
1211           odr[2] := sdLvl;
1212           odr[3] := sdOther;
1213           odr[4] := sdRem;
1214         end;
1215  
1216      3: begin
1217           odr[2] := sdOther;
1218           odr[3] := sdSeq;
1219           odr[4] := sdRem;
1220         end;
1221  
1222      4: begin
1223           odr[2] := sdLvl;
1224           odr[3] := sdSeq;
1225           odr[4] := sdRem;
1226         end;
1227    end;
1228    Compare := 0;
1229    for i := 1 to 4 do
1230    begin
1231      case odr[i] of
1232        sdRem:   begin
1233                   s1 := Item1.Caption;
1234                   s2 := Item2.Caption;
1235                 end;
1236  
1237        sdSeq:   begin
1238                   s1 := RPad(Item1.SubItems[IdxSeq]);
1239                   s2 := RPad(Item2.SubItems[IdxSeq]);
1240                 end;
1241  
1242        sdLvl:   begin
1243                   s1 := Item1.SubItems[IdxLvl2];
1244                   s2 := Item2.SubItems[IdxLvl2];
1245                 end;
1246  
1247        sdOther: begin
1248                   s1 := Item1.SubItems[IdxType];
1249                   s2 := Item2.SubItems[IdxType];
1250                 end;
1251  
1252      end;
1253      Compare := CompareText(s1, s2);
1254      if Compare <> 0 then break;
1255    end;
1256    if not FTopSortUp then
1257      Compare := -Compare;
1258  end;
1259  
1260  procedure TfrmRemCoverSheet.lvViewExit(Sender: TObject);
1261  begin
1262    inherited;
1263    //TDP - CQ#19733 Corrected tabbing issues
1264    if TabIsPressed() then btnView.SetFocus;
1265  end;
1266  
1267  procedure TfrmRemCoverSheet.lvCoverCompare(Sender: TObject; Item1,
1268    Item2: TListItem; Data: Integer; var Compare: Integer);
1269  var
1270    i: integer;
1271    odr: array[1..2] of TSortData;
1272    s1, s2: string;
1273  
1274  begin
1275    case FBottomSortTag of
1276      1: begin
1277           odr[1] := sdRem;
1278           odr[2] := sdSeq;
1279         end;
1280  
1281      2: begin
1282           odr[1] := sdSeq;
1283           odr[2] := sdRem;
1284         end;
1285    end;
1286    Compare := 0;
1287    for i := 1 to 2 do
1288    begin
1289      case odr[i] of
1290        sdRem:   begin
1291                   s1 := Item1.Caption;
1292                   s2 := Item2.Caption;
1293                 end;
1294  
1295        sdSeq:   begin
1296                   s1 := RPad(Item1.SubItems[IdxSeq]);
1297                   s2 := RPad(Item2.SubItems[IdxSeq]);
1298                 end;
1299      end;
1300      Compare := CompareText(s1, s2);
1301      if Compare <> 0 then break;
1302    end;
1303    if not FBottomSortUp then
1304      Compare := -Compare;
1305  end;
1306  
1307  procedure TfrmRemCoverSheet.sbUpClick(Sender: TObject);
1308  var
1309    NextItem: TListItem;
1310    Seq1, Seq2: string;
1311  
1312  begin
1313    if assigned(lvCover.Selected) then
1314    begin
1315      if FBottomSortTag <> 2 then
1316      begin
1317        FBottomSortTag := 2;
1318        lvCover.CustomSort(nil, 0);
1319      end;
1320      if lvCover.Selected.Index > 0 then
1321      begin
1322        NextItem := lvCover.Items[lvCover.Selected.Index - 1];
1323        Seq1 := NextItem.SubItems[IdxSeq];
1324        Seq2 := lvCover.Selected.SubItems[IdxSeq];
1325        SetSeq(NextItem, Seq2);
1326        SetSeq(lvCover.Selected, Seq1);
1327        lvCover.CustomSort(nil, 0);
1328        If ScreenReaderSystemActive then
1329          GetScreenReader.Speak('Reminder Moved up in Sequence');
1330        UpdateButtons;
1331      end;            
1332    end;
1333  end;
1334  
1335  procedure TfrmRemCoverSheet.sbDownClick(Sender: TObject);
1336  var
1337    NextItem: TListItem;
1338    Seq1, Seq2: string;
1339  
1340  begin
1341    if assigned(lvCover.Selected) then
1342    begin
1343      if FBottomSortTag <> 2 then
1344      begin
1345        FBottomSortTag := 2;
1346        lvCover.CustomSort(nil, 0);
1347      end;
1348      if lvCover.Selected.Index < (lvCover.Items.Count-1) then
1349      begin
1350        NextItem := lvCover.Items[lvCover.Selected.Index + 1];
1351        Seq1 := NextItem.SubItems[IdxSeq];
1352        Seq2 := lvCover.Selected.SubItems[IdxSeq];
1353        SetSeq(NextItem, Seq2);
1354        SetSeq(lvCover.Selected, Seq1);
1355        lvCover.CustomSort(nil, 0);
1356        If ScreenReaderSystemActive then
1357          GetScreenReader.Speak('Reminder Moved down in Sequence');
1358        UpdateButtons;
1359      end;
1360    end;
1361  end;
1362  
1363  procedure TfrmRemCoverSheet.SetSeq(Item: TListItem; const Value: string);
1364  var
1365    tmpSL: TORStringList;
1366    Idx: integer;
1367    tmp: string;
1368  
1369  begin
1370    tmpSL := GetCurrent(FEditingIEN, FEditingLevel, FALSE);
1371    if assigned(tmpSL) then
1372    begin
1373      Idx := GetIndex(tmpSL, Item);
1374      if Idx >= 0 then
1375      begin
1376        tmp := tmpSL[idx];
1377        if(Piece(Tmp,U,1) <> Value) then
1378        begin
1379          SetPiece(tmp,U,1,Value);
1380          tmpSL[idx] := tmp;
1381          MarkListAsChanged;
1382          SetupItem(Item, tmp);
1383        end;
1384      end;
1385    end;
1386  end;
1387  
1388  procedure TfrmRemCoverSheet.sbCopyRightClick(Sender: TObject);
1389  var
1390    i: integer;
1391    Seq, Cur, Idx: integer;
1392    tmpSL: TORStringList;
1393    IEN: string;
1394  
1395  begin
1396    if assigned(tvAll.Selected) then
1397    begin
1398      IEN := Piece(TORTreeNode(tvAll.Selected).StringData, U, 1);
1399      if ListHasData(IEN, IdxIEN) then
1400      begin
1401        ShowMsg('List already contains this Reminder');
1402        exit;
1403      end;
1404      if lvCover.Items.Count = 0 then
1405        Seq := 10
1406      else
1407      begin
1408        Seq := 0;
1409        for i := 0 to lvCover.Items.Count-1 do
1410        begin
1411          Cur := StrToIntDef(lvCover.Items[i].SubItems[IdxSeq], 0);
1412          if Seq < Cur then
1413            Seq := Cur;
1414        end;
1415        inc(Seq,10);
1416        if Seq > 999 then
1417        begin
1418          Seq := 999;
1419          while (Seq > 0) and ListHasData(IntToStr(Seq), IdxSeq) do dec(Seq);
1420        end;
1421      end;
1422      if Seq > 0 then
1423      begin
1424        tmpSL := GetCurrent(FEditingIEN, FEditingLevel, FALSE, TRUE);
1425        Idx := tmpSL.IndexOfPiece(IEN,U,2);
1426        if Idx < 0 then
1427        begin
1428          tmpSL.Add(IntToStr(Seq) + U + CVAddCode + TORTreeNode(tvAll.Selected).StringData);
1429          MarkListAsChanged;
1430          UpdateMasterListView;
1431          for i := 0 to lvCover.Items.Count-1 do
1432            if IEN = lvCover.Items[i].SubItems[IdxIEN] then
1433            begin
1434              lvCover.Selected := lvCover.Items[i];
1435              break;
1436            end;
1437        end;
1438        if ScreenReaderSystemActive then
1439          GetScreenReader.Speak('Reminder Added to ' + DataName[FEditingLevel] + ' Level Reminders List');
1440      end;
1441    end;
1442  end;
1443  
1444  procedure TfrmRemCoverSheet.sbCopyRightExit(Sender: TObject);
1445  begin
1446    inherited;
1447    //TDP - CQ#19733 On Tab from sbCopyRight, go to btnOK if no data in lvCover
1448    if TabIsPressed() then
1449    begin
1450      if not ScreenReaderSystemActive then
1451      begin
1452        if lvCover.Items.Count = 0 then btnOK.SetFocus;
1453      end;
1454    end;
1455  end;
1456  
1457  function TfrmRemCoverSheet.ListHasData(Seq: string; SubIdx: integer): boolean;
1458  var
1459    i: integer;
1460  
1461  begin
1462    Result := FALSE;
1463    for i := 0 to lvCover.Items.Count-1 do
1464      if Seq = lvCover.Items[i].SubItems[SubIdx] then
1465      begin
1466        Result := TRUE;
1467        break;
1468      end;
1469  end;
1470  
1471  procedure TfrmRemCoverSheet.udSeqChangingEx(Sender: TObject;
1472    var AllowChange: Boolean; NewValue: Smallint;
1473    Direction: TUpDownDirection);
1474  begin
1475    if FUpdating or (not FInitialized) then exit;
1476    if ListHasData(IntToStr(NewValue), IdxSeq) then
1477    begin
1478      AllowChange := FALSE;
1479      case Direction of
1480        updUp:   udSeq.Position := NewValue + 1;
1481        updDown: udSeq.Position := NewValue - 1;
1482      end;
1483    end;
1484  end;
1485  
1486  procedure TfrmRemCoverSheet.sbCopyLeftClick(Sender: TObject);
1487  var
1488    idx, Index, i: integer;
1489    tmpSL: TORStringList;
1490  
1491  begin
1492    if assigned(lvCover.Selected) then
1493    begin
1494      tmpSL := GetCurrent(FEditingIEN, FEditingLevel, FALSE);
1495      if assigned(tmpSL) then
1496      begin
1497        Idx := GetIndex(tmpSL, lvCover.Selected);
1498        Index := lvCover.Selected.Index;
1499        if Idx >= 0 then
1500        begin
1501          tmpSL.Delete(Idx);
1502          MarkListAsChanged;
1503          UpdateMasterListView;
1504          if lvCover.Items.Count > 0 then
1505          begin
1506            if Index > 0 then
1507              dec(Index);
1508            for i := 0 to lvCover.Items.Count-1 do
1509              if lvCover.Items[i].Index = Index then
1510              begin
1511                lvCover.Selected := lvCover.Items[i];
1512                break;
1513              end;
1514          end;
1515          if ScreenReaderSystemActive then
1516            GetScreenReader.Speak('Reminder Removed from ' + DataName[FEditingLevel] + ' Level Reminders List');
1517        end;
1518      end;
1519      if sbCopyLeft.Enabled and (not sbCopyLeft.Focused) then
1520        sbCopyLeft.SetFocus;    
1521    end;
1522  end;
1523  
1524  procedure TfrmRemCoverSheet.tvAllDblClick(Sender: TObject);
1525  begin
1526    if sbCopyRight.Enabled then
1527      sbCopyRight.Click;
1528  end;
1529  
1530  procedure TfrmRemCoverSheet.btnApplyClick(Sender: TObject);
1531  begin
1532    SaveData(TRUE);
1533    btnApply.Enabled := FALSE;
1534  end;
1535  
1536  procedure TfrmRemCoverSheet.btnOKClick(Sender: TObject);
1537  begin
1538    SaveData(FALSE);
1539  end;
1540  
1541  procedure TfrmRemCoverSheet.btnOKExit(Sender: TObject);
1542  begin
1543    inherited;
1544    //TDP - CQ#19733 On ShiftTab from btnOK, go to sbCopyRight if no data in lvCover
1545    if ShiftTabIsPressed() then
1546    begin
1547      if not ScreenReaderSystemActive then
1548      begin
1549        if lvCover.Items.Count = 0 then sbCopyRight.SetFocus;
1550      end;
1551    end;
1552  end;
1553  
1554  procedure TfrmRemCoverSheet.SaveData(FromApply: boolean);
1555  var
1556    i, j: integer;
1557    tmpSL: TORStringList;
1558    DeleteIt, DoRefresh: boolean;
1559    Level, lvl: TRemCoverDataLevel;
1560    ALevel, AClass, Code, IEN: string;
1561  
1562  begin
1563    DoRefresh := FALSE;
1564    i := 0;
1565    while (i < FData.Count) do
1566    begin
1567      DeleteIt := FALSE;
1568      if(Piece(FData[i],U,2) = BoolChar[TRUE]) then
1569      begin
1570        tmpSL := TORStringList(FData.Objects[i]);
1571        if assigned(tmpSL) then
1572        begin
1573          Level := dlPackage;
1574          Code := copy(FData[i],1,1);
1575          for lvl := low(TRemCoverDataLevel) to high(TRemCoverDataLevel) do
1576          begin
1577            if DataCode[lvl] = Code then
1578            begin
1579              Level := lvl;
1580              break;
1581            end;
1582          end;
1583          if Level <> dlPackage then
1584          begin
1585            IEN := copy(Piece(FData[i],U,1),2,MaxInt);
1586            ALevel := InternalName[Level];
1587            ACLass := '';
1588            case Level of
1589              dlDivision, dlService, dlLocation, dlUser:
1590                ALevel := ALevel + '.`' + IEN;
1591              dlUserClass:
1592                AClass := IEN;
1593            end;
1594            for j := 0 to tmpSL.Count-1 do
1595              tmpSL[j] := pieces(tmpSL[j],U,1,2);
1596            SetCoverSheetLevelData(ALevel, AClass, tmpSL);
1597            tmpSL.Free;
1598            DeleteIt := TRUE;
1599            FDataSaved := TRUE;
1600            DoRefresh := TRUE;
1601          end;
1602        end;
1603      end;
1604      if DeleteIt then
1605        FData.Delete(i)
1606      else
1607        inc(i);
1608    end;
1609    if FromApply and DoRefresh then
1610      UpdateMasterListView;
1611  end;
1612  
1613  procedure TfrmRemCoverSheet.lvCoverDblClick(Sender: TObject);
1614  begin
1615    if sbCopyLeft.Enabled then
1616      sbCopyLeft.Click;
1617  end;
1618  
1619  procedure TfrmRemCoverSheet.lvViewChange(Sender: TObject; Item: TListItem;
1620    Change: TItemChange);
1621  begin
1622    lvViewSelectItem(Sender, Item, FALSE);
1623  end;
1624  
1625  procedure TfrmRemCoverSheet.lvViewSelectItem(Sender: TObject; Item: TListItem;
1626    Selected: Boolean);
1627  var
1628    lvl: TRemCoverDataLevel;
1629    i: integer;
1630    ClsName, TIEN, IEN, lvlName: string;
1631    ok: boolean;
1632  
1633  begin
1634    if assigned(lvView.Selected) and (not FUpdatingView) then
1635    begin
1636      FUpdatingView := TRUE;
1637      try
1638        lvl := TRemCoverDataLevel(StrToIntDef(lvView.Selected.SubItems[IdxLvl2],ord(dlUser)));
1639        IEN := lvView.Selected.SubItems[IdxIEN];
1640        lvlName := lvView.Selected.SubItems[IdxLvl];
1641        TIEN := lvView.Selected.SubItems[IdxTIEN];
1642        ClsName := lvView.Selected.SubItems[IdxType];
1643        ok := (lvl <> FEditingLevel);
1644        if(not ok) and (lvl = dlUserClass) then
1645          ok := (FEditingIEN <> StrToIntDef(TIEN,0));
1646        if (not FUserMode) and ok and (lvl <> dlPackage) then
1647        begin
1648          case lvl of
1649            dlSystem:    FUpdatePending := cbSystem;
1650            dlDivision:  FUpdatePending := cbDivision;
1651            dlService:   FUpdatePending := cbService;
1652            dlLocation:  FUpdatePending := cbLocation;
1653            dlUserClass: FUpdatePending := cbUserClass;
1654            dlUser:      FUpdatePending := cbUser;
1655          end;
1656          if lvl = dlUserClass then
1657          begin
1658            cbxClass.InitLongList(ClsName);
1659            cbxClass.SelectByID(TIEN);
1660            FCurClass := cbxClass.ItemIEN;
1661          end;
1662          cbxDropDownClose(nil);
1663        end;
1664        if (lvl = FEditingLevel) then
1665        begin
1666          for i := 0 to lvCover.Items.Count-1 do
1667            if IEN = lvCover.Items[i].SubItems[IdxIEN] then
1668            begin
1669              lvCover.Selected := lvCover.Items[i];
1670              break;
1671            end;
1672        end;
1673        for i := 0 to lvView.Items.Count-1 do
1674        begin
1675          if (IEN = lvView.Items[i].SubItems[IdxIEN]) and
1676             (lvlName = lvView.Items[i].SubItems[IdxLvl]) then
1677          begin
1678            lvView.Selected := lvView.Items[i];
1679            break;
1680          end;
1681        end;
1682      finally
1683        FUpdatingView := FALSE;
1684      end;
1685    end;
1686  end;
1687  
1688  function TfrmRemCoverSheet.RPad(Str: String): String;
1689  begin
1690    Result := StringOfChar('0',7-length(Str)) + Str;
1691  end;
1692  
1693  procedure TfrmRemCoverSheet.btnViewClick(Sender: TObject);
1694  var
1695    frmRemCoverPreview: TfrmRemCoverPreview;
1696    CurSortOrder: integer;
1697    CurSortDir: boolean;
1698    i, idx, SeqCnt: integer;
1699    Lvl, LastLvl, tmp, AddCode, IEN, Seq, SortID: string;
1700    RemList, LvlList: TORStringList; // IEN^Name^Seq^SortID^Locked
1701    ANode: TTreeNode;
1702  
1703    procedure GetAllChildren(PNode: TTreeNode; const ASeq, ASortID: string);
1704    var
1705      Node: TTreeNode;
1706  
1707    begin
1708      PNode.Expand(FALSE);
1709      Node := PNode.GetFirstChild;
1710      while assigned(Node) do
1711      begin
1712        tmp := TORTreeNode(Node).StringData;
1713        if copy(tmp,1,1) = CVCatCode then
1714          GetAllChildren(Node, ASeq, ASortID)
1715        else
1716        begin
1717          if RemList.IndexOfPiece(Piece(tmp,u,1)) < 0 then
1718          begin
1719            SetPiece(tmp,u,3,ASeq);
1720            inc(SeqCnt);
1721            SortID := copy(ASortID,1,7) + RPad(IntToStr(SeqCnt)) + copy(ASortID,15,MaxInt);
1722            SetPiece(tmp,u,4,SortID);
1723            RemList.Add(tmp);
1724          end;
1725        end;
1726        Node := Node.GetNextSibling;
1727      end;
1728    end;
1729  
1730  begin
1731    Screen.OnActiveControlChange := fOldFocusChanged;
1732    try
1733      frmRemCoverPreview := TfrmRemCoverPreview.Create(Application);
1734      try
1735        CurSortOrder := FTopSortTag;
1736        CurSortDir := FTopSortUp;
1737        lvView.Items.BeginUpdate;
1738        try
1739          FTopSortTag := 3;
1740          FTopSortUp := TRUE;
1741          lvView.CustomSort(nil, 0);
1742          RemList := TORStringList.Create;
1743          try
1744            LvlList := TORStringList.Create;
1745            try
1746              LastLvl := '';
1747              for i := 0 to lvView.Items.Count-1 do
1748              begin
1749                Lvl := lvView.Items[i].SubItems[IdxLvl2];
1750                if LvL <> LastLvl then
1751                begin
1752                  RemList.AddStrings(LvlList);
1753                  LvlList.Clear;
1754                  LastLvl := Lvl;
1755                end;
1756                IEN := lvView.Items[i].SubItems[IdxIEN];
1757                AddCode := lvView.Items[i].SubItems[IdxAdd];
1758                idx := RemList.IndexOfPiece(IEN);
1759                if AddCode = CVRemoveCode then
1760                begin
1761                  if(idx >= 0) and (piece(RemList[idx],U,5) <> '1') then
1762                    RemList.Delete(idx);
1763                end
1764                else
1765                begin
1766                  if idx < 0 then
1767                  begin
1768                    Seq := lvView.Items[i].SubItems[IdxSeq];
1769                    SortID := RPad(Seq) + '0000000' + lvl + copy(lvView.Items[i].SubItems[IdxTIEN] + '0000000000',1,10);
1770                    tmp := IEN + U + lvView.Items[i].Caption + U + Seq + U + SortID;
1771                    if AddCode = CVLockCode then
1772                      tmp := tmp + U + '1';
1773                    RemList.Add(tmp);
1774                  end
1775                  else
1776                  if (AddCode = CVLockCode) and (piece(RemList[idx],U,5) <> '1') then
1777                  begin
1778                    tmp := RemList[idx];
1779                    SetPiece(tmp,U,5,'1');
1780                    RemList[idx] := tmp;
1781                  end;
1782                end;
1783              end;
1784              RemList.AddStrings(LvlList);
1785              FTopSortTag := CurSortOrder;
1786              FTopSortUp := CurSortDir;
1787              lvView.CustomSort(nil, 0);
1788  
1789              LvlList.Clear;
1790              //LvlList.Assign(RemList);
1791              FastAssign(RemList, LvlList);
1792              RemList.Clear;
1793              FInternalExpansion := TRUE;
1794              try
1795                for i := 0 to LvlList.Count-1 do
1796                begin
1797                  IEN := piece(LvlList[i],U,1);
1798                  if (copy(LvlList[i],1,1) = CVCatCode) then
1799                  begin
1800                    ANode := tvAll.Items.GetFirstNode;
1801                    while assigned(ANode) do
1802                    begin
1803                      if IEN = piece(TORTreeNode(ANode).StringData,U,1) then
1804                      begin
1805                        SeqCnt := 0;
1806                        GetAllChildren(ANode, Piece(LvlList[i], U, 3), Piece(LvlList[i], U, 4));
1807                        ANode := nil;
1808                      end
1809                      else
1810                        ANode := ANode.GetNextSibling;
1811                    end;
1812                  end
1813                  else
1814                  if RemList.IndexOfPiece(IEN) < 0 then
1815                    RemList.Add(LvlList[i]);
1816                end;
1817              finally
1818                FInternalExpansion := FALSE;
1819              end;
1820            finally
1821              LvlList.Free;
1822            end;
1823  
1824            RemList.SortByPiece(4);
1825            for i := 0 to RemList.Count-1 do
1826            begin
1827              with frmRemCoverPreview.lvMain.Items.Add do
1828              begin
1829                tmp := RemList[i];
1830                Caption := Piece(tmp, U, 2);
1831                SubItems.Add(Piece(tmp, U, 3));
1832                SubItems.Add(Piece(tmp, U, 4));
1833              end;
1834            end;
1835          finally
1836            RemList.Free;
1837          end;
1838        finally
1839          lvView.Items.EndUpdate;
1840        end;
1841        frmRemCoverPreview.ShowModal;
1842      finally
1843        frmRemCoverPreview.Free;
1844      end;
1845    finally
1846      Screen.OnActiveControlChange := ActiveControlChanged;
1847    end;
1848  end;
1849  
1850  procedure TfrmRemCoverSheet.btnViewExit(Sender: TObject);
1851  begin
1852    inherited;
1853    //TDP - CQ#19733 Corrected tabbing issues
1854    if TabIsPressed() then
1855    begin
1856      if ScreenReaderSystemActive then lblCAC.SetFocus
1857      else begin
1858        if pnlUser.Visible then cbxUserLoc.SetFocus
1859        else cbSystem.SetFocus;
1860      end;
1861    end;
1862    if ShiftTabIsPressed() then lvView.SetFocus;
1863  end;
1864  
1865  procedure TfrmRemCoverSheet.lvCoverKeyDown(Sender: TObject; var Key: Word;
1866    Shift: TShiftState);
1867  begin
1868    if (Key = VK_DELETE) and sbCopyLeft.Enabled then
1869      sbCopyLeft.Click;
1870  end;
1871  
1872  procedure TfrmRemCoverSheet.edtSeqKeyPress(Sender: TObject; var Key: Char);
1873  begin
1874    if (Key < '0') or (Key > '9') then
1875      Key := #0;
1876  end;
1877  
1878  procedure TfrmRemCoverSheet.cbxDivisionKeyDown(Sender: TObject;
1879    var Key: Word; Shift: TShiftState);
1880  begin
1881    if (Key = VK_RETURN) and TORComboBox(Sender).DroppedDown then
1882      TORComboBox(Sender).DroppedDown := FALSE;
1883  end;
1884  
1885  function TfrmRemCoverSheet.GetCoverSheetLvlData(ALevel,
1886    AClass: string): TStrings;
1887  var
1888    IEN: string;
1889    i, j: integer;
1890  
1891  begin
1892    Result := GetCoverSheetLevelData(ALevel, AClass);
1893    for i := 0 to Result.Count-1 do
1894    begin
1895      IEN := copy(piece(Result[i],U,2),2,MaxInt);
1896      j := FMasterList.IndexOfPiece(IEN);
1897      if j >= 0 then
1898        Result[i] := Result[i] + piece(FMasterList[j],U,3);
1899    end;
1900  end;
1901  
1902  procedure TfrmRemCoverSheet.SetButtonHints;
1903  {This procedure sets the Lock, Add, and Remove button hints based on the
1904   selected parameter level}
1905  begin
1906    if FEditingLevel = dlDivision then
1907    begin
1908      btnLock.hint := 'Adds Reminder to the Coversheet display and Locks the Reminder'
1909            + CRLF + 'so it can not be removed from the Coversheet display at any'
1910            + CRLF + 'of the lower levels (Service, Location, User Class, User).';
1911      btnRemove.hint := 'Removes Reminders from the Coversheet display.  Will not'
1912            + CRLF + 'remove Reminders which are locked at the System level.';
1913      btnAdd.hint := 'Adds Reminders to the Coversheet at the Division level and'
1914            + CRLF + 'below.  It also removes the lock from a Reminder locked at'
1915            + CRLF + 'the Division level while leaving the Reminder on the Coversheet.';
1916    end
1917    else if FEditingLevel = dlService then
1918    begin
1919      btnLock.hint := 'Adds Reminder to the Coversheet display and Locks the Reminder'
1920            + CRLF + 'so it can not be removed from the Coversheet display at any of'
1921            + CRLF + 'the lower levels (Location, User Class, User).';
1922      btnRemove.hint := 'Removes Reminders from the Coversheet display.  Will not'
1923            + CRLF + 'remove Reminders which are locked at the Division level or higher.';
1924      btnAdd.hint := 'Adds Reminders to the Coversheet at the Service level and'
1925            + CRLF + 'below.  It also removes the lock from a Reminder locked at the'
1926            + CRLF + 'Service level while leaving the Reminder on the Coversheet.';
1927    end
1928    else if FEditingLevel = dlLocation then
1929    begin
1930      btnLock.hint := 'Adds Reminder to the Coversheet display and Locks the Reminder'
1931            + CRLF + 'so it can not be removed from the Coversheet display at any of'
1932            + CRLF + 'the lower levels (User Class, User).';
1933      btnRemove.hint := 'Removes Reminders from the Coversheet display.  Will not'
1934            + CRLF + 'remove Reminders which are locked at the Service level or higher.';
1935      btnAdd.hint := 'Adds Reminders to the Coversheet at the Location level and'
1936            + CRLF + 'below.  It also removes the lock from a Reminder locked at the'
1937            + CRLF + 'Location level while leaving the Reminder on the Coversheet.';
1938    end
1939    else if FEditingLevel = dlUserClass then
1940    begin
1941      btnLock.hint := 'Adds Reminder to the Coversheet display and Locks the Reminder so'
1942            + CRLF + 'it can not be removed from the Coversheet display at the User level.';
1943      btnRemove.hint := 'Removes Reminders from the Coversheet display.  Will not remove'
1944            + CRLF + 'Reminders which are locked at the Location level or higher.';
1945      btnAdd.hint := 'Adds Reminders to the Coversheet at the User Class level and'
1946            + CRLF + 'below.  It also removes the lock from a Reminder locked at the'
1947            + CRLF + 'User Class level while leaving the Reminder on the Coversheet.';
1948    end
1949    else if FEditingLevel = dlUser then
1950    begin
1951      btnRemove.hint := 'Removes Reminders from the Coversheet display.  Will not'
1952            + CRLF + 'remove Reminders which are locked at the User Class level'
1953            + CRLF + 'or higher.';
1954      btnAdd.hint := 'Adds Reminders to the Coversheet at the User level.';
1955    end
1956    else
1957    begin
1958      btnLock.hint := 'Adds Reminder to the Coversheet display and Locks the Reminder'
1959            + CRLF + 'so it can not be removed from the Coversheet display at any of'
1960            + CRLF + 'the lower levels (Division, Service, Location, User Class, User).';
1961      btnRemove.hint := 'Removes Reminders from the Coversheet display.';
1962      btnAdd.hint := 'Adds Reminders to the Coversheet at the System level and'
1963            + CRLF + 'below.  It also removes the lock from a Reminder locked at the'
1964            + CRLF + 'System level while leaving the Reminder on the Coversheet.';
1965    end;
1966  end;
1967  
1968  procedure TfrmRemCoverSheet.FormCreate(Sender: TObject);
1969  begin
1970    FSavePause := Application.HintHidePause;   //Save Hint Pause setting
1971    Application.HintHidePause := 20000;   //Reset Hint Pause to 20 seconds
1972    //mlgnLock.hint := 'Lock a Reminder to prevent it''s removal from a lower'
1973    imgLock.hint := 'Lock a Reminder to prevent it''s removal from a lower'
1974           + CRLF + 'level Coversheet display.  For example, if you lock'
1975           + CRLF + 'a Reminder at the Service level, then that Reminder'
1976           + CRLF + 'cannot be removed from the coversheet display at'
1977           + CRLF + 'the Location, User Class, or User levels.';
1978    lblLock.hint := imgLock.hint;       
1979    fOldFocusChanged := Screen.OnActiveControlChange;
1980    Screen.OnActiveControlChange := ActiveControlChanged;
1981  end;
1982  
1983  procedure TfrmRemCoverSheet.ActiveControlChanged(Sender: TObject);
1984  begin
1985    if assigned(fOldFocusChanged) then fOldFocusChanged(Sender);
1986    UpdateButtons;
1987  end;
1988  
1989  procedure TfrmRemCoverSheet.LockButtonUpdate(Data, FNAME, Hint: string);
1990  begin
1991    btnLock.Caption := Data;
1992    btnLock.Glyph.LoadFromResourceName(hinstance, FNAME);
1993    if btnLock.Hint <> Hint then btnLock.Hint := Hint;
1994    if FNAME = 'BMP_LOCK' then btnLock.OnClick := btnLockClick
1995    else
1996      btnLock.OnClick := btnAddClick;
1997  end;
1998  
1999  end.

Module Calls (2 levels)


fRemCoverSheet
 ├fBase508Form
 │ ├uConst
 │ └uHelpManager
 ├rCore
 │ └uCore
 ├uCore...
 ├uPCE
 │ ├uConst
 │ ├uCore...
 │ ├rPCE
 │ ├rCore...
 │ ├rTIU
 │ ├fEncounterFrame
 │ ├uVitals
 │ ├fFrame
 │ ├fPCEProvider
 │ └rVitals
 ├rProbs
 │ └uCore...
 ├rTIU...
 ├rReminders
 │ ├fMHTest
 │ ├uCore...
 │ ├uReminders
 │ └rCore...
 ├uReminders...
 └fRemCoverPreview
   └fBase508Form...

Module Called-By (2 levels)


     fRemCoverSheet
    fReminderTree┤ 
         fFrame┤ │ 
     uReminders┤ │ 
         fNotes┤ │ 
      fConsults┤ │ 
fReminderDialog┤ │ 
       fSurgery┘ │ 
fOptionsReminders┘ 
       fOptions┘