| [453] | 1 | //kt -- Modified with SourceScanner on 8/8/2007 | 
|---|
|  | 2 | unit fOptionsReminders; | 
|---|
|  | 3 |  | 
|---|
|  | 4 | interface | 
|---|
|  | 5 |  | 
|---|
|  | 6 | uses | 
|---|
|  | 7 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, | 
|---|
|  | 8 | StdCtrls, ExtCtrls, ORCtrls, OrFn, DKLang; | 
|---|
|  | 9 |  | 
|---|
|  | 10 | type | 
|---|
|  | 11 | TfrmOptionsReminders = class(TForm) | 
|---|
|  | 12 | pnlBottom: TPanel; | 
|---|
|  | 13 | btnOK: TButton; | 
|---|
|  | 14 | btnCancel: TButton; | 
|---|
|  | 15 | lstDisplayed: TORListBox; | 
|---|
|  | 16 | lstNotDisplayed: TORListBox; | 
|---|
|  | 17 | btnUp: TButton; | 
|---|
|  | 18 | btnDown: TButton; | 
|---|
|  | 19 | btnDelete: TButton; | 
|---|
|  | 20 | btnAdd: TButton; | 
|---|
|  | 21 | lblDisplayed: TLabel; | 
|---|
|  | 22 | lblNotDisplayed: TLabel; | 
|---|
|  | 23 | bvlBottom: TBevel; | 
|---|
|  | 24 | radSort: TRadioGroup; | 
|---|
|  | 25 | DKLanguageController1: TDKLanguageController; | 
|---|
|  | 26 | procedure FormCreate(Sender: TObject); | 
|---|
|  | 27 | procedure lstDisplayedChange(Sender: TObject); | 
|---|
|  | 28 | procedure lstNotDisplayedChange(Sender: TObject); | 
|---|
|  | 29 | procedure btnUpClick(Sender: TObject); | 
|---|
|  | 30 | procedure btnDownClick(Sender: TObject); | 
|---|
|  | 31 | procedure btnDeleteClick(Sender: TObject); | 
|---|
|  | 32 | procedure btnAddClick(Sender: TObject); | 
|---|
|  | 33 | function GetFirstSelection(aList: TORListBox): integer; | 
|---|
|  | 34 | procedure SetItem(aList: TORListBox; index: integer); | 
|---|
|  | 35 | procedure MoveSelected(aList: TORListBox; items: TStrings); | 
|---|
|  | 36 | procedure btnOKClick(Sender: TObject); | 
|---|
|  | 37 | procedure radSortClick(Sender: TObject); | 
|---|
|  | 38 | private | 
|---|
|  | 39 | { Private declarations } | 
|---|
|  | 40 | procedure CheckEnable; | 
|---|
|  | 41 | public | 
|---|
|  | 42 | { Public declarations } | 
|---|
|  | 43 | end; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | var | 
|---|
|  | 46 | frmOptionsReminders: TfrmOptionsReminders; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | procedure DialogOptionsReminders(topvalue, leftvalue, fontsize: integer; var actiontype: Integer); | 
|---|
|  | 49 |  | 
|---|
|  | 50 | implementation | 
|---|
|  | 51 |  | 
|---|
|  | 52 | uses rOptions, fRemCoverSheet, rReminders; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | {$R *.DFM} | 
|---|
|  | 55 |  | 
|---|
|  | 56 | procedure DialogOptionsReminders(topvalue, leftvalue, fontsize: integer; var actiontype: Integer); | 
|---|
|  | 57 | // create the form and make it modal, return an action | 
|---|
|  | 58 | var | 
|---|
|  | 59 | frmOptionsReminders: TfrmOptionsReminders; | 
|---|
|  | 60 | begin | 
|---|
|  | 61 | if NewRemCoverSheetListActive then | 
|---|
|  | 62 | EditCoverSheetReminderList(TRUE) | 
|---|
|  | 63 | else | 
|---|
|  | 64 | begin | 
|---|
|  | 65 | frmOptionsReminders := TfrmOptionsReminders.Create(Application); | 
|---|
|  | 66 | actiontype := 0; | 
|---|
|  | 67 | try | 
|---|
|  | 68 | with frmOptionsReminders do | 
|---|
|  | 69 | begin | 
|---|
|  | 70 | if (topvalue < 0) or (leftvalue < 0) then | 
|---|
|  | 71 | Position := poScreenCenter | 
|---|
|  | 72 | else | 
|---|
|  | 73 | begin | 
|---|
|  | 74 | Position := poDesigned; | 
|---|
|  | 75 | Top := topvalue; | 
|---|
|  | 76 | Left := leftvalue; | 
|---|
|  | 77 | end; | 
|---|
|  | 78 | ResizeAnchoredFormToFont(frmOptionsReminders); | 
|---|
|  | 79 | ShowModal; | 
|---|
|  | 80 | actiontype := btnOK.Tag; | 
|---|
|  | 81 | end; | 
|---|
|  | 82 | finally | 
|---|
|  | 83 | frmOptionsReminders.Release; | 
|---|
|  | 84 | end; | 
|---|
|  | 85 | end; | 
|---|
|  | 86 | end; | 
|---|
|  | 87 |  | 
|---|
|  | 88 | procedure TfrmOptionsReminders.FormCreate(Sender: TObject); | 
|---|
|  | 89 | var | 
|---|
|  | 90 | i: integer; | 
|---|
|  | 91 | biglist, userlist: TStringList; | 
|---|
|  | 92 | begin | 
|---|
|  | 93 | biglist := TStringList.Create; | 
|---|
|  | 94 | userlist := TStringList.Create; | 
|---|
|  | 95 | try | 
|---|
|  | 96 | rpcGetReminders(biglist); | 
|---|
|  | 97 | for i := 0 to biglist.Count - 1 do | 
|---|
|  | 98 | if strtointdef(Piece(biglist[i], '^', 2), 0) > 0 then | 
|---|
|  | 99 | userlist.Add(biglist[i]) | 
|---|
|  | 100 | else | 
|---|
|  | 101 | lstNotDisplayed.Items.Add(biglist[i]); | 
|---|
|  | 102 | SortByPiece(userlist, '^', 2); | 
|---|
|  | 103 | for i := 0 to userlist.Count - 1 do | 
|---|
|  | 104 | lstDisplayed.Items.Add(userlist[i]); | 
|---|
|  | 105 | finally | 
|---|
|  | 106 | biglist.free; | 
|---|
|  | 107 | userlist.free; | 
|---|
|  | 108 | end; | 
|---|
|  | 109 | CheckEnable; | 
|---|
|  | 110 | end; | 
|---|
|  | 111 |  | 
|---|
|  | 112 | procedure TfrmOptionsReminders.CheckEnable; | 
|---|
|  | 113 | // allow buttons to be enabled or not depending on selections | 
|---|
|  | 114 | begin | 
|---|
|  | 115 | with lstDisplayed do | 
|---|
|  | 116 | begin | 
|---|
|  | 117 | if Items.Count > 0 then | 
|---|
|  | 118 | begin | 
|---|
|  | 119 | if SelCount > 0 then | 
|---|
|  | 120 | begin | 
|---|
|  | 121 | btnUp.Enabled     := (SelCount > 0) | 
|---|
|  | 122 | and (not Selected[0]) | 
|---|
|  | 123 | and (radSort.ItemIndex = 0); | 
|---|
|  | 124 | btnDown.Enabled   := (SelCount > 0) | 
|---|
|  | 125 | and (not Selected[Items.Count - 1]) | 
|---|
|  | 126 | and (radSort.ItemIndex = 0); | 
|---|
|  | 127 | btnDelete.Enabled := true; | 
|---|
|  | 128 | end | 
|---|
|  | 129 | else | 
|---|
|  | 130 | begin | 
|---|
|  | 131 | btnUp.Enabled     := false; | 
|---|
|  | 132 | btnDown.Enabled   := false; | 
|---|
|  | 133 | btnDelete.Enabled := false; | 
|---|
|  | 134 | end; | 
|---|
|  | 135 | end | 
|---|
|  | 136 | else | 
|---|
|  | 137 | begin | 
|---|
|  | 138 | btnUp.Enabled     := false; | 
|---|
|  | 139 | btnDown.Enabled   := false; | 
|---|
|  | 140 | btnDelete.Enabled := false; | 
|---|
|  | 141 | end; | 
|---|
|  | 142 | end; | 
|---|
|  | 143 | with lstNotDisplayed do | 
|---|
|  | 144 | begin | 
|---|
|  | 145 | btnAdd.Enabled := SelCount > 0; | 
|---|
|  | 146 | end; | 
|---|
|  | 147 | end; | 
|---|
|  | 148 |  | 
|---|
|  | 149 | procedure TfrmOptionsReminders.lstDisplayedChange(Sender: TObject); | 
|---|
|  | 150 | begin | 
|---|
|  | 151 | CheckEnable; | 
|---|
|  | 152 | end; | 
|---|
|  | 153 |  | 
|---|
|  | 154 | procedure TfrmOptionsReminders.lstNotDisplayedChange(Sender: TObject); | 
|---|
|  | 155 | begin | 
|---|
|  | 156 | CheckEnable; | 
|---|
|  | 157 | end; | 
|---|
|  | 158 |  | 
|---|
|  | 159 | procedure TfrmOptionsReminders.btnUpClick(Sender: TObject); | 
|---|
|  | 160 | var | 
|---|
|  | 161 | newindex, i: integer; | 
|---|
|  | 162 | begin | 
|---|
|  | 163 | with lstDisplayed do | 
|---|
|  | 164 | begin | 
|---|
|  | 165 | i := 0; | 
|---|
|  | 166 | while i < Items.Count do | 
|---|
|  | 167 | begin | 
|---|
|  | 168 | if Selected[i] then | 
|---|
|  | 169 | begin | 
|---|
|  | 170 | newindex := i - 1; | 
|---|
|  | 171 | Items.Move(i, newindex); | 
|---|
|  | 172 | Selected[newindex] := true; | 
|---|
|  | 173 | end; | 
|---|
|  | 174 | inc(i); | 
|---|
|  | 175 | end; | 
|---|
|  | 176 | end; | 
|---|
|  | 177 | lstDisplayedChange(self); | 
|---|
|  | 178 | end; | 
|---|
|  | 179 |  | 
|---|
|  | 180 | procedure TfrmOptionsReminders.btnDownClick(Sender: TObject); | 
|---|
|  | 181 | var | 
|---|
|  | 182 | newindex, i: integer; | 
|---|
|  | 183 | begin | 
|---|
|  | 184 | with lstDisplayed do | 
|---|
|  | 185 | begin | 
|---|
|  | 186 | i := Items.Count - 1; | 
|---|
|  | 187 | while i > -1 do | 
|---|
|  | 188 | begin | 
|---|
|  | 189 | if Selected[i] then | 
|---|
|  | 190 | begin | 
|---|
|  | 191 | newindex := i + 1; | 
|---|
|  | 192 | Items.Move(i, newindex); | 
|---|
|  | 193 | Selected[newindex] := true; | 
|---|
|  | 194 | end; | 
|---|
|  | 195 | dec(i); | 
|---|
|  | 196 | end; | 
|---|
|  | 197 | end; | 
|---|
|  | 198 | lstDisplayedChange(self); | 
|---|
|  | 199 | end; | 
|---|
|  | 200 |  | 
|---|
|  | 201 | procedure TfrmOptionsReminders.btnDeleteClick(Sender: TObject); | 
|---|
|  | 202 | var | 
|---|
|  | 203 | index: integer; | 
|---|
|  | 204 | begin | 
|---|
|  | 205 | index := GetFirstSelection(lstDisplayed); | 
|---|
|  | 206 | MoveSelected(lstDisplayed, lstNotDisplayed.Items); | 
|---|
|  | 207 | SetItem(lstDisplayed, index); | 
|---|
|  | 208 | CheckEnable; | 
|---|
|  | 209 | end; | 
|---|
|  | 210 |  | 
|---|
|  | 211 | procedure TfrmOptionsReminders.btnAddClick(Sender: TObject); | 
|---|
|  | 212 | var | 
|---|
|  | 213 | index: integer; | 
|---|
|  | 214 | begin | 
|---|
|  | 215 | index := GetFirstSelection(lstNotDisplayed); | 
|---|
|  | 216 | MoveSelected(lstNotDisplayed, lstDisplayed.Items); | 
|---|
|  | 217 | SetItem(lstNotDisplayed, index); | 
|---|
|  | 218 | if radSort.ItemIndex = 1 then radSortClick(self); | 
|---|
|  | 219 | CheckEnable; | 
|---|
|  | 220 | end; | 
|---|
|  | 221 |  | 
|---|
|  | 222 | function TfrmOptionsReminders.GetFirstSelection(aList: TORListBox): integer; | 
|---|
|  | 223 | begin | 
|---|
|  | 224 | for result := 0 to aList.Items.Count - 1 do | 
|---|
|  | 225 | if aList.Selected[result] then exit; | 
|---|
|  | 226 | result := LB_ERR; | 
|---|
|  | 227 | end; | 
|---|
|  | 228 |  | 
|---|
|  | 229 | procedure TfrmOptionsReminders.SetItem(aList: TORListBox; index: integer); | 
|---|
|  | 230 | var | 
|---|
|  | 231 | maxindex: integer; | 
|---|
|  | 232 | begin | 
|---|
|  | 233 | with aList do | 
|---|
|  | 234 | begin | 
|---|
|  | 235 | SetFocus; | 
|---|
|  | 236 | maxindex := aList.Items.Count - 1; | 
|---|
|  | 237 | if Index = LB_ERR then | 
|---|
|  | 238 | Index := 0 | 
|---|
|  | 239 | else if Index > maxindex then Index := maxindex; | 
|---|
|  | 240 | Selected[index] := true; | 
|---|
|  | 241 | end; | 
|---|
|  | 242 | CheckEnable; | 
|---|
|  | 243 | end; | 
|---|
|  | 244 |  | 
|---|
|  | 245 | procedure TfrmOptionsReminders.MoveSelected(aList: TORListBox; Items: TStrings); | 
|---|
|  | 246 | var | 
|---|
|  | 247 | i: integer; | 
|---|
|  | 248 | begin | 
|---|
|  | 249 | for i := aList.Items.Count - 1 downto 0 do | 
|---|
|  | 250 | begin | 
|---|
|  | 251 | if aList.Selected[i] then | 
|---|
|  | 252 | begin | 
|---|
|  | 253 | Items.AddObject(aList.Items[i], aList.Items.Objects[i]); | 
|---|
|  | 254 | aList.Items.Delete(i); | 
|---|
|  | 255 | end; | 
|---|
|  | 256 | end; | 
|---|
|  | 257 | end; | 
|---|
|  | 258 |  | 
|---|
|  | 259 | procedure TfrmOptionsReminders.btnOKClick(Sender: TObject); | 
|---|
|  | 260 | var | 
|---|
|  | 261 | i: integer; | 
|---|
|  | 262 | values: string; | 
|---|
|  | 263 | aList: TStringList; | 
|---|
|  | 264 | begin | 
|---|
|  | 265 | aList := TStringList.Create; | 
|---|
|  | 266 | try | 
|---|
|  | 267 | with lstDisplayed do | 
|---|
|  | 268 | for i := 0 to Items.Count - 1 do | 
|---|
|  | 269 | begin | 
|---|
|  | 270 | values := inttostr(i + 1) + '^' + Piece(Items[i], '^', 1); | 
|---|
|  | 271 | aList.Add(values); | 
|---|
|  | 272 | end; | 
|---|
|  | 273 | rpcSetReminders(aList); | 
|---|
|  | 274 | finally | 
|---|
|  | 275 | aList.free; | 
|---|
|  | 276 | end; | 
|---|
|  | 277 | end; | 
|---|
|  | 278 |  | 
|---|
|  | 279 | procedure TfrmOptionsReminders.radSortClick(Sender: TObject); | 
|---|
|  | 280 | var | 
|---|
|  | 281 | i: integer; | 
|---|
|  | 282 | userlist: TStringList; | 
|---|
|  | 283 | begin | 
|---|
|  | 284 | userlist := TStringList.Create; | 
|---|
|  | 285 | try | 
|---|
|  | 286 | for i := 0 to lstDisplayed.Items.Count - 1 do | 
|---|
|  | 287 | userlist.Add(lstDisplayed.Items[i]); | 
|---|
|  | 288 | case radSort.ItemIndex of | 
|---|
|  | 289 | 0: SortByPiece(userlist, '^', 2); | 
|---|
|  | 290 | else SortByPiece(userlist, '^', 3); | 
|---|
|  | 291 | end; | 
|---|
|  | 292 | lstDisplayed.Items.Clear; | 
|---|
|  | 293 | for i := 0 to userlist.Count - 1 do | 
|---|
|  | 294 | lstDisplayed.Items.Add(userlist[i]); | 
|---|
|  | 295 | finally | 
|---|
|  | 296 | userlist.free; | 
|---|
|  | 297 | end; | 
|---|
|  | 298 | CheckEnable; | 
|---|
|  | 299 | end; | 
|---|
|  | 300 |  | 
|---|
|  | 301 | end. | 
|---|