source: trunk/Modules/Attendance/UModuleAttendance.pas

Last change on this file was 25, checked in by chronos, 12 years ago
  • Přidáno: Základní čtení logů z přístupového terminálu.
File size: 14.5 KB
Line 
1unit UModuleAttendance;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, UModularSystem, UFormList, UFormEdit, Controls,
9 SpecializedList, Forms, ActnList, Menus, UDataModel, Dialogs,
10 SpecializedDictionary, USqlDatabase;
11
12type
13
14 { TDataModuleAttendance }
15
16 TDataModuleAttendance = class(TDataModule)
17 AReadFromTerminal: TAction;
18 ActionList1: TActionList;
19 MenuItem1: TMenuItem;
20 PopupMenu1: TPopupMenu;
21 procedure AReadFromTerminalExecute(Sender: TObject);
22 private
23 { private declarations }
24 public
25 { public declarations }
26 end;
27
28 { TModuleAttendance }
29
30 TModuleAttendance = class(TModule)
31 private
32 ModelLog: TDataModel;
33 ViewFormLog: TDataViewForm;
34 ViewListLog: TDataViewList;
35 ModelTerminal: TDataModel;
36 ViewFormTerminal: TDataViewForm;
37 ViewListTerminal: TDataViewList;
38 ModelOperation: TDataModel;
39 ViewFormOperation: TDataViewForm;
40 ViewListOperation: TDataViewList;
41 ModelAttendance: TDataModel;
42 ViewFormAttendance: TDataViewForm;
43 ViewListAttendance: TDataViewList;
44 ModelHoliday: TDataModel;
45 ViewFormHoliday: TDataViewForm;
46 ViewListHoliday: TDataViewList;
47 ModelPassage: TDataModel;
48 ViewFormPassage: TDataViewForm;
49 ViewListPassage: TDataViewList;
50 ModelUser: TDataModel;
51 ViewFormUser: TDataViewForm;
52 ViewListUser: TDataViewList;
53 procedure InitModels;
54 protected
55 procedure DoStart; override;
56 procedure DoStop; override;
57 procedure DoInstall; override;
58 procedure DoUninstall; override;
59 public
60 constructor Create(Owner: TComponent); override;
61 destructor Destroy; override;
62 end;
63
64
65var
66 DataModuleAttendance: TDataModuleAttendance;
67
68implementation
69
70{$R *.lfm}
71
72uses
73 UFormMain, UCore, UTerminalBF630, UAccessControler, UAttendance;
74
75resourcestring
76 SAttendance = 'Attendance';
77 SPersonalId = 'Personal Id';
78 SFirstName = 'First name';
79 SSecondName = 'Second name';
80 SEnabled = 'Enabled';
81 SAddress = 'Address';
82 SPort = 'Port';
83 SType = 'Type';
84 SName = 'Name';
85 SFingerPrint = 'Fingerprint';
86 SCardCode = 'Card code';
87 SNote = 'Note';
88 SLogin = 'Login';
89 SPassword = 'Password';
90 STerminal = 'Terminal';
91 SUser = 'User';
92 SDate = 'Date';
93 STime = 'Time';
94 SOperation = 'Operation';
95 SDay = 'Day';
96 SMonth = 'Month';
97 SYear = 'Year';
98 SKeyNumber = 'Key number';
99 SText = 'Text';
100 SPassage = 'Passage';
101 STimeFrom = 'Time from';
102 STimeTo = 'Time to';
103 SHoliday = 'Holiday';
104 SLog = 'Log';
105 SUsersRead = 'User read: ';
106 SLogCount = 'Log count: ';
107
108{ TDataModuleAttendance }
109
110procedure TDataModuleAttendance.AReadFromTerminalExecute(Sender: TObject);
111var
112 AccessControler: TAccessControler;
113 VirtualAccessControler: TVirtualTerminalBF630;
114 UserCount: Integer;
115 UserRec: TUser;
116 Passage: TUserPassage;
117 PassageCount: Integer;
118 Data: TDictionaryStringString;
119 I: Integer;
120begin
121 Data := nil;
122 UserRec := nil;
123 AccessControler := nil;
124 Passage := nil;
125 try
126 VirtualAccessControler := TVirtualTerminalBF630.Create;
127 VirtualAccessControler.InitDemoData;
128 VirtualAccessControler.Active := True;
129
130 Data := TDictionaryStringString.Create;
131
132 AccessControler := TTerminalBF630.Create;
133 AccessControler.Active := True;
134 UserCount := AccessControler.GetUserCount;
135 //ShowMessage(SUsersRead + IntToStr(UserCount));
136
137 (*UserRec := TUser.Create;
138 for I := 0 to UserCount - 1 do begin
139 Data.Clear;
140 AccessControler.GetUser(I, UserRec);
141 Data.Add('FirstName', UserRec.FirstName);
142 Data.Add('SecondName', UserRec.SecondName);
143 Core.Database.Insert('User', Data);
144 end; *)
145
146 PassageCount := AccessControler.GetPassageCount;
147 //ShowMessage(SLogCount + IntToStr(PassageCount));
148
149 Passage := TUserPassage.Create;
150 for I := 0 to PassageCount - 1 do begin
151 Data.Clear;
152 AccessControler.GetPassage(I, Passage);
153 Data.Add('Terminal', IntToStr(Passage.Terminal));
154 Data.Add('Operation', IntToStr(Passage.Operation));
155 Data.Add('Time', DateTimeToSQL(Passage.Time));
156 Data.Add('User', IntToStr(Passage.User));
157 Core.Database.Insert('Passage', Data);
158 end;
159
160 finally
161 if Assigned(Data) then Data.Free;
162 if Assigned(UserRec) then UserRec.Free;
163 if Assigned(Passage) then Passage.Free;
164 if Assigned(AccessControler) then AccessControler.Free;
165 VirtualAccessControler.Free;
166 end;
167end;
168
169
170{ TModuleAttendance }
171
172procedure TModuleAttendance.InitModels;
173var
174 NewDataView: TDataViewList;
175 NewDataView2: TDataViewForm;
176 NewModel: TDataModel;
177begin
178 ModelUser := TDataModel.Create;
179 with ModelUser do begin
180 with Items do begin
181 AddItem(SEnabled, 'Enabled', dtBoolean);
182 AddItem(SPersonalId, 'PersonalId', dtString);
183 AddItem(SLogin, 'Login', dtString);
184 AddItem(SPassword, 'Password', dtString);
185 AddItem(SFirstName, 'FirstName', dtString);
186 AddItem(SSecondName, 'SecondName', dtString);
187 AddItem(SCardCode, 'CardCode', dtString);
188 AddItem(SFingerPrint, 'FingerPrint', dtString);
189 AddItem(SNote, 'Note', dtText);
190 end;
191 Name := 'User';
192 Caption := SUser;
193 end;
194 ViewListUser := TDataViewList.Create;
195 with ViewListUser do begin
196 with Columns do begin
197 AddItem(SEnabled, 'Enabled', True, 30);
198 AddItem(SPersonalId, 'PersonalId', True, 80);
199 AddItem(SLogin, 'Login', False, 80);
200 AddItem(SPassword, 'Password', False, 80);
201 AddItem(SFirstName, 'FirstName', True, 80);
202 AddItem(SSecondName, 'SecondName', True, 80);
203 AddItem(SCardCode, 'CardCode', True, 80);
204 AddItem(SFingerPrint, 'FingerPrint', True, 80);
205 AddItem(SNote, 'Note', False, 80);
206 end;
207 Name := 'User';
208 Caption := SUser;
209 ImageIndex := 9;
210 end;
211 FormMain.RegisterDataViewList(ViewListUser);
212 ViewFormUser := TDataViewForm.Create;
213 with ViewFormUser do begin
214 Name := 'User';
215 Caption := SUser;
216 with Items do begin
217 AddItem(SEnabled, 'Enabled', ctCheckBox, True, Bounds(1, 0, 1, 1));
218 AddItem(SPersonalId, 'PersonalId', ctSpinEdit, True, Bounds(3, 0, 1, 1));
219 AddItem(SLogin, 'Login', ctEdit, True, Bounds(1, 1, 1, 1));
220 AddItem(SPassword, 'Password', ctEdit, True, Bounds(3, 1, 1, 1));
221 AddItem(SFirstName, 'FirstName', ctEdit, True, Bounds(1, 2, 1, 1));
222 AddItem(SSecondName, 'SecondName', ctEdit, True, Bounds(3, 2, 1, 1));
223 AddItem(SCardCode, 'CardCode', ctEdit, True, Bounds(1, 3, 1, 1));
224 AddItem(SFingerPrint, 'FingerPrint', ctEdit, True, Bounds(3, 3, 1, 1));
225 AddItem(SNote, 'Note', ctMemo, True, Bounds(0, 5, 4, 4), alTop);
226 end;
227 end;
228 FormMain.RegisterDataViewForm(ViewFormUser);
229
230 ViewListPassage := TDataViewList.Create;
231 with ViewListPassage do begin
232 with Columns do begin
233 AddItem(STime, 'Time', True, 150);
234 AddItem(SUser, 'User', True, 80);
235 AddItem(SOperation, 'Operation', True, 80);
236 AddItem(STerminal, 'Terminal', True, 80);
237 end;
238 Name := 'Passage';
239 Caption := SPassage;
240 ImageIndex := 12;
241 end;
242 FormMain.RegisterDataViewList(ViewListPassage);
243 ViewFormPassage := TDataViewForm.Create;
244 with ViewFormPassage do begin
245 with Items do begin
246 AddItem(STime, 'Time', ctDateTime, True, Bounds(1, 0, 1, 1));
247 with AddItem(SUser, 'User', ctReference, True, Bounds(3, 0, 1, 1)) do
248 ReferencedTable := 'User';
249 with AddItem(SOperation, 'Operation', ctReference, True, Bounds(1, 1, 1, 1)) do
250 ReferencedTable := 'Operation';
251 with AddItem(STerminal, 'Terminal', ctReference, True, Bounds(3, 1, 1, 1)) do
252 ReferencedTable := 'Terminal';
253 end;
254 Name := 'Passage';
255 Caption := SPassage;
256 ImageIndex := 12;
257 end;
258 FormMain.RegisterDataViewForm(ViewFormPassage);
259
260 ViewListAttendance := TDataViewList.Create;
261 with ViewListAttendance do begin
262 with Columns do begin
263 AddItem(SDate, 'Date', True, 80);
264 AddItem(SUser, 'User', True, 80);
265 AddItem(STimeFrom, 'TimeFrom', True, 120);
266 AddItem(STimeTo, 'TimeTo', True, 120);
267 end;
268 Name := 'Attendance';
269 Caption := SAttendance;
270 ImageIndex := 14;
271 end;
272 FormMain.RegisterDataViewList(ViewListAttendance);
273 ViewFormAttendance := TDataViewForm.Create;
274 with ViewFormAttendance do begin
275 with Items do begin
276 AddItem(SUser, 'User', ctReference, True, Bounds(1, 0, 1, 1));
277 AddItem(SDate, 'Date', ctDate, True, Bounds(3, 0, 1, 1));
278 AddItem(STimeFrom, 'TimeFrom', ctTime, True, Bounds(1, 1, 1, 1));
279 AddItem(STimeTo, 'TimeTo', ctTime, True, Bounds(3, 1, 1, 1));
280 end;
281 Name := 'Attendance';
282 Caption := SAttendance;
283 ImageIndex := 14;
284 end;
285 FormMain.RegisterDataViewForm(ViewFormAttendance);
286
287 ViewListHoliday := TDataViewList.Create;
288 with ViewListHoliday do begin
289 with Columns do begin
290 AddItem(SEnabled, 'Enabled', True, 30);
291 AddItem(SName, 'Name', True, 300);
292 AddItem(SDay, 'Day', True, 50);
293 AddItem(SMonth, 'Month', True, 50);
294 AddItem(SYear, 'Year', True, 50);
295 end;
296 Name := 'Holiday';
297 Caption := SHoliday;
298 ImageIndex := 10;
299 end;
300 FormMain.RegisterDataViewList(ViewListHoliday);
301 ViewFormHoliday := TDataViewForm.Create;
302 with ViewFormHoliday do begin
303 with Items do begin
304 AddItem(SEnabled, 'Enabled', ctCheckBox, True, Bounds(1, 0, 1, 1));
305 AddItem(SName, 'Name', ctEdit, True, Bounds(3, 0, 1, 1));
306 AddItem(SDay, 'Day', ctSpinEdit, True, Bounds(1, 1, 1, 1));
307 AddItem(SMonth, 'Month', ctSpinEdit, True, Bounds(3, 1, 1, 1));
308 AddItem(SYear, 'Year', ctSpinEdit, True, Bounds(1, 2, 1, 1));
309 end;
310 Name := 'Holiday';
311 Caption := SHoliday;
312 ImageIndex := 10;
313 end;
314 FormMain.RegisterDataViewForm(ViewFormHoliday);
315
316 ViewListOperation := TDataViewList.Create;
317 with ViewListOperation do begin
318 with Columns do begin
319 AddItem(SName, 'Name', True, 100);
320 AddItem(SKeyNumber, 'KeyId', True, 100);
321 end;
322 Name := 'Operation';
323 Caption := SOperation;
324 ImageIndex := 13;
325 end;
326 FormMain.RegisterDataViewList(ViewListOperation);
327 ViewFormOperation := TDataViewForm.Create;
328 with ViewFormOperation do begin
329 with Items do begin
330 AddItem(SName, 'Name', ctEdit, True, Bounds(1, 0, 1, 1));
331 AddItem(SKeyNumber, 'KeyId', ctEdit, True, Bounds(3, 0, 1, 1));
332 end;
333 Name := 'Operation';
334 Caption := SOperation;
335 ImageIndex := 13;
336 end;
337 FormMain.RegisterDataViewForm(ViewFormOperation);
338
339 ViewListTerminal := TDataViewList.Create;
340 with ViewListTerminal do begin
341 with Columns do begin
342 AddItem(SName, 'Name', True, 80);
343 AddItem(SEnabled, 'Enabled', True, 30);
344 AddItem(SAddress, 'Address', True, 120);
345 AddItem(SPort, 'Port', True, 50);
346 with AddItem(SType, 'Type', True, 80) do
347 ReferencedTable := 'TerminalType';
348 AddItem(SNote, 'Note', True, 80);
349 end;
350 Name := 'Terminal';
351 Caption := STerminal;
352 ImageIndex := 8;
353 end;
354 FormMain.RegisterDataViewList(ViewListTerminal);
355 ViewFormTerminal := TDataViewForm.Create;
356 with ViewFormTerminal do begin
357 with Items do begin
358 AddItem(SName, 'Name', ctEdit, True, Bounds(1, 0, 1, 1));
359 AddItem(SEnabled, 'Enabled', ctCheckBox, True, Bounds(3, 0, 1, 1));
360 AddItem(SAddress, 'Address', ctEdit, True, Bounds(1, 1, 1, 1));
361 AddItem(SPort, 'Port', ctSpinEdit, True, Bounds(3, 1, 1, 1));
362 with AddItem(SType, 'Type', ctReference, True, Bounds(1, 2, 1, 1)) do
363 ReferencedTable := 'TerminalType';
364 AddItem(SNote, 'Note', ctMemo, True, Bounds(0, 4, 4, 4), alTop);
365 end;
366 Name := 'Terminal';
367 Caption := STerminal;
368 ImageIndex := 8;
369 end;
370 FormMain.RegisterDataViewForm(ViewFormTerminal);
371
372 ViewListLog := TDataViewList.Create;
373 with ViewListLog do begin
374 with Columns do begin
375 AddItem(STime, 'Time', True, 120);
376 AddItem(SUser, 'User', True, 80);
377 AddItem(SText, 'Text', True, 400);
378 end;
379 Name := 'Log';
380 Caption := SLog;
381 ImageIndex := 11;
382 end;
383 FormMain.RegisterDataViewList(ViewListLog);
384 ViewFormLog := TDataViewForm.Create;
385 with ViewFormLog do begin
386 with Items do begin
387 AddItem(STime, 'Time', ctDateTime, True, Bounds(1, 0, 1, 1));
388 AddItem(SUser, 'User', ctReference, True, Bounds(3, 0, 1, 1));
389 AddItem(SText, 'Text', ctEdit, True, Bounds(1, 1, 1, 1));
390 end;
391 Name := 'Log';
392 Caption := SLog;
393 ImageIndex := 11;
394 end;
395 FormMain.RegisterDataViewForm(ViewFormLog);
396end;
397
398procedure TModuleAttendance.DoStart;
399begin
400 inherited DoStart;
401 Application.Title := SAttendance;
402 FormMain.Caption := SAttendance;
403 DataModuleAttendance := TDataModuleAttendance.Create(FormMain);
404 InitModels;
405end;
406
407procedure TModuleAttendance.DoStop;
408begin
409 FreeAndNil(ModelUser);
410 FormMain.UnregisterDataViewList(ViewListUser);
411 FreeAndNil(ViewListUser);
412 FormMain.UnregisterDataViewForm(ViewFormUser);
413 FreeAndNil(ViewFormUser);
414 FormMain.UnregisterDataViewList(ViewListAttendance);
415 FreeAndNil(ViewListAttendance);
416 FormMain.UnregisterDataViewForm(ViewFormAttendance);
417 FreeAndNil(ViewFormAttendance);
418 FormMain.UnregisterDataViewList(ViewListHoliday);
419 FreeAndNil(ViewListHoliday);
420 FormMain.UnregisterDataViewForm(ViewFormHoliday);
421 FreeAndNil(ViewFormHoliday);
422 FormMain.UnregisterDataViewList(ViewListLog);
423 FreeAndNil(ViewListLog);
424 FormMain.UnregisterDataViewForm(ViewFormLog);
425 FreeAndNil(ViewFormLog);
426 FormMain.UnregisterDataViewList(ViewListOperation);
427 FreeAndNil(ViewListOperation);
428 FormMain.UnregisterDataViewForm(ViewFormOperation);
429 FreeAndNil(ViewFormOperation);
430 FormMain.UnregisterDataViewList(ViewListPassage);
431 FreeAndNil(ViewListPassage);
432 FormMain.UnregisterDataViewForm(ViewFormPassage);
433 FreeAndNil(ViewFormPassage);
434 FormMain.UnregisterDataViewList(ViewListTerminal);
435 FreeAndNil(ViewListTerminal);
436 FormMain.UnregisterDataViewForm(ViewFormTerminal);
437 FreeAndNil(ViewFormTerminal);
438 FreeAndNil(DataModuleAttendance);
439 inherited DoStop;
440end;
441
442procedure TModuleAttendance.DoInstall;
443begin
444 inherited DoInstall;
445end;
446
447procedure TModuleAttendance.DoUninstall;
448begin
449 inherited DoUninstall;
450end;
451
452constructor TModuleAttendance.Create(Owner: TComponent);
453begin
454 inherited Create(Owner);
455 Identification := 'Attendance';
456 Title := SAttendance;
457 Author := 'Chronos';
458 License:= 'GNU/LGPLv3';
459end;
460
461destructor TModuleAttendance.Destroy;
462begin
463 inherited Destroy;
464end;
465
466end.
467
Note: See TracBrowser for help on using the repository browser.