[go: up one dir, main page]

Menu

[r22]: / rpmdfstrucvcl.pas  Maximize  Restore  History

Download this file

721 lines (675 with data), 19.1 kB

  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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
{*******************************************************}
{ }
{ Report Manager }
{ }
{ rpmdfstrucvcl }
{ Shows the report structure and allow to alter it}
{ }
{ }
{ Copyright (c) 1994-2002 Toni Martir }
{ toni@pala.com }
{ }
{ This file is under the MPL license }
{ If you enhace this file you must provide }
{ source code }
{ }
{ }
{*******************************************************}
unit rpmdfstrucvcl;
interface
{$I rpconf.inc}
uses
SysUtils,Windows,
{$IFDEF USEVARIANTS}
Types,
{$ENDIF}
Classes,
Graphics, Controls, Forms, Dialogs,
ComCtrls,Menus, ActnList, ImgList, Buttons, ExtCtrls,
rpreport,rpsubreport,rpmdconsts,rpdbbrowservcl,
rpsection,rpmdobjinspvcl,rpprintitem, ToolWin;
type
TFRpStructureVCL = class(TFrame)
ActionList1: TActionList;
ImageList1: TImageList;
AUp: TAction;
ADown: TAction;
ADelete: TAction;
PopupMenu1: TPopupMenu;
MDetail: TMenuItem;
MPHeader: TMenuItem;
MPFooter: TMenuItem;
MGHeader: TMenuItem;
MSubReport: TMenuItem;
PControl: TPageControl;
TabStructure: TTabSheet;
RView: TTreeView;
Panel1: TToolBar;
BNew: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
TabData: TTabSheet;
procedure Expand1Click(Sender: TObject);
procedure RViewClick(Sender: TObject);
procedure AUpExecute(Sender: TObject);
procedure ADownExecute(Sender: TObject);
procedure ADeleteExecute(Sender: TObject);
procedure BNewClick(Sender: TObject);
procedure MPHeaderClick(Sender: TObject);
procedure RViewChange(Sender: TObject; Node: TTreeNode);
private
{ Private declarations }
oldappidle:TIdleEvent;
AAction:TAction;
FReport:TRpReport;
FObjInsp:TFRpObjInspVCL;
procedure ActionIdle(Sender:TObject;var done:boolean);
procedure SetReport(Value:TRpReport);
procedure CreateInterface;
procedure DisableRView;
procedure EnableRView;
public
{ Public declarations }
designframe:TControl;
browser:TFRpBrowserVCL;
procedure UpdateCaptions;
function FindSelectedSubreport:TRpSubreport;
function FindSelectedObject:TObject;
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
procedure DeleteSelectedNode;
property Report:TRpReport read FReport write SetReport;
property ObjInsp:TFRpObjInspVCL read FObjInsp write FObjInsp;
procedure RefreshInterface;
procedure SelectDataItem(data:TObject);
end;
implementation
{$R *.dfm}
uses rpmdfdesignvcl, rpmdfmainvcl;
constructor TFRpStructureVCL.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
MPHeader.Caption:=TranslateStr(119,MPHeader.Caption);
MPHeader.Hint:=TranslateStr(120,MPHeader.Hint);
MPFooter.Caption:=TranslateStr(121,MPFooter.Caption);
MPFooter.Hint:=TranslateStr(122,MPFooter.Hint);
MGHeader.Caption:=TranslateStr(123,MGHeader.Caption);
MGHeader.Hint:=TranslateStr(124,MGHeader.Hint);
MSubReport.Caption:=TranslateStr(125,MSubreport.Caption);
MSubReport.Hint:=TranslateStr(126,MSubreport.Hint);
MDetail.Caption:=TranslateStr(129,MDetail.Caption);
MDetail.Hint:=TranslateStr(130,MDetail.Hint);
ADelete.Caption:=TranslateStr(137,ADelete.Caption);
ADelete.Hint:=TranslateStr(138,ADelete.Hint);
AUp.Hint:=TranslateStr(139,AUp.Hint);
ADown.Hint:=TranslateStr(140,ADown.Hint);
BNew.Hint:=TranslateStr(734,BNew.Hint);
TabStructure.Caption:=SRpStructure;
TabData.Caption:=SRpData;
browser:=TFRpBrowserVCL.Create(Self);
browser.ShowDatabases:=false;
browser.Parent:=TabData;
PControl.ActivePageIndex:=0;
end;
destructor TFRpStructureVCL.Destroy;
begin
browser.FreeFieldsInfo;
inherited Destroy;
end;
procedure TFRpStructureVCL.SetReport(Value:TRpReport);
begin
FReport:=Value;
if Not Assigned(FReport) then
exit;
// Creates the interface
CreateInterface;
RView.FullExpand;
Browser.Report:=FReport;
if Assigned(designframe) then
begin
TFRpDesignFrameVCL(designframe).UpdateSelection(true);
end;
end;
procedure TFRpStructureVCL.ActionIdle(Sender:TObject;var done:boolean);
var
FRpMainF:TFRpMainFVCL;
begin
FRpMainF:=TFRpMainFVCL(Owner);
Application.OnIdle:=oldappidle;
done:=false;
if Assigned(AAction) then
AAction.Execute
else
begin
FRpMainF.RefreshInterface(Self);
end;
end;
function TFRpStructureVCL.FindSelectedSubreport:TRpSubreport;
var
selectednode:TTreeNode;
begin
Result:=nil;
selectednode:=RView.Selected;
if Not Assigned(selectednode) then
begin
selectednode:=RView.Items[0];
end;
if Not Assigned(selectednode) then
Raise Exception.Create(SRPNoSelectedSubreport);
Assert(selectednode.data<>nil,'Node without data assertion error');
if (TObject(selectednode.data) is TRpSubReport) then
begin
Result:=TRpSubReport(selectednode.data);
exit;
end;
selectednode:=selectednode.Parent;
Assert(selectednode.data<>nil,'Expected subreport');
if (TObject(selectednode.data) is TRpSubReport) then
begin
Result:=TRpSubReport(selectednode.data);
exit;
end;
Assert(selectednode.data<>nil,'Expected subreport');
end;
function TFRpStructureVCL.FindSelectedObject:TObject;
var
selectednode:TTreeNode;
begin
selectednode:=RView.Selected;
if Not Assigned(selectednode) then
begin
selectednode:=RView.Items[0];
end;
if Not Assigned(selectednode) then
Raise Exception.Create(SRPNoSelectedSubreport);
Assert(selectednode.data<>nil,'Node without data assertion error');
Assert(selectednode.data<>nil,'Expected data with a value');
Result:=TObject(selectednode.data);
end;
procedure TFRpStructureVCL.UpdateCaptions;
var
i:integer;
aobj:TObject;
begin
for i:=0 to RView.Items.Count-1 do
begin
if assigned(RView.Items[i].Data) then
begin
aobj:=TObject(RView.Items[i].Data);
if aobj is TRpSection then
begin
RView.Items[i].Text:=TRpSection(RView.Items[i].Data).SectionCaption(true);
end;
end;
end;
end;
procedure TFRpStructureVCL.DisableRView;
begin
RView.Items.BeginUpdate;
RView.OnChange:=nil;
RView.OnClick:=nil;
end;
procedure TFRpStructureVCL.EnableRView;
begin
RView.OnChange:=RViewChange;
RView.OnClick:=RViewClick;
RView.Items.EndUpdate;
end;
procedure TFRpStructureVCL.CreateInterface;
var
anew:TTreeNode;
i,j:integer;
subr:TRpSubreport;
child:TTreeNode;
begin
DisableRView;
try
RView.Items.Clear;
// Adds the items
for i:=0 to Report.SubReports.Count-1 do
begin
subr:=Report.SubReports.Items[i].SubReport;
anew:=RView.Items.Add(nil,subr.GetDisplayName(true));
anew.data:=Report.SubReports.Items[i].SubReport;
for j:=0 to subr.Sections.Count-1 do
begin
child:=RView.Items.AddChild(anew,subr.Sections.Items[j].Section.SectionCaption(true));
child.data:=subr.Sections.Items[j].Section;
end;
end;
finally
EnableRView;
end;
if Not Assigned(RView.Selected) then
RView.Selected:=RView.TopItem
end;
procedure TFRpStructureVCL.Expand1Click(Sender: TObject);
begin
RView.FullExpand;
end;
procedure TFRpStructureVCL.DeleteSelectedNode;
var
secorsub:TObject;
selsubreport:TRpSubReport;
begin
secorsub:=FindSelectedObject;
if (secorsub is TRpSubReport) then
freport.DeleteSubreport(TRpSubReport(secorsub))
else
begin
if (Not (secorsub is TRpSection)) then
Raise Exception.Create(SRPNoSelectedSection);
selsubreport:=FindSelectedSubreport;
selsubreport.FreeSection(TRpSection(secorsub));
end;
end;
procedure TFRpStructureVCL.RViewClick(Sender: TObject);
var
aobject:TObject;
begin
TFRpDesignFrameVCL(designframe).UpdateSelection(false);
aobject:=FindSelectedObject;
if Assigned(aobject) then
begin
AUp.Enabled:=True;
ADown.Enabled:=True;
end
else
begin
AUp.Enabled:=False;
ADown.Enabled:=False;
end;
end;
function FindDataInTree(nodes:TTreeNodes;data:TObject):TTreeNode;
var
i:integer;
begin
Result:=nil;
i:=0;
while i<nodes.Count do
begin
if nodes.item[i].data=Data then
begin
Result:=nodes.item[i];
break;
end;
inc(i);
end;
end;
procedure TFRpStructureVCL.SelectDataItem(data:TObject);
var
anode:TTreeNode;
begin
anode:=FindDataInTree(RView.Items,data);
if Assigned(anode) then
begin
RView.Selected:=anode;
RViewClick(Self);
end;
end;
procedure TFRpStructureVCL.AUpExecute(Sender: TObject);
var
subrep:TRpSubreport;
arep:TRpSubReport;
aobject:TObject;
changesubrep:integer;
asection:TRpSection;
asec:TRpSection;
i,index:integer;
asectype:TRpSectionType;
firstdetail,lastdetail:integer;
begin
// Goes up
aobject:=FindSelectedObject;
if (aobject is TRpSubReport) then
begin
subrep:=TRpSubReport(FindSelectedObject);
i:=0;
changesubrep:=-1;
while i<report.SubReports.Count do
begin
if report.SubReports.Items[i].SubReport=subrep then
begin
if changesubrep<0 then
break;
arep:=report.SubReports.Items[changesubrep].SubReport;
report.SubReports.Items[changesubrep].SubReport:=subrep;
report.SubReports.Items[i].SubReport:=arep;
SetReport(FReport);
break;
end;
changesubrep:=i;
inc(i);
end;
end
else
begin
if (aobject is TRpSection) then
begin
subrep:=FindSelectedSubreport;
asection:=TRpSection(aobject);
// It can be a detail,pheader,pfooter
if asection.SectionType in [rpsecdetail,rpsecpheader,rpsecpfooter] then
begin
asectype:=asection.SectionType;
firstdetail:=subrep.FirstSectionThatIs(asectype);
lastdetail:=subrep.LastSectionThatIs(asectype);
if firstdetail=lastdetail then
exit;
index:=-1;
for i:=firstdetail to lastdetail do
begin
if subrep.Sections[i].Section=asection then
begin
index:=i;
break;
end;
end;
if index>=0 then
begin
if index>firstdetail then
begin
asec:=subrep.Sections[index-1].Section;
subrep.Sections[index-1].Section:=subrep.Sections[index].Section;
subrep.Sections[index].Section:=asec;
SetReport(FReport);
SelectDataItem(asection);
end;
end;
end
else
begin
if asection.SectionType=rpsecgfooter then
begin
if subrep.GroupCount<2 then
exit;
index:=-1;
lastdetail:=subrep.LastDetail;
firstdetail:=subrep.FirstDetail;
for i:=1 to subrep.GroupCount do
begin
asec:=subrep.Sections.Items[lastdetail+i].Section;
if asec=asection then
begin
index:=i;
break;
end;
end;
if index<0 then
exit;
if index<2 then
exit;
// Group footer
asec:=subrep.Sections.Items[lastdetail+index-1].Section;
subrep.Sections.Items[lastdetail+index-1].Section:=subrep.Sections.Items[lastdetail+index].Section;
subrep.Sections.Items[lastdetail+index].Section:=asec;
// Group Header
asec:=subrep.Sections.Items[firstdetail-index+1].Section;
subrep.Sections.Items[firstdetail-index+1].Section:=subrep.Sections.Items[firstdetail-index].Section;
subrep.Sections.Items[firstdetail-index].Section:=asec;
// Update
SetReport(FReport);
SelectDataItem(asection);
end
else
begin
if asection.SectionType=rpsecgheader then
begin
if subrep.GroupCount<2 then
exit;
index:=-1;
lastdetail:=subrep.LastDetail;
firstdetail:=subrep.FirstDetail;
for i:=1 to subrep.GroupCount do
begin
asec:=subrep.Sections.Items[firstdetail-i].Section;
if asec=asection then
begin
index:=i;
break;
end;
end;
if index<0 then
exit;
if index>=subrep.groupcount then
exit;
// Group footer
asec:=subrep.Sections.Items[lastdetail+index+1].Section;
subrep.Sections.Items[lastdetail+index+1].Section:=subrep.Sections.Items[lastdetail+index].Section;
subrep.Sections.Items[lastdetail+index].Section:=asec;
// Group Header
asec:=subrep.Sections.Items[firstdetail-index-1].Section;
subrep.Sections.Items[firstdetail-index-1].Section:=subrep.Sections.Items[firstdetail-index].Section;
subrep.Sections.Items[firstdetail-index].Section:=asec;
// Update
SetReport(FReport);
SelectDataItem(asection);
end
else
begin
if asection.SectionType=rpsecpheader then
begin
end;
end;
end;
end;
end;
end;
end;
procedure TFRpStructureVCL.ADownExecute(Sender: TObject);
var
subrep:TRpSubreport;
arep:TRpSubReport;
changesubrep:integer;
i:integer;
aobject:TObject;
index:integer;
asection,asec:TRpSection;
asectype:TRpSectionType;
firstdetail,lastdetail:integer;
begin
// Goes down
aobject:=FindSelectedObject;
if (aobject is TRpSubReport) then
begin
subrep:=TRpSubReport(FindSelectedObject);
i:=0;
changesubrep:=-1;
while i<report.SubReports.Count do
begin
if report.SubReports.Items[i].SubReport=subrep then
begin
changesubrep:=i;
end
else
begin
if changesubrep>=0 then
begin
arep:=report.SubReports.Items[i].SubReport;
report.SubReports.Items[i].SubReport:=subrep;
report.SubReports.Items[changesubrep].SubReport:=arep;
SetReport(FReport);
break;
end;
end;
inc(i);
end;
end
else
begin
if (aobject is TRpSection) then
begin
subrep:=FindSelectedSubreport;
asection:=TRpSection(aobject);
// It can be a detail,pheader,pfooter
if asection.SectionType in [rpsecdetail,rpsecpheader,rpsecpfooter] then
begin
asectype:=asection.SectionType;
firstdetail:=subrep.FirstSectionThatIs(asectype);
lastdetail:=subrep.LastSectionThatIs(asectype);
if firstdetail=lastdetail then
exit;
index:=-1;
for i:=firstdetail to lastdetail do
begin
if subrep.Sections[i].Section=asection then
begin
index:=i;
break;
end;
end;
if index<0 then
exit;
if index<lastdetail then
begin
asec:=subrep.Sections[index+1].Section;
subrep.Sections[index+1].Section:=subrep.Sections[index].Section;
subrep.Sections[index].Section:=asec;
SetReport(FReport);
SelectDataItem(asection);
end;
end
else
begin
if asection.SectionType=rpsecgheader then
begin
if subrep.GroupCount<2 then
exit;
index:=-1;
lastdetail:=subrep.LastDetail;
firstdetail:=subrep.FirstDetail;
for i:=1 to subrep.GroupCount do
begin
asec:=subrep.Sections.Items[firstdetail-i].Section;
if asec=asection then
begin
index:=i;
break;
end;
end;
if index<=1 then
exit;
// Group footer
asec:=subrep.Sections.Items[lastdetail+index-1].Section;
subrep.Sections.Items[lastdetail+index-1].Section:=subrep.Sections.Items[lastdetail+index].Section;
subrep.Sections.Items[lastdetail+index].Section:=asec;
// Group Header
asec:=subrep.Sections.Items[firstdetail-index+1].Section;
subrep.Sections.Items[firstdetail-index+1].Section:=subrep.Sections.Items[firstdetail-index].Section;
subrep.Sections.Items[firstdetail-index].Section:=asec;
// Update
SetReport(FReport);
SelectDataItem(asection);
end
else
if asection.SectionType=rpsecgfooter then
begin
if subrep.GroupCount<2 then
exit;
index:=-1;
lastdetail:=subrep.LastDetail;
firstdetail:=subrep.FirstDetail;
for i:=1 to subrep.GroupCount do
begin
asec:=subrep.Sections.Items[lastdetail+i].Section;
if asec=asection then
begin
index:=i;
break;
end;
end;
if index<0 then
exit;
if index>=subrep.GroupCount then
exit;
// Group footer
asec:=subrep.Sections.Items[lastdetail+index+1].Section;
subrep.Sections.Items[lastdetail+index+1].Section:=subrep.Sections.Items[lastdetail+index].Section;
subrep.Sections.Items[lastdetail+index].Section:=asec;
// Group Header
asec:=subrep.Sections.Items[firstdetail-index-1].Section;
subrep.Sections.Items[firstdetail-index-1].Section:=subrep.Sections.Items[firstdetail-index].Section;
subrep.Sections.Items[firstdetail-index].Section:=asec;
// Update
SetReport(FReport);
SelectDataItem(asection);
end
end;
end;
end;
end;
procedure TFRpStructureVCL.ADeleteExecute(Sender: TObject);
var
FRpMainF:TFRpMainFVCL;
begin
FRpMainF:=TFRpMainFVCL(Owner);
AAction:=FRpMainf.ADeleteSelection;
oldappidle:=Application.Onidle;
Application.OnIdle:=ActionIdle;
end;
procedure TFRpStructureVCL.BNewClick(Sender: TObject);
var
apoint:TPoint;
begin
apoint.x:=BNew.Left;
apoint.y:=BNew.Top+BNew.Height;
apoint:=BNew.Parent.ClientToScreen(apoint);
BNew.DropDownMenu.Popup(apoint.x,apoint.y);
end;
procedure TFRpStructureVCL.MPHeaderClick(Sender: TObject);
var
FRpMainF:TFRpMainFVCL;
begin
if Sender=MPHeader then
begin
FRpMainF:=TFRpMainFVCL(Owner);
AAction:=FRpMainf.ANewPageHeader;
oldappidle:=Application.Onidle;
Application.OnIdle:=ActionIdle;
exit;
end;
if Sender=MPFooter then
begin
FRpMainF:=TFRpMainFVCL(Owner);
AAction:=FRpMainf.ANewPageFooter;
oldappidle:=Application.Onidle;
Application.OnIdle:=ActionIdle;
exit;
end;
if Sender=MGHeader then
begin
FRpMainF:=TFRpMainFVCL(Owner);
AAction:=FRpMainf.ANewGroup;
oldappidle:=Application.Onidle;
Application.OnIdle:=ActionIdle;
exit;
end;
if Sender=MSubReport then
begin
FRpMainF:=TFRpMainFVCL(Owner);
AAction:=FRpMainf.ANewSubreport;
oldappidle:=Application.Onidle;
Application.OnIdle:=ActionIdle;
exit;
end;
if Sender=MDetail then
begin
FRpMainF:=TFRpMainFVCL(Owner);
AAction:=FRpMainf.ANewDetail;
oldappidle:=Application.Onidle;
Application.OnIdle:=ActionIdle;
exit;
end;
end;
procedure TFRpStructureVCL.RefreshInterface;
begin
AAction:=nil;
oldappidle:=Application.Onidle;
Application.OnIdle:=ActionIdle;
end;
procedure TFRpStructureVCL.RViewChange(Sender: TObject; Node: TTreeNode);
begin
RViewClick(Self);
end;
end.