-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMARCAuthEditor.pas
executable file
·565 lines (470 loc) · 14.4 KB
/
MARCAuthEditor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
unit MARCAuthEditor;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, common, mycharconversion, TntStdCtrls, ComCtrls,
Mask, DBCtrls, TntDBCtrls, dbcgrids, ExtCtrls, Grids, DBGrids, DateUtils,
TntDBGrids, TntClasses, DB, TntComCtrls, Buttons, TntButtons, TntDialogs,
TntMenus, TntForms, ActnList, cUnicodeCodecs;
type Tlink =
record
start : integer;
len : integer;
typ : Integer;
spcode : integer;
name : string;
end;
TCoord =
record
start : integer;
len : integer;
end;
type
TMARCAuthEditorform = class(TTntForm)
MainMenu1: TTntMainMenu;
File1: TTntMenuItem;
Save1: TTntMenuItem;
Delete1: TTntMenuItem;
Return1: TTntMenuItem;
Edit0081: TTntMenuItem;
Loadrecordfromfile1: TTntMenuItem;
EditLeader1: TTntMenuItem;
N1: TTntMenuItem;
N2: TTntMenuItem;
Saveastemplate1: TTntMenuItem;
Editrecord1: TTntMenuItem;
StatusBar1: TTntStatusBar;
full: TTntMemo;
TntBitBtn1: TTntBitBtn;
TntBitBtn5: TTntBitBtn;
TntBitBtn6: TTntBitBtn;
TntPopupMenu1: TTntPopupMenu;
Editleader2: TTntMenuItem;
Edit0082: TTntMenuItem;
N3: TTntMenuItem;
Loadfromtemplate1: TTntMenuItem;
Saveastemplate2: TTntMenuItem;
N4: TTntMenuItem;
Arrangetags1: TTntMenuItem;
ToolsBtn: TTntBitBtn;
Edittag1: TTntMenuItem;
ComboBox1: TTntComboBox;
TntLabel1: TTntLabel;
TntBitBtn7: TTntBitBtn;
Locate1: TTntMenuItem;
N5: TTntMenuItem;
procedure Return1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure Delete1Click(Sender: TObject);
procedure Edit0081Click(Sender: TObject);
procedure Loadrecordfromfile1Click(Sender: TObject);
procedure EditLeader1Click(Sender: TObject);
procedure Saveastemplate1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Editrecord1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure fullDblClick(Sender: TObject);
procedure fullClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MakeReadOnly;
procedure MakeEdit;
procedure ToolsBtnClick(Sender: TObject);
procedure Arrangetags1Click(Sender: TObject);
procedure fullKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure TntFormShow(Sender: TObject);
procedure Locate1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
saved : boolean;
edit_from_result_set : boolean;
record_index, previous_record, next_record : integer;
function SaveAuthData : boolean;
end;
var
MARCAuthEditorform: TMARCAuthEditorform;
reclock, inbasket, newrec : boolean;//saved,
linenr : integer;
myrecno:integer;
links : array of Tlink;
templatename : string;
procedure Refresh_auth;
implementation
uses form008auth, MyAccess, ldr, MainUnit, DataUnit, Math, EditMarcUnit,
StrUtils, WideIniClass, ProgresBarUnit, utility, GlobalProcedures,
zauthlocate;
{$R *.dfm}
procedure TMARCAuthEditorform.Return1Click(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure load_from_template(filename : string);
var
f : TextFile;
rec : UTF8String;
begin
AssignFile(F, FastRecordCreator.OpenDialog1.FileName);
Reset(F);
readln(f,rec);
if (rec='MARC TEMPLATE') then
begin
while( not (eof(f))) do
begin
readln(f,rec);
if (copy(rec,1,5) <> '[936]') then
if (copy(rec,1,5) <> '[001]') then
MARCAuthEditorForm.full.Lines.Add(UTF8StringToWideString(rec));
end;
end;
CloseFile(f);
end;
procedure TMARCAuthEditorform.Save1Click(Sender: TObject);
begin
SaveAuthData;
end;
procedure TMARCAuthEditorform.Delete1Click(Sender: TObject);
var
res, recno: integer;
text : UTF8String;
begin
if not newrec then
begin
res := WideMessageDlg('Do you want to delete this record from the database?',
mtConfirmation, [mbYes, mbNo], 0);
if res = mrYes Then
begin
recno := data.auth.FieldByName('recno').AsInteger;
text := WideStringToString(data.auth.GetBlob('text').AsWideString, Greek_codepage);
data.auth.Delete;
append_move(UserCode, 4, today, CurrentUserName + ' deleted auth recno=' + Data.auth.FieldByName('recno').AsString);
RecordUpdated(myzebraauthhost, 'delete', recno, text);
full.Modified := False;
ModalResult := mrOk;
end;
end
Else
begin
full.Modified := False;
Close;
end;
end;
procedure TMARCAuthEditorform.Edit0081Click(Sender: TObject);
var
cl,i : integer;
begin
cl := -1;
for i:=0 to full.Lines.Count-1 do
if copy(full.Lines[i],1,5) = '[008]' then begin cl := i; break; end;
eightauth.Edit1.text:=copy(full.Lines[cl],7,length(full.Lines[cl]));
eightauth.showmodal;
full.Lines[cl] :='[008] '+eightauth.Edit1.text;
end;
procedure TMARCAuthEditorform.Loadrecordfromfile1Click(Sender: TObject);
begin
load_and_merge_record(FastrecordCreator.Opendialog1, Full);
end;
procedure TMARCAuthEditorform.EditLeader1Click(Sender: TObject);
var
cl,i : integer;
begin
cl := -1;
for i:=0 to full.Lines.Count-1 do
if copy(full.Lines[i],1,5) = '[LDR]' then begin cl := i; break; end;
if cl <> -1 then
begin
leaderform.record_type := 'auth';
leaderform.Edit1.text:=copy(full.Lines[cl],7,length(full.Lines[cl]));
leaderform.showmodal;
full.Lines[cl] :='[LDR] '+leaderform.Edit1.text;
end;
end;
procedure TMARCAuthEditorform.Saveastemplate1Click(Sender: TObject);
var
i: integer;
f: textfile;
begin
FastRecordCreator.SaveDialog1.FileName := '';
FastRecordCreator.SaveDialog1.Filter := 'TMPL files (*.tmpl)|*.tmpl';
FastRecordCreator.SaveDialog1.FilterIndex := 1; { start the dialog showing all files }
if FastRecordCreator.SaveDialog1.Execute then
begin
Assignfile(f,FastRecordCreator.Savedialog1.FileName);
rewrite(f);
writeln(f,'MARC TEMPLATE');
for i:=0 to full.Lines.Count-1 do
writeln(f,WideStringToUTF8String(full.lines[i]));
CloseFile(f);
end;
end;
procedure unlock_record;
begin
if reclock Then
begin
EditTable(data.auth);
data.auth['lockcode'] := -1;
PostTable(data.auth);
reclock := False;
end;
end;
function TMARCAuthEditorform.SaveAuthData: boolean;
var
action: string;
rec: UTF8String;
recnr : integer;
begin
result :=true;
FixMemo(full);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if disp2mrc(full.Lines,rec) = 0 then //If the record was transformed successfully from Lines to MARC
begin
if SyntaxCheck(full.Lines,'auth') <> true then result := false;
if result = true then
begin
with data.auth do
begin
action:='update';
EditTable(data.auth);
EnhanceMARC(FieldByName('recno').AsInteger, rec);
FieldByName('level').AsInteger := ComboBox1.ItemIndex;
GetBlob('text').AsWideString := StringToWideString(rec, Greek_codepage);
TBlobField(FieldByName('text')).Modified := True;
if templatename = '' then
begin
FieldByName('Modified').Value := Today;
FieldByName('Modifier').Value := UserCode;
end;
PostTable(data.auth);
append_move(UserCode, 4, today, CurrentUserName + ' changed auth recno=' + Data.auth.FieldByName('recno').AsString);
if not Data.auth.FieldByName('creator').IsNull then
MARCAuthEditorform.StatusBar1.Panels[1].Text := 'Created by: ' + return_username(Data.auth.FieldByName('creator').AsInteger) +
' on ' + Data.auth.FieldByName('created').AsString;
if not Data.auth.FieldByName('modifier').IsNull then
MARCAuthEditorform.StatusBar1.Panels[2].Text := 'Modified by: ' + return_username(Data.auth.FieldByName('modifier').AsInteger) +
' on ' + Data.auth.FieldByName('modified').AsString;
end;
full.Lines.Clear;
marcrecord2memo(rec, full);
full.Modified := False;
saved:=true;
newrec := False;
recnr := Data.auth.FieldByName('recno').AsInteger;
RecordUpdated(myzebraauthhost, action, recnr, MakeMRCFromAuth(recnr));
unlock_record;
end;
end
Else
result := false;
if result = false then
WideShowMessage('You have a syntax error in this record. Please check.');
end;
procedure TMARCAuthEditorform.FormClose(Sender: TObject;
var Action: TCloseAction);
var
res: integer;
begin
if Full.Modified then
begin
res := WideMessageDlg('Record has not been saved.'+#10#13+'Do you want to save?',
mtConfirmation, [mbYes, mbNo, mbCancel], 0);
case res of
mrYes: if not SaveAuthData Then Action := caNone;
mrCancel: Action := caNone;
end;
end;
if (Action <> caNone)and (data.auth.RecordCount > 0)
then unlock_record;
end;
function take_lock : boolean;
begin
data.auth.RefreshRecord;
if (UserCode = 0) or //User is an administrator
(data.auth.FieldByName('lockcode').AsInteger = -1) or //The record is not edited by any user
(data.auth.FieldByName('lockcode').IsNull) or
(data.auth.FieldByName('lockcode').AsInteger = UserCode) or //The record is editing by me
(MinutesBetween(now, data.auth.FieldByName('locktime').AsDateTime)>60) //The lock is taken for more than 60 mins
Then
begin
//Lock table
EditTable(data.auth);
data.auth['lockcode'] := UserCode;
data.auth['locktime'] := now;
PostTable(data.auth);
reclock := True;
end;
Result := reclock;
end;
procedure TMARCAuthEditorform.MakeEdit;
begin
if take_lock Then
begin
full.ReadOnly := False;
ToolsBtn.Enabled := True;
TntBitBtn5.Enabled := True;
TntBitBtn6.Enabled := True;
ComboBox1.Enabled := True;
full.OnDblClick := fullDblClick;
end
Else
ShowMessage('This record is being edited by another user');
end;
procedure TMARCAuthEditorform.MakeReadOnly;
begin
full.ReadOnly := True;
ToolsBtn.Enabled := False;
TntBitBtn5.Enabled := False;
TntBitBtn6.Enabled := False;
ComboBox1.Enabled := False;
full.OnDblClick := nil;
end;
procedure TMARCAuthEditorform.Editrecord1Click(Sender: TObject);
begin
MakeEdit;
end;
procedure TMARCAuthEditorform.ComboBox1Change(Sender: TObject);
begin
full.Modified := True;
end;
procedure TMARCAuthEditorform.fullDblClick(Sender: TObject);
var
strr : string;
begin
strr := LeftStr(full.Lines.Strings[linenr], 5);
if strr='' then exit;
if (strr='[LDR]') then MainMenu1.Items[0].Items[1].Click
else if (strr='[008]') then MainMenu1.Items[0].Items[2].Click
else
begin
EditMarcForm.str := full.Lines.Strings[linenr];
if length(full.Lines.Strings[linenr])>6 then
begin
EditMarcForm.StatusBar1.SimpleText := StatusBar1.Panels[0].Text;
EditMarcForm.record_type := 'auth';
EditMarcForm.ShowModal;
if EditMarcForm.ModalResult = mrOk then
begin
full.Lines.Delete(linenr);
full.Lines.Insert(linenr, EditMarcForm.str);
end;
end;
end;
end;
procedure TMARCAuthEditorform.fullClick(Sender: TObject);
begin
linenr := full.CaretPos.Y;
end;
procedure TMARCAuthEditorform.FormCreate(Sender: TObject);
begin
PopulateComboFromIni('AuthRecordLevel', ComboBox1);
end;
procedure Refresh_Auth;
var
rec: UTF8String;
begin
with MARCAuthEditorForm do
begin
StatusBar1.Panels[0].Text := '';
StatusBar1.Panels[1].Text := '';
StatusBar1.Panels[2].Text := '';
full.Lines.Clear;
saved := False;
newrec := False;
myrecno := FastRecordCreator.gotoauthrecno;
MakeReadOnly;
OpenAuthTable(myrecno);
rec := WideStringToString(data.auth.GetBlob('text').AsWideString, Greek_codepage);
try
if rec<>'' then marcrecord2memo(rec, full);
finally
StatusBar1.Panels[0].Text := 'Record '+inttostr(myrecno)+'.';
ComboBox1.ItemIndex := Data.auth.FieldByName('level').AsInteger;
full.Modified := False;
end;
end;
end;
procedure Refresh_Form;
begin
reclock := False;
try
Refresh_Auth;
finally
if templatename <> '' Then
begin
load_from_template(templatename);
MARCAuthEditorform.SaveAuthData;
templatename := '';
end;
if not Data.auth.FieldByName('creator').IsNull then
MARCAuthEditorform.StatusBar1.Panels[1].Text := 'Created by: ' + return_username(Data.auth.FieldByName('creator').AsInteger) +
' on ' + Data.auth.FieldByName('created').AsString;
if not Data.auth.FieldByName('modifier').IsNull then
MARCAuthEditorform.StatusBar1.Panels[2].Text := 'Modified by: ' + return_username(Data.auth.FieldByName('modifier').AsInteger) +
' on ' + Data.auth.FieldByName('modified').AsString;
end;
end;
procedure TMARCAuthEditorform.ToolsBtnClick(Sender: TObject);
var
Point : TPoint;
begin
Point.X := (Sender as TTntBitBtn).Left;
Point.Y := (Sender as TTntBitBtn).Top + (Sender as TTntBitBtn).Height;
Point := ClientToScreen(Point);
TntPopupMenu1.Popup(Point.X, Point.Y);
end;
procedure TMARCAuthEditorform.Arrangetags1Click(Sender: TObject);
var
a : wideString;
b : wideString;
i : integer;
c : boolean;
begin
repeat
c:=false;
for i := 1 to full.Lines.Count-2 do
begin
a := full.Lines.Strings[i];
b := full.Lines.Strings[i+1];
if Copy(full.Lines.Strings[i], 2, 3) > Copy(full.Lines.Strings[i+1], 2, 3) then
begin
full.Lines.Strings[i+1]:= a;
full.Lines.Strings[i] := b;
c := true;
end;
end;
until (c=false);
end;
// By pressing Ctrl-T rearranges tags in the MARC Editor.
procedure TMARCAuthEditorform.fullKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (full.ReadOnly = False) then
begin
if (Shift = [ssCtrl]) and (Key = 84) Then //Key = t
Arrangetags1Click(Sender)
else if (Key = VK_F10) then
Locate1Click(Sender);
end;
end;
procedure TMARCAuthEditorform.TntFormShow(Sender: TObject);
begin
refresh_form;
end;
procedure TMARCAuthEditorform.Locate1Click(Sender: TObject);
begin
zauthlocateform.myrecno := -1;
zauthlocateform.source_record := '';
if not data.auth.FieldByName('recno').IsNull then
begin
zauthlocateform.myrecno := data.auth.FieldByName('recno').Value;
zauthlocateform.calledfrom:='editor';
disp2mrc(full.Lines, zauthlocateform.source_record);
zauthlocateform.ShowModal;
if zauthlocateform.merged_record <> '' then
begin
full.Lines.Clear;
marcrecord2memo(zauthlocateform.merged_record, full);
end;
end;
end;
end.