-
Notifications
You must be signed in to change notification settings - Fork 1
/
preparingreport.pas
1772 lines (1643 loc) · 59.5 KB
/
preparingreport.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
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
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit preparingreport;
interface
uses System.Classes, System.JSON, System.Generics.Collections, SynPdf, Winapi.Windows,
Vcl.Graphics, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.SQLite,
FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Data.DB,
FireDAC.Comp.Client, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
FireDAC.DApt, FireDAC.Comp.DataSet, u02 ;
type
TUpdateUIEvent = procedure(mposition: Integer; fRaportName: string) of object;
TEndUpdateUIEvent = procedure(ertxt: string; er: Boolean; fpdf_file: string;
fRaportName: string) of object;
TSUMobj = class
typeSrc: integer;
fieldName: string;
end;
TobjBand = class
typeobj: Integer;
name: string;
Caption: string;
Top: Integer;
Left: Integer;
PenWidth: Integer;
Width: Integer;
Height: Integer;
OldHeight : integer;
Align: Integer;
FontSize: integer;
FontStyleBold: integer;
FontStyleItalic: integer;
FontStyleUnderLine: integer;
MarginRight: integer;
Field: string;
queryNo: integer;
FormatValue: string;
AutoSizeH: integer;
sUMobjList: TList <TSUMobj>;
Visible: string;
AsVisible: Boolean;
constructor Create();
destructor Destroy; override;
end;
TBand = class
typeBand: Integer;
name: string;
Height: Integer;
OldHeight: Integer;
objBandList: TList <TobjBand>;
constructor Create();
destructor Destroy; override;
end;
TSUMValue = class
public
paramValuePageFloat: Currency;
paramValuePagePrevFloat: Currency;
paramValueAllFloat: Currency;
field: TField;
procedure Sum();
procedure NewPage();
end;
TReportQuery = class(TFDQuery)
public
mainQ: Integer;
queryNo: Integer;
sqlTxt: string;
ParamValues: TList <TParamValue>;
sUMValues: TList <TSUMValue>;
procedure Sum();
procedure NewPage();
procedure Next;
procedure BuildSUMLIst();
constructor Create();
destructor Destroy; override;
end;
TReportStruct = class
public
raportName: string;
RaportFileName: string;
PageOrientation: integer;
bandList: TList <TBand>;
HeightAllTop: integer;
HeightAllBottom: integer;
HeightAllDetail: integer;
CountDetailInPage : integer;
CurrentPageNo : integer;
TopCount : integer;
BottomCount: integer;
DetailCount: integer;
DetailCountMax: integer;
MaxBandBottomCount: integer;
ScaleX: double;
ScaleY: double;
PageHeight : integer;
PageWidth : integer;
ReportQueryList: TList <TReportQuery>;
debug: Integer;
globalVariables : TList <TParamValue>;
STICK_BAND_BOTTOM: Integer;
constructor Create();
destructor Destroy; override;
end;
TPageStruct = class
RaportFileName: string;
ReportStruct: TReportStruct;
constructor Create();
destructor Destroy; override;
end;
TPreparingReport = class
private
fposition: Integer;
ferror_txt: string;
ferror: Boolean;
pdf_file: string;
//ReportStruct: TReportStruct;
PageStructList: TList <TPageStruct>;
FDConnection: TFDConnection;
mHWND : HWND;
procedure UpdateUI();
procedure EndUpdateUI();
procedure GeneratePages();
procedure SetGlobalVariable(ReportStruct: TReportStruct);
procedure CopyGlobalVariableToParam(ReportStruct: TReportStruct);
function GeneratePage(lPdf :TPdfDocumentGDI; ReportStruct: TReportStruct): boolean;
procedure UpdateGC();
function BuildPageDef(): Boolean;
function BuildReportDef(ReportStruct: TReportStruct; JSONValue: TJSONValue): Boolean;
function RednderBandTop(fCanvas: TCanvas;ReportStruct: TReportStruct): boolean;
function RednderBandBottom(fCanvas: TCanvas;ReportStruct: TReportStruct): boolean;
function RednderBandDetail(fCanvas: TCanvas{; var EndRap: boolean};ReportStruct: TReportStruct): boolean;
function BandRectangleTop(fCanvas: TCanvas; band: Tband;ReportStruct: TReportStruct): Boolean;
function BandRectangleDetail(fCanvas: TCanvas; band: Tband;ReportStruct: TReportStruct): Boolean;
function BandRectangleBottom(fCanvas: TCanvas; band: Tband;ReportStruct: TReportStruct): Boolean;
function CreateSQL(ReportStruct: TReportStruct):TReportQuery;
function GetMaxDetaiCount( ReportStruct: TReportStruct): integer;
function GetValueParam( ReportStruct: TReportStruct;fName: string): Variant;
procedure RenderOBJ(ftop:integer;fCanvas: TCanvas; fobjBand: TobjBand;ReportStruct: TReportStruct);
function GetValueFromQuery(fobjBand: TobjBand;ReportStruct: TReportStruct): string;
procedure DrawVert(fCanvas: TCanvas; Box: TRect; const Text: string);
function ParsujStr(Caption : string; globalVariables : TList <TParamValue>): string;
function SetHDetailBanf(fCanvas: TCanvas; band:Tband; ReportStruct:TReportStruct): integer;
function GetGlobalValueInt(globalVariables : TList <TParamValue>; fname: string;
var ParamValue: TParamValue; var return: Boolean): Integer;
function SetGlobalValueInt(globalVariables : TList <TParamValue>; fname: string; value: Integer): Boolean;
function GetSumValue(fobjBand: TobjBand;ReportStruct: TReportStruct): string; //sUMobjList
procedure AddUpdateParamRapVarBoolean(globalVariables : TList <TParamValue>;fparamName: string; fparamValue: Boolean);
function GetMaxBandBottomCount( ReportStruct: TReportStruct): integer;
public
reporDefName: string;
pathToPdf: string;
DriverName: string;
Database: string;
FUpdateUIEvent: TUpdateUIEvent;
FEndUpdateUIEvent: TEndUpdateUIEvent;
ParamValues: TList <TParamValue>;
id_PDF_file_str: string;
procedure _UpdateUI(mposition: Integer; fRaportName: string);
procedure _EndUpdateUI(ertxt: string;er: boolean; fpdf_file: string;
fRaportName: string);
constructor Create();
destructor Destroy; override;
procedure Start;
procedure AddParamSQLINT(fparamName: string; fparamValue: Integer);
end;
implementation
uses Vcl.Forms, System.SysUtils, System.IOUtils, System.StrUtils, System.Variants, u03 ;
const REPORT_BAND_TOP = 0;
PAGE_BAND_TOP = 1;
DATAIL_BAND = 2;
REPORT_BAND_BOTTOM = 3;
PAGE_BAND_BOTTOM = 4;
TYPE_TEXT_OBJ = 0;
TYPE_FIELD_OBJ = 1;
TYPE_BOX_OBJ = 2;
TYPE_FIELD_BOX_OBJ = 3;
TYPE_FIELD_SUM_BOX_OBJ = 4 ;
CENTER_TEXT_OBJ = 1;
LEFT_TEXT_OBJ = 0;
RIGHT_TEXT_OBJ = 2;
MAIN_SQL = 1;
procedure TSUMValue.NewPage();
begin
paramValuePagePrevFloat := paramValuePageFloat;
paramValuePageFloat := 0;
end;
procedure TSUMValue.Sum();
begin
if not Field.IsNull then
begin
paramValueAllFloat := paramValueAllFloat + Field.Value;
paramValuePageFloat := paramValuePageFloat + + Field.Value;
end;
end;
constructor TobjBand.Create();
begin
sUMobjList := TList <TSUMobj>.Create();
AsVisible := True;
end;
destructor TobjBand.Destroy;
var
i: Integer;
begin
for i := 0 to sUMobjList.Count -1 do
sUMobjList[i].Free;
sUMobjList.Free;
inherited;
end;
destructor TPageStruct.Destroy();
var
i: Integer;
begin
ReportStruct.Free;
inherited;
end;
constructor TPageStruct.Create();
begin
inherited;
ReportStruct := TReportStruct.Create();
end;
constructor TBand.Create();
begin
inherited;
objBandList := TList <TobjBand>.Create();
end;
destructor TBand.Destroy();
var
i: Integer;
begin
for i := 0 to objBandList.Count -1 do
begin
objBandList[i].Free;
end;
objBandList.Free;
inherited;
end;
constructor TReportQuery.Create( );
begin
inherited Create (nil);
ParamValues := TList <TParamValue>.Create();
sUMValues := TList <TSUMValue>.Create();
end;
destructor TReportQuery.Destroy();
var
i: Integer;
begin
for i := 0 to ParamValues.Count -1 do
begin
ParamValues[i].Free;
end;
ParamValues.Free;
for i := 0 to sUMValues.Count -1 do
begin
sUMValues[i].Free;
end;
sUMValues.Free;
inherited;
end;
procedure TReportQuery.BuildSUMLIst();
var
i: integer;
sumv: TsUMValue;
begin
for i := 0 to Fields.Count -1 do
begin
if (Fields[i].DataType = ftFloat) or (Fields[i].DataType = ftLargeint) or
(Fields[i].DataType = ftInteger) or
(Fields[i].DataType = ftCurrency) then
begin
sumv := TsUMValue.Create();
sumv.field := Fields[i];
sumv.paramValuePageFloat := 0;
sumv.paramValuePagePrevFloat := 0;
sumv.paramValueAllFloat := 0;
sUMValues.Add(sumv);
end;
end;
end;
procedure TReportQuery.Sum();
var
i: integer;
begin
for i := 0 to sUMValues.Count -1 do
sUMValues[i].Sum();
end;
procedure TReportQuery.NewPage();
var
i: integer;
begin
for i := 0 to sUMValues.Count -1 do
sUMValues[i].NewPage();
end;
procedure TReportQuery.Next;
begin
inherited;
end;
constructor TReportStruct.Create();
begin
inherited;
bandList := TList <TBand>.Create();
ReportQueryList := TList <TReportQuery>.Create();
globalVariables := TList <TParamValue>.Create();
end;
destructor TReportStruct.Destroy();
var
i: Integer;
begin
for i := 0 to globalVariables.Count -1 do
begin
globalVariables[i].Free;
end;
globalVariables.Free;
for i := 0 to bandList.Count -1 do
begin
bandList[i].Free;
end;
bandList.Free;
for i := 0 to ReportQueryList.Count -1 do
begin
ReportQueryList[i].Free;
end;
ReportQueryList.Free;
inherited;
end;
procedure TPreparingreport._UpdateUI(mposition: Integer; fRaportName: string);
begin
end;
procedure TPreparingreport._EndUpdateUI(ertxt: string;er: boolean; fpdf_file: string;
fRaportName: string);
begin
Writeln(ertxt + #13#10);
Writeln(fpdf_file + #13#10);
Writeln(fRaportName + #13#10);
end;
constructor TPreparingreport.Create();
begin
ferror_txt := '';
ferror := false;
ParamValues := TList <TParamValue>.Create();
end;
destructor TPreparingreport.Destroy();
var
i: Integer;
begin
for i := 0 to ParamValues.Count -1 do
begin
ParamValues[i].Free;
end;
ParamValues.Free;
inherited;
end;
procedure TPreparingreport.AddParamSQLINT(fparamName: string; fparamValue: Integer);
var
ParamValue: TParamValue;
begin
ParamValue := TParamValue.Create();
ParamValue.paramName := fparamName;
ParamValue.paramValueInt := fparamValue;
ParamValue.paramType := REPORT_INT;
ParamValues.Add(ParamValue);
end;
procedure TPreparingreport.AddUpdateParamRapVarBoolean(globalVariables : TList <TParamValue>;fparamName: string; fparamValue: Boolean);
var
ParamValue: TParamValue;
ii: integer;
begin
for ii := 0 to globalVariables.Count - 1 do
begin
if globalVariables[ii].paramName = fparamName then
begin
globalVariables[ii].paramType := REPORT_BOOLEAN;
globalVariables[ii].paramValueBoolean := fparamValue;
exit;
end;
end;
ParamValue := TParamValue.Create();
ParamValue.paramName := fparamName;
ParamValue.paramValueBoolean := fparamValue;
ParamValue.paramType := REPORT_BOOLEAN;
globalVariables.Add(ParamValue);
end;
procedure TPreparingreport.Start;
var
i: Integer;
begin
try
PageStructList := TList <TPageStruct>.Create;
try
if BuildPageDef() then
begin
EndUpdateUI();
exit;
end;
UpdateUI();
GeneratePages();
EndUpdateUI();
for i :=0 to PageStructList.Count -1 do
PageStructList[i].Free;
finally
PageStructList.free;
end;
except
on E: Exception do
begin
ferror_txt := E.Message;
ferror := True;
end;
end;
end;
procedure TPreparingreport.UpdateGC();
begin
mHWND := GetDC(0);
end;
function TPreparingreport.BuildReportDef(ReportStruct: TReportStruct; JSONValue: TJSONValue): Boolean;
var
pathToRepDef, inputstr: string;
JV: TJSONValue;
inputfile : TStringList;
bandArray: TJSONArray;
bandElementList : TJSONValue;
bandElement : TJSONValue;
band: TBand ;
objArray: TJSONArray;
objArrayList : TJSONValue;
objArrayElement : TJSONValue;
objBand :TobjBand;
fontArray: TJSONArray;
fontArrayList : TJSONValue;
fontArrayElement : TJSONValue;
i: integer;
paramValues : TParamValue;
paramArray: TJSONArray;
paramElementList : TJSONValue;
paramElement : TJSONValue;
sQLparamValues : TParamValue;
sQLparamArray: TJSONArray;
sQLparamElementList : TJSONValue;
sQLparamElement : TJSONValue;
ReportQuery: TReportQuery;
globalVarValues : TParamValue;
globalVarArray: TJSONArray;
globalVarElementList : TJSONValue;
globalVarElement : TJSONValue;
//sumVarValues : TParamValue;
sumVarArray: TJSONArray;
sumVarElementList : TJSONValue;
sumVarElement : TJSONValue;
sQLtxtArray: TJSONArray;
ii: integer;
ParamValueG : TParamValue;
sUMobj: TSUMobj;
begin
result:= false;
try
JV := (JsonValue as TJSONObject).Get('RaportName').JSONValue;
ReportStruct.RaportName := JV.Value;
except
on E: Exception do
begin
ferror_txt := E.Message;
ferror := True;
result := True;
exit;
end;
end;
try
JV := (JsonValue as TJSONObject).Get('PageOrientation').JSONValue;
ReportStruct.PageOrientation := JV.GetValue<Integer>;
except
ReportStruct.PageOrientation := 0;
end;
try
JV := (JsonValue as TJSONObject).Get('RaportFileName').JSONValue;
ReportStruct.RaportFileName := JV.Value;
except
ReportStruct.RaportFileName := '';
end;
try
JV := (JsonValue as TJSONObject).Get('PageHeight').JSONValue;
ReportStruct.PageHeight := JV.GetValue<Integer>;
except
ReportStruct.PageHeight := 0;
end;
try
JV := (JsonValue as TJSONObject).Get('PageWidth').JSONValue;
ReportStruct.PageWidth := JV.GetValue<Integer>;
except
ReportStruct.PageWidth := 0;
end;
try
JV := (JsonValue as TJSONObject).Get('debug').JSONValue;
ReportStruct.debug := JV.GetValue<Integer>;
except
ReportStruct.debug := 0;
end;
try
JV := (JsonValue as TJSONObject).Get('STICK_BAND_BOTTOM').JSONValue;
ReportStruct.STICK_BAND_BOTTOM := JV.GetValue<Integer>;
except
ReportStruct.STICK_BAND_BOTTOM := 0;
end;
try
if JsonValue.TryGetValue('globalVariables', globalVarArray) then
begin
globalVarArray := (JsonValue as TJSONObject).Get('globalVariables').JSONValue as TJSONArray;
for globalVarElementList in globalVarArray do
begin
ParamValueG := TParamValue.Create();
globalVarElement := (globalVarElementList as TJSONObject).Get('paramName').JSONValue;
ParamValueG.paramName := globalVarElement.Value;
globalVarElement := (globalVarElementList as TJSONObject).Get('paramType').JSONValue;
ParamValueG.paramType := globalVarElement.GetValue<Integer>;
globalVarElement := (globalVarElementList as TJSONObject).Get('paramValue').JSONValue;
if ParamValueG.paramType = REPORT_STRING then
ParamValueG.paramValueString := globalVarElement.Value
else if ParamValueG.paramType = REPORT_INT then
ParamValueG.paramValueInt := StrToInt(globalVarElement.Value);
ReportStruct.globalVariables.Add(ParamValueG);
end;
end;
except
on E: Exception do
begin
ferror_txt := E.Message;
ferror := True;
result := True;
end;
end;
try
if JsonValue.TryGetValue('SQL', sQLparamArray) then
begin
sQLparamArray := (JsonValue as TJSONObject).Get('SQL').JSONValue as TJSONArray;
for sQLparamElementList in sQLparamArray do
begin
ReportQuery := TReportQuery.Create();
ReportQuery.sqlTxt := '';
sQLtxtArray := (sQLparamElementList as TJSONObject).Get('sqlTxt').JSONValue as TJSONArray;
if sQLtxtArray <> nil then
begin
for ii := 0 to sQLtxtArray.Count-1 do
begin
ReportQuery.sqlTxt := ReportQuery.sqlTxt + sQLtxtArray[ii].Value;
end;
end;
sQLparamElement := (sQLparamElementList as TJSONObject).Get('queryNo').JSONValue;
ReportQuery.queryNo := sQLparamElement.GetValue<Integer>;
sQLparamElement := (sQLparamElementList as TJSONObject).Get('mainQ').JSONValue;
ReportQuery.mainQ := sQLparamElement.GetValue<Integer>;
if sQLparamElementList.TryGetValue('sqlParam', paramArray) then
begin
paramArray := (sQLparamElementList as TJSONObject).Get('sqlParam').JSONValue as TJSONArray;
for paramElementList in paramArray do
begin
paramValues := TParamValue.Create();
paramElement := (paramElementList as TJSONObject).Get('paramName').JSONValue;
paramValues.paramName := paramElement.Value;
paramElement := (paramElementList as TJSONObject).Get('paramType').JSONValue;
paramValues.paramType := paramElement.GetValue<Integer>;
ReportQuery.ParamValues.Add(paramValues);
end;
end;
ReportStruct.ReportQueryList.Add(ReportQuery);
end;
end;
except
on E: Exception do
begin
ferror_txt := E.Message;
ferror := True;
result := True;
end;
end;
//sqlParam
//
try
if JsonValue.TryGetValue('band', bandArray) then
begin
bandArray := (JsonValue as TJSONObject).Get('band').JSONValue as TJSONArray;
for bandElementList in bandArray do
begin
bandElement := (bandElementList as TJSONObject).Get('typeBand').JSONValue;
band := TBand.Create();
band.typeBand := bandElement.GetValue<Integer>;
bandElement := (bandElementList as TJSONObject).Get('name').JSONValue;
band.name := bandElement.Value;
bandElement := (bandElementList as TJSONObject).Get('Height').JSONValue;
band.Height := bandElement.GetValue<Integer>;
band.OldHeight := band.Height;
objArray := (bandElementList as TJSONObject).Get('objBand').JSONValue as TJSONArray;
for objArrayList in objArray do
begin
objArrayElement := (objArrayList as TJSONObject).Get('typeobj').JSONValue;
objBand := TobjBand.Create;
objBand.typeobj := objArrayElement.GetValue<Integer>;
if objArrayList.TryGetValue('sum', sumVarArray) then
begin
sumVarArray := ( objArrayList as TJSONObject).Get('sum').JSONValue as TJSONArray;
for sumVarElementList in sumVarArray do
begin
sUMobj := TSUMobj.Create;
if sumVarElementList.TryGetValue('typeSrc', sUMobj.typeSrc) then
begin
sumVarElement := (sumVarElementList as TJSONObject).Get('typeSrc').JSONValue;
sUMobj.typeSrc := sumVarElement.GetValue<Integer>;
end;
if sumVarElementList.TryGetValue('field', sUMobj.fieldName) then
begin
sumVarElement := (sumVarElementList as TJSONObject).Get('field').JSONValue;
sUMobj.fieldName := sumVarElement.Value;
end;
objBand.sUMobjList.Add(sUMobj) ;
end;
end;
if objArrayList.TryGetValue('AutoSizeH', objBand.Align) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('AutoSizeH').JSONValue;
objBand.AutoSizeH := objArrayElement.GetValue<Integer>;
end;
if objArrayList.TryGetValue('MarginRight', objBand.MarginRight) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('MarginRight').JSONValue;
objBand.MarginRight := objArrayElement.GetValue<Integer>;
end;
if objArrayList.TryGetValue('FormatValue', objBand.FormatValue) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('FormatValue').JSONValue;
objBand.FormatValue := objArrayElement.Value;
end else
objBand.FormatValue := '';
objArrayElement := (objArrayList as TJSONObject).Get('Name').JSONValue;
objBand.name := objArrayElement.Value;
if objArrayList.TryGetValue('Caption', objBand.Caption) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('Caption').JSONValue;
objBand.Caption := objArrayElement.Value;
end;
objArrayElement := (objArrayList as TJSONObject).Get('Top').JSONValue;
objBand.Top := objArrayElement.GetValue<Integer>;
if objArrayList.TryGetValue('Align', objBand.Align) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('Align').JSONValue;
objBand.Align := objArrayElement.GetValue<Integer>;
end;
if objArrayList.TryGetValue('Field', objBand.Field) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('Field').JSONValue;
objBand.Field := objArrayElement.Value;
end;
if objArrayList.TryGetValue('Left', objBand.Left) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('Left').JSONValue;
objBand.Left := objArrayElement.GetValue<Integer>;
end;
if objArrayList.TryGetValue('PenWidth', objBand.PenWidth) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('PenWidth').JSONValue;
objBand.PenWidth := objArrayElement.GetValue<Integer>;
end;
if objArrayList.TryGetValue('Width', objBand.Width) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('Width').JSONValue;
objBand.Width := objArrayElement.GetValue<Integer>;
end;
if objArrayList.TryGetValue('Height', objBand.Height) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('Height').JSONValue;
objBand.Height := objArrayElement.GetValue<Integer>;
end;
if objArrayList.TryGetValue('queryNo', objBand.queryNo) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('queryNo').JSONValue;
objBand.queryNo := objArrayElement.GetValue<Integer>;
end else objBand.queryNo := -1;
if objArrayList.TryGetValue('Visible', objBand.Visible) then
begin
objArrayElement := (objArrayList as TJSONObject).Get('Visible').JSONValue;
objBand.Visible := objArrayElement.Value;
if objBand.Visible = '' then
begin
objBand.Visible := 'T.';
objBand.AsVisible := True;
end else if objBand.Visible = 'T.' then
begin
objBand.AsVisible := True;
end else if objBand.Visible = 'F.' then
begin
objBand.AsVisible := False;
end else
begin
objBand.AsVisible := False;
end;
end else
begin
objBand.Visible := '';
objBand.AsVisible := True;
end;
if objArrayList.TryGetValue('font', fontArray) then
begin
fontArray := (objArrayList as TJSONObject).Get('font').JSONValue as TJSONArray;
for fontArrayList in fontArray do
begin
fontArrayElement := (fontArrayList as TJSONObject).Get('size').JSONValue;
objBand.FontSize := fontArrayElement.GetValue<Integer>;
fontArrayElement := (fontArrayList as TJSONObject).Get('bold').JSONValue;
objBand.FontStyleBold := fontArrayElement.GetValue<Integer>;
fontArrayElement := (fontArrayList as TJSONObject).Get('italic').JSONValue;
objBand.FontStyleItalic := fontArrayElement.GetValue<Integer>;
fontArrayElement := (fontArrayList as TJSONObject).Get('UnderLine').JSONValue;
objBand.FontStyleUnderLine := fontArrayElement.GetValue<Integer>;
end;
end;
band.objBandList.Add(objBand);
end;
ReportStruct.bandList.Add(band);
end;
end;
ReportStruct.HeightAllTop := 0;
ReportStruct.HeightAllBottom := 0;
for i := 0 to ReportStruct.bandList.Count -1 do
begin
if (ReportStruct.bandList[i].typeBand = REPORT_BAND_TOP) or
(ReportStruct.bandList[i].typeBand = PAGE_BAND_TOP) then
ReportStruct.HeightAllTop := ReportStruct.bandList[i].Height +ReportStruct.HeightAllTop;
if (ReportStruct.bandList[i].typeBand = REPORT_BAND_BOTTOM) or
(ReportStruct.bandList[i].typeBand = PAGE_BAND_BOTTOM) then
ReportStruct.HeightAllBottom := ReportStruct.bandList[i].Height + ReportStruct.HeightAllBottom;
if (ReportStruct.bandList[i].typeBand = DATAIL_BAND) then
ReportStruct.HeightAllDetail := ReportStruct.bandList[i].Height + ReportStruct.HeightAllDetail;
end;
except
on E: Exception do
begin
ferror_txt := E.Message;
ferror := True;
result := True;
end;
end;
end;
function TPreparingreport.BuildPageDef(): Boolean;
var
pathToRepDef, inputstr: string;
JSONValue: TJSONValue;
inputfile : TStringList;
pageValues : TParamValue;
pageArray: TJSONArray;
pageElementList : TJSONValue;
pageElement : TJSONValue;
PageStruct: TPageStruct;
globalVarValues : TParamValue;
globalVarArray: TJSONArray;
globalVarElementList : TJSONValue;
globalVarElement : TJSONValue;
ParamValue : TParamValue ;
JsonRapObj: TJSONValue;
begin
result:= false;
JsonValue := nil;
try
pathToRepDef:= reporDefName ;
inputfile := TStringList.Create;
try
inputfile.LoadFromFile(pathToRepDef, TEncoding.UTF8);
inputstr := inputfile.Text;
finally
inputfile.Free;
end;
try
JSONValue := TJSONObject.ParseJSONValue(inputstr);
except
on E: Exception do
begin
ferror_txt := E.Message;
ferror := True;
end;
end;
//PageStructList
if JsonValue.TryGetValue('Page', PageArray) then
begin
PageArray := (JsonValue as TJSONObject).Get('Page').JSONValue as TJSONArray;
for pageElementList in pageArray do
begin
PageStruct := TPageStruct.Create();
PageStructList.Add(PageStruct);
pageElement := (pageElementList as TJSONObject).Get('RaportFileName').JSONValue;
PageStruct.RaportFileName := pageElement.Value;
JsonRapObj := (pageElementList as TJSONObject).Get('RapDef').JSONValue;
if BuildReportDef(PageStruct.ReportStruct, JsonRapObj) then
exit;
end;
end else
begin
ferror_txt := 'empty page definition';
ferror := True;
result := True;
end;
except
on E: Exception do
begin
ferror_txt := E.Message;
ferror := True;
result := True;
end;
end;
end;
procedure TPreparingreport.CopyGlobalVariableToParam(ReportStruct: TReportStruct);
var
i,ii: integer;
ParamValue: TParamValue;
begin
for i := 0 to ParamValues.Count - 1 do
begin
for ii := 0 to ReportStruct.globalVariables.Count - 1 do
begin
if ReportStruct.globalVariables[ii].paramName = ParamValues[i].paramName then
begin
if ReportStruct.globalVariables[ii].paramType = ParamValues[i].paramType then
begin
if ReportStruct.globalVariables[ii].paramType = REPORT_STRING then
ParamValues[i].paramValueString := ReportStruct.globalVariables[ii].paramValueString
else if ReportStruct.globalVariables[ii].paramType = REPORT_INT then
begin
ParamValues[i].paramValueInt := ReportStruct.globalVariables[ii].paramValueInt;
ParamValues[i].paramValueInt := StrToInt(ReportStruct.globalVariables[ii].paramValueString);
end;
end;
end;
end;
end;
end;
procedure TPreparingreport.SetGlobalVariable(ReportStruct: TReportStruct);
var
i,ii: integer;
ParamValue: TParamValue;
yes: boolean;
begin
for i := 0 to ParamValues.Count - 1 do
begin
yes := false;
for ii := 0 to ReportStruct.globalVariables.Count - 1 do
begin
if ReportStruct.globalVariables[ii].paramName = ParamValues[i].paramName then
begin
yes := True;
if ReportStruct.globalVariables[ii].paramType = ParamValues[i].paramType then
begin
if ReportStruct.globalVariables[ii].paramType = REPORT_STRING then
ReportStruct.globalVariables[ii].paramValueString := ParamValues[i].paramValueString
else if ReportStruct.globalVariables[ii].paramType = REPORT_INT then
begin
ReportStruct.globalVariables[ii].paramValueInt := ParamValues[i].paramValueInt;
ReportStruct.globalVariables[ii].paramValueString := IntToStr(ParamValues[i].paramValueInt);
end;
end;
break;
end;
end;
if Yes = false then
begin
ParamValue := TParamValue.Create;
ParamValue.paramValueString := ParamValues[i].paramValueString;
if ParamValues[i].paramtype = REPORT_INT then
ParamValue.paramValueString := IntToStr(ParamValues[i].paramValueInt);
ParamValue.paramValueInt := ParamValues[i].paramValueInt;
ParamValue.paramName := ParamValues[i].paramName;
ParamValue.paramtype := ParamValues[i].paramtype;
ReportStruct.globalVariables.Add(ParamValue);
end;
end;
end;
function TPreparingreport.GeneratePage(lPdf :TPdfDocumentGDI; ReportStruct: TReportStruct): boolean;
var
endRap: boolean;
//Metafile : TMetafile;
//mCanvas : TCanvas;
mCanvas : TCanvas;
i: Integer;
bmp: TBitmap;
ParamValue: TParamValue;
return: Boolean;
mainSQL :TReportQuery;
begin
result := false;
endRap := false;
mainSQL := nil;
try
//if ReportStruct.globalVariables.Count > 0 then
if Assigned( ReportStruct.globalVariables) then
begin
AddUpdateParamRapVarBoolean(ReportStruct.globalVariables, 'ENDRAP' , false);
SetGlobalVariable(ReportStruct);
end;
if ReportStruct.ReportQueryList.Count > 0 then
mainSQL := CreateSQL(ReportStruct);
try
if ReportStruct.PageOrientation = 1 then
lPdf.DefaultPageLandscape := true
else
lPdf.DefaultPageLandscape := false;
if ReportStruct.HeightAllDetail > 0 then
ReportStruct.CountDetailInPage := trunc((Integer(lPDF.DefaultPageHeight) - ReportStruct.HeightAllTop
- ReportStruct.HeightAllBottom) / ReportStruct.HeightAllDetail);
ReportStruct.CurrentPageNo := 0;
GetGlobalValueInt(ReportStruct.globalVariables,'PAGE_NO',ParamValue, return);
try
//Metafile := TMetafile.Create;
//Metafile.SetSize(ReportStruct.PageWidth, ReportStruct.PageHeight);
//mCanvas := TCanvas.Create(Metafile, 0);
//mCanvas.Lock;
while True do
begin
//endRap := true;
AddUpdateParamRapVarBoolean(ReportStruct.globalVariables, 'ENDRAP' , True);
lPDF.AddPage;
if Assigned(mainSQL) then
mainSQL.NewPage();
if Assigned(ParamValue) then
begin
// add page no
ParamValue.SetValueInt(ParamValue.GetValueInt() + 1);
end;