@reportman/engine 0.0.0-stage → 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/LICENSE +373 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/data/columns.d.ts +50 -0
  4. package/dist/data/columns.d.ts.map +1 -0
  5. package/dist/data/columns.js +385 -0
  6. package/dist/data/columns.js.map +1 -0
  7. package/dist/data/databaseinfo.d.ts +41 -0
  8. package/dist/data/databaseinfo.d.ts.map +1 -0
  9. package/dist/data/databaseinfo.js +145 -0
  10. package/dist/data/databaseinfo.js.map +1 -0
  11. package/dist/data/datainfo.d.ts +82 -0
  12. package/dist/data/datainfo.d.ts.map +1 -0
  13. package/dist/data/datainfo.js +449 -0
  14. package/dist/data/datainfo.js.map +1 -0
  15. package/dist/data/errors.d.ts +8 -0
  16. package/dist/data/errors.d.ts.map +1 -0
  17. package/dist/data/errors.js +14 -0
  18. package/dist/data/errors.js.map +1 -0
  19. package/dist/data/host.d.ts +132 -0
  20. package/dist/data/host.d.ts.map +1 -0
  21. package/dist/data/host.js +108 -0
  22. package/dist/data/host.js.map +1 -0
  23. package/dist/data/op.d.ts +21 -0
  24. package/dist/data/op.d.ts.map +1 -0
  25. package/dist/data/op.js +97 -0
  26. package/dist/data/op.js.map +1 -0
  27. package/dist/data/reportdataset.d.ts +116 -0
  28. package/dist/data/reportdataset.d.ts.map +1 -0
  29. package/dist/data/reportdataset.js +396 -0
  30. package/dist/data/reportdataset.js.map +1 -0
  31. package/dist/data/transfer.d.ts +46 -0
  32. package/dist/data/transfer.d.ts.map +1 -0
  33. package/dist/data/transfer.js +100 -0
  34. package/dist/data/transfer.js.map +1 -0
  35. package/dist/data/union.d.ts +88 -0
  36. package/dist/data/union.d.ts.map +1 -0
  37. package/dist/data/union.js +733 -0
  38. package/dist/data/union.js.map +1 -0
  39. package/dist/eval/chinesetables.d.ts +5 -0
  40. package/dist/eval/chinesetables.d.ts.map +1 -0
  41. package/dist/eval/chinesetables.js +8 -0
  42. package/dist/eval/chinesetables.js.map +1 -0
  43. package/dist/eval/evaluator.d.ts +100 -0
  44. package/dist/eval/evaluator.d.ts.map +1 -0
  45. package/dist/eval/evaluator.js +667 -0
  46. package/dist/eval/evaluator.js.map +1 -0
  47. package/dist/eval/exception.d.ts +9 -0
  48. package/dist/eval/exception.d.ts.map +1 -0
  49. package/dist/eval/exception.js +15 -0
  50. package/dist/eval/exception.js.map +1 -0
  51. package/dist/eval/fields.d.ts +60 -0
  52. package/dist/eval/fields.d.ts.map +1 -0
  53. package/dist/eval/fields.js +104 -0
  54. package/dist/eval/fields.js.map +1 -0
  55. package/dist/eval/functions.d.ts +27 -0
  56. package/dist/eval/functions.d.ts.map +1 -0
  57. package/dist/eval/functions.js +810 -0
  58. package/dist/eval/functions.js.map +1 -0
  59. package/dist/eval/identifiers.d.ts +100 -0
  60. package/dist/eval/identifiers.d.ts.map +1 -0
  61. package/dist/eval/identifiers.js +195 -0
  62. package/dist/eval/identifiers.js.map +1 -0
  63. package/dist/eval/parser.d.ts +47 -0
  64. package/dist/eval/parser.d.ts.map +1 -0
  65. package/dist/eval/parser.js +336 -0
  66. package/dist/eval/parser.js.map +1 -0
  67. package/dist/index.d.ts +52 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +42 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/params/param.d.ts +92 -0
  72. package/dist/params/param.d.ts.map +1 -0
  73. package/dist/params/param.js +358 -0
  74. package/dist/params/param.js.map +1 -0
  75. package/dist/params/parameters.d.ts +87 -0
  76. package/dist/params/parameters.d.ts.map +1 -0
  77. package/dist/params/parameters.js +499 -0
  78. package/dist/params/parameters.js.map +1 -0
  79. package/dist/report/barcode/barcodeitem.d.ts +76 -0
  80. package/dist/report/barcode/barcodeitem.d.ts.map +1 -0
  81. package/dist/report/barcode/barcodeitem.js +864 -0
  82. package/dist/report/barcode/barcodeitem.js.map +1 -0
  83. package/dist/report/barcode/code128.d.ts +18 -0
  84. package/dist/report/barcode/code128.d.ts.map +1 -0
  85. package/dist/report/barcode/code128.js +187 -0
  86. package/dist/report/barcode/code128.js.map +1 -0
  87. package/dist/report/barcode/netutil.d.ts +30 -0
  88. package/dist/report/barcode/netutil.d.ts.map +1 -0
  89. package/dist/report/barcode/netutil.js +65 -0
  90. package/dist/report/barcode/netutil.js.map +1 -0
  91. package/dist/report/barcode/pdf417.d.ts +17 -0
  92. package/dist/report/barcode/pdf417.d.ts.map +1 -0
  93. package/dist/report/barcode/pdf417.js +782 -0
  94. package/dist/report/barcode/pdf417.js.map +1 -0
  95. package/dist/report/barcode/pdf417tables.d.ts +11 -0
  96. package/dist/report/barcode/pdf417tables.d.ts.map +1 -0
  97. package/dist/report/barcode/pdf417tables.js +880 -0
  98. package/dist/report/barcode/pdf417tables.js.map +1 -0
  99. package/dist/report/barcode/qrcode.d.ts +14 -0
  100. package/dist/report/barcode/qrcode.d.ts.map +1 -0
  101. package/dist/report/barcode/qrcode.js +214 -0
  102. package/dist/report/barcode/qrcode.js.map +1 -0
  103. package/dist/report/barcode/zxingwidth.d.ts +4 -0
  104. package/dist/report/barcode/zxingwidth.d.ts.map +1 -0
  105. package/dist/report/barcode/zxingwidth.js +247 -0
  106. package/dist/report/barcode/zxingwidth.js.map +1 -0
  107. package/dist/report/chart/chartidens.d.ts +70 -0
  108. package/dist/report/chart/chartidens.d.ts.map +1 -0
  109. package/dist/report/chart/chartidens.js +162 -0
  110. package/dist/report/chart/chartidens.js.map +1 -0
  111. package/dist/report/chart/chartitem.d.ts +110 -0
  112. package/dist/report/chart/chartitem.d.ts.map +1 -0
  113. package/dist/report/chart/chartitem.js +403 -0
  114. package/dist/report/chart/chartitem.js.map +1 -0
  115. package/dist/report/chart/series.d.ts +65 -0
  116. package/dist/report/chart/series.d.ts.map +1 -0
  117. package/dist/report/chart/series.js +74 -0
  118. package/dist/report/chart/series.js.map +1 -0
  119. package/dist/report/chart/vectorchart.d.ts +18 -0
  120. package/dist/report/chart/vectorchart.d.ts.map +1 -0
  121. package/dist/report/chart/vectorchart.js +356 -0
  122. package/dist/report/chart/vectorchart.js.map +1 -0
  123. package/dist/report/convert.d.ts +4 -0
  124. package/dist/report/convert.d.ts.map +1 -0
  125. package/dist/report/convert.js +162 -0
  126. package/dist/report/convert.js.map +1 -0
  127. package/dist/report/errors.d.ts +13 -0
  128. package/dist/report/errors.d.ts.map +1 -0
  129. package/dist/report/errors.js +20 -0
  130. package/dist/report/errors.js.map +1 -0
  131. package/dist/report/identifiers.d.ts +91 -0
  132. package/dist/report/identifiers.d.ts.map +1 -0
  133. package/dist/report/identifiers.js +404 -0
  134. package/dist/report/identifiers.js.map +1 -0
  135. package/dist/report/imageitem.d.ts +66 -0
  136. package/dist/report/imageitem.d.ts.map +1 -0
  137. package/dist/report/imageitem.js +190 -0
  138. package/dist/report/imageitem.js.map +1 -0
  139. package/dist/report/items.d.ts +219 -0
  140. package/dist/report/items.d.ts.map +1 -0
  141. package/dist/report/items.js +1015 -0
  142. package/dist/report/items.js.map +1 -0
  143. package/dist/report/report.d.ts +221 -0
  144. package/dist/report/report.d.ts.map +1 -0
  145. package/dist/report/report.js +1968 -0
  146. package/dist/report/report.js.map +1 -0
  147. package/dist/report/run.d.ts +87 -0
  148. package/dist/report/run.d.ts.map +1 -0
  149. package/dist/report/run.js +121 -0
  150. package/dist/report/run.js.map +1 -0
  151. package/dist/report/section.d.ts +86 -0
  152. package/dist/report/section.d.ts.map +1 -0
  153. package/dist/report/section.js +325 -0
  154. package/dist/report/section.js.map +1 -0
  155. package/dist/report/subreport.d.ts +49 -0
  156. package/dist/report/subreport.d.ts.map +1 -0
  157. package/dist/report/subreport.js +220 -0
  158. package/dist/report/subreport.js.map +1 -0
  159. package/dist/util/base64.d.ts +9 -0
  160. package/dist/util/base64.d.ts.map +1 -0
  161. package/dist/util/base64.js +60 -0
  162. package/dist/util/base64.js.map +1 -0
  163. package/dist/util/chars.d.ts +45 -0
  164. package/dist/util/chars.d.ts.map +1 -0
  165. package/dist/util/chars.js +194 -0
  166. package/dist/util/chars.js.map +1 -0
  167. package/dist/util/compositeformat.d.ts +3 -0
  168. package/dist/util/compositeformat.d.ts.map +1 -0
  169. package/dist/util/compositeformat.js +99 -0
  170. package/dist/util/compositeformat.js.map +1 -0
  171. package/dist/util/culture.d.ts +84 -0
  172. package/dist/util/culture.d.ts.map +1 -0
  173. package/dist/util/culture.js +59 -0
  174. package/dist/util/culture.js.map +1 -0
  175. package/dist/util/cultures.generated.d.ts +3 -0
  176. package/dist/util/cultures.generated.d.ts.map +1 -0
  177. package/dist/util/cultures.generated.js +1043 -0
  178. package/dist/util/cultures.generated.js.map +1 -0
  179. package/dist/util/dateformat.d.ts +21 -0
  180. package/dist/util/dateformat.d.ts.map +1 -0
  181. package/dist/util/dateformat.js +439 -0
  182. package/dist/util/dateformat.js.map +1 -0
  183. package/dist/util/dateparse.d.ts +12 -0
  184. package/dist/util/dateparse.d.ts.map +1 -0
  185. package/dist/util/dateparse.js +1212 -0
  186. package/dist/util/dateparse.js.map +1 -0
  187. package/dist/util/datetime.d.ts +70 -0
  188. package/dist/util/datetime.d.ts.map +1 -0
  189. package/dist/util/datetime.js +265 -0
  190. package/dist/util/datetime.js.map +1 -0
  191. package/dist/util/decimal.d.ts +54 -0
  192. package/dist/util/decimal.d.ts.map +1 -0
  193. package/dist/util/decimal.js +365 -0
  194. package/dist/util/decimal.js.map +1 -0
  195. package/dist/util/delphitext.d.ts +40 -0
  196. package/dist/util/delphitext.d.ts.map +1 -0
  197. package/dist/util/delphitext.js +408 -0
  198. package/dist/util/delphitext.js.map +1 -0
  199. package/dist/util/doubleutil.d.ts +30 -0
  200. package/dist/util/doubleutil.d.ts.map +1 -0
  201. package/dist/util/doubleutil.js +651 -0
  202. package/dist/util/doubleutil.js.map +1 -0
  203. package/dist/util/inflate.d.ts +7 -0
  204. package/dist/util/inflate.d.ts.map +1 -0
  205. package/dist/util/inflate.js +256 -0
  206. package/dist/util/inflate.js.map +1 -0
  207. package/dist/util/netexception.d.ts +59 -0
  208. package/dist/util/netexception.d.ts.map +1 -0
  209. package/dist/util/netexception.js +94 -0
  210. package/dist/util/netexception.js.map +1 -0
  211. package/dist/util/numberformat.d.ts +14 -0
  212. package/dist/util/numberformat.d.ts.map +1 -0
  213. package/dist/util/numberformat.js +828 -0
  214. package/dist/util/numberformat.js.map +1 -0
  215. package/dist/util/numberparse.d.ts +49 -0
  216. package/dist/util/numberparse.d.ts.map +1 -0
  217. package/dist/util/numberparse.js +568 -0
  218. package/dist/util/numberparse.js.map +1 -0
  219. package/dist/util/reportmanres.en.generated.d.ts +2 -0
  220. package/dist/util/reportmanres.en.generated.d.ts.map +1 -0
  221. package/dist/util/reportmanres.en.generated.js +2082 -0
  222. package/dist/util/reportmanres.en.generated.js.map +1 -0
  223. package/dist/util/reportmanres.es.generated.d.ts +2 -0
  224. package/dist/util/reportmanres.es.generated.d.ts.map +1 -0
  225. package/dist/util/reportmanres.es.generated.js +2082 -0
  226. package/dist/util/reportmanres.es.generated.js.map +1 -0
  227. package/dist/util/translator.d.ts +29 -0
  228. package/dist/util/translator.d.ts.map +1 -0
  229. package/dist/util/translator.js +79 -0
  230. package/dist/util/translator.js.map +1 -0
  231. package/dist/variant/coercion.d.ts +9 -0
  232. package/dist/variant/coercion.d.ts.map +1 -0
  233. package/dist/variant/coercion.js +298 -0
  234. package/dist/variant/coercion.js.map +1 -0
  235. package/dist/variant/context.d.ts +25 -0
  236. package/dist/variant/context.d.ts.map +1 -0
  237. package/dist/variant/context.js +22 -0
  238. package/dist/variant/context.js.map +1 -0
  239. package/dist/variant/variant.d.ts +193 -0
  240. package/dist/variant/variant.d.ts.map +1 -0
  241. package/dist/variant/variant.js +1229 -0
  242. package/dist/variant/variant.js.map +1 -0
  243. package/package.json +35 -4
  244. package/README.md +0 -3
@@ -0,0 +1,1968 @@
1
+ // Port of the runtime part of Reportman.Reporting.BaseReport and Report: a report while it is
2
+ // laid out into a metafile (BeginPrint, the parameters, the datasets, PrintNextPage with its
3
+ // sections, groups, page headers and footers, columns, skips and page counts, EndPrint).
4
+ //
5
+ // The operations that may reach the data host are Ops (see data/op.ts); the rest, as the
6
+ // evaluator, is synchronous.
7
+ import { MetaFile, MetaObjectDraw, MetaObjectImage, MetaObjectText, MetaObjectType, MetaPage, PageSizeDetail, } from '@reportman/metafile';
8
+ import { Evaluator } from '../eval/evaluator.js';
9
+ import { DatasetAlias } from '../eval/fields.js';
10
+ import { EvalIdentifiers, IdenVariableParam } from '../eval/identifiers.js';
11
+ import { fromBase64String } from '../util/base64.js';
12
+ import { toUpperNet, trimNet, replaceNet } from '../util/chars.js';
13
+ import { CultureInfo } from '../util/culture.js';
14
+ import { formatDateTime, utcTimeZone } from '../util/dateformat.js';
15
+ import { messageOf, NamedException, nullReferenceException, UnNamedException } from '../util/netexception.js';
16
+ import { formatDecimal, formatDouble, formatInteger } from '../util/numberformat.js';
17
+ import { convertDoubleToInt32, NumberStyles, parseInt32 } from '../util/numberparse.js';
18
+ import { Translator } from '../util/translator.js';
19
+ import { ParamType, Variant, VariantType } from '../variant/variant.js';
20
+ import { DriverType } from '@reportman/lib';
21
+ import { ReportDatabase } from '../data/databaseinfo.js';
22
+ import { ReportDataInfo, sqlParameterName, variantDbType, variantParameterValue } from '../data/datainfo.js';
23
+ import { NotSupportedYetError } from '../data/errors.js';
24
+ import { runSync, wait } from '../data/op.js';
25
+ import { ReportDataset } from '../data/reportdataset.js';
26
+ import { ReportParam } from '../params/param.js';
27
+ import { NoDataToPrintException, ReportException } from './errors.js';
28
+ import { IdenBarcodeOp, IdenEof, IdenGetValueFromSQL, IdenGraphicOp, IdenImageOp, IdenOrientationOp, IdenPageOp, IdenParamInfo, IdenReOpen, IdenReportVar, IdenSetLanguage, IdenTextHeight, IdenTextOp, } from './identifiers.js';
29
+ import { ExpressionItem, LabelItem, pt, ShapeItem, SubReportEvent, } from './items.js';
30
+ import { SectionRuntime, SectionType, SkipType } from './section.js';
31
+ import { ImageItem } from './imageitem.js';
32
+ import { SubReportRuntime } from './subreport.js';
33
+ import { barcodeOp, BarcodeItem } from './barcode/barcodeitem.js';
34
+ import { ChartItem } from './chart/chartitem.js';
35
+ import { IdenGraphicBounds, IdenGraphicClear, IdenGraphicColor, IdenGraphicNew, IdenGraphicNewFunction, IdenGraphicNewXY, IdenGraphicSerieColor, } from './chart/chartidens.js';
36
+ /** BaseReport.MAX_PAGENUM. */
37
+ export const MAX_PAGENUM = 100000;
38
+ const INT_MAX = 2147483647;
39
+ const MILIS_PROGRESS_DEFAULT = 500;
40
+ /** PageSizeType. */
41
+ var PageSizeType;
42
+ (function (PageSizeType) {
43
+ PageSizeType[PageSizeType["Default"] = 0] = "Default";
44
+ PageSizeType[PageSizeType["Custom"] = 1] = "Custom";
45
+ PageSizeType[PageSizeType["User"] = 2] = "User";
46
+ })(PageSizeType || (PageSizeType = {}));
47
+ /** A mutable context: the culture changes per page with the report language, as the thread culture. */
48
+ class RunContext {
49
+ culture;
50
+ translator;
51
+ timeZone;
52
+ now;
53
+ constructor(culture, translator, now, timeZone) {
54
+ this.culture = culture;
55
+ this.translator = translator;
56
+ this.now = now;
57
+ this.timeZone = timeZone;
58
+ }
59
+ }
60
+ /** The culture of a report language while a page prints (PrintNextPage), undefined to keep it. */
61
+ function languageCulture(language) {
62
+ switch (language) {
63
+ case 0:
64
+ return CultureInfo.get('en-US');
65
+ case 1:
66
+ return CultureInfo.get('es-ES');
67
+ case 2:
68
+ // C# parity: C# selects the neutral culture "ca"; its formats are those of ca-ES
69
+ return CultureInfo.get('ca-ES');
70
+ }
71
+ return undefined;
72
+ }
73
+ export class ReportRuntime {
74
+ model;
75
+ host;
76
+ translator;
77
+ context;
78
+ evalHost;
79
+ /** DataTable.Locale of the datasets (the culture when the report was prepared). */
80
+ locale;
81
+ invariant = CultureInfo.invariant;
82
+ onProgress;
83
+ // The model, at run time
84
+ params = [];
85
+ databases = [];
86
+ dataInfos = [];
87
+ subReports = [];
88
+ expressionItems = [];
89
+ chartItems = [];
90
+ /**
91
+ * ChartingDriver: the device that draws the charts instead of the device the report prints
92
+ * with (null: that device draws them, with its drawChart or else the vector chart).
93
+ */
94
+ chartingDriver = null;
95
+ /**
96
+ * Whether convertToDotNet converted the report from data drivers only the Delphi engine has
97
+ * (Zeos, IBX, FireDAC, BDE...): its parameters keep the meaning they have in Delphi.
98
+ */
99
+ convertedFromDelphi = false;
100
+ // BaseReport state
101
+ metaFile;
102
+ evaluator;
103
+ fLanguage;
104
+ fDataAlias = new DatasetAlias();
105
+ evalIdens;
106
+ openingDatasets = new Set();
107
+ fDriver = null;
108
+ errorProcessing = false;
109
+ lastErrorProcessing = '';
110
+ pendingSections = [];
111
+ fGroupHeaders = [];
112
+ gHeaders = [];
113
+ gFooters = [];
114
+ fTotalPages = [];
115
+ mmfirst = 0;
116
+ fCompose;
117
+ lastPage = false;
118
+ section = null;
119
+ subreport = null;
120
+ printing = false;
121
+ fRecordCount = 0;
122
+ currentSubReportIndex = 0;
123
+ currentSectionIndex = 0;
124
+ oldprintedsectionext = pt(0, 0);
125
+ oldsubreport = null;
126
+ havepagefooters = false;
127
+ sectionextevaluated = false;
128
+ oldprintedsection = null;
129
+ pageposx = 0;
130
+ pageposy = 0;
131
+ pagespacex = 0;
132
+ pagefooters = null;
133
+ asection = null;
134
+ pagefooterpos = 0;
135
+ sectionext = pt(0, 0);
136
+ fintpageindex = 0;
137
+ printedSomething = false;
138
+ pageNum = 0;
139
+ pageNumGroup = 0;
140
+ internalPageWidth = 0;
141
+ internalPageHeight = 0;
142
+ freeSpace = 0;
143
+ currentOrientation;
144
+ updatePageSize = false;
145
+ initialPageDetail = null;
146
+ /** ExecuteSubReportIndexes. */
147
+ executeSubReportIndexes;
148
+ pageSizeIndex;
149
+ constructor(model, options) {
150
+ this.model = model;
151
+ this.host = options.host;
152
+ this.locale = options.culture;
153
+ this.translator = options.translator ?? Translator.forCulture(options.culture);
154
+ this.evalHost = options.evalHost;
155
+ this.context = new RunContext(options.culture, this.translator, () => this.evalHost.now(), options.timeZone ?? utcTimeZone);
156
+ this.onProgress = options.onProgress;
157
+ this.executeSubReportIndexes = options.subReportIndexes ?? null;
158
+ this.fCompose = options.compose !== undefined;
159
+ this.metaFile = options.compose ?? new MetaFile();
160
+ this.fLanguage = model.language;
161
+ this.pageSizeIndex = model.pageSizeIndex;
162
+ this.currentOrientation = model.pageOrientation;
163
+ // MetaFile settings the C# property setters copy at load time
164
+ this.metaFile.linesPerInch = model.linesPerInch;
165
+ this.metaFile.printerSelect = model.printerSelect;
166
+ for (const db of model.databaseInfo)
167
+ this.databases.push(new ReportDatabase(this, db));
168
+ for (const di of model.dataInfo)
169
+ this.dataInfos.push(new ReportDataInfo(this, di));
170
+ for (const p of model.params)
171
+ this.params.push(new ReportParam(this, p));
172
+ this.buildSubReports();
173
+ const iden = (name, i) => [name, i];
174
+ const idens = [
175
+ iden('PAGE', new IdenReportVar(this, 'PAGE')),
176
+ iden('PAGINA', new IdenReportVar(this, 'PAGE')),
177
+ iden('LANGUAGE', new IdenReportVar(this, 'LANGUAGE')),
178
+ iden('PAGENUM', new IdenReportVar(this, 'PAGENUM')),
179
+ iden('PAGEWIDTH', new IdenReportVar(this, 'PAGEWIDTH')),
180
+ iden('PAGEHEIGHT', new IdenReportVar(this, 'PAGEHEIGHT')),
181
+ iden('FREE_SPACE_CMS', new IdenReportVar(this, 'FREE_SPACE_CMS')),
182
+ iden('FREE_SPACE_INCH', new IdenReportVar(this, 'FREE_SPACE_INCH')),
183
+ iden('FREE_SPACE_TWIPS', new IdenReportVar(this, 'FREE_SPACE_TWIPS')),
184
+ iden('CURRENTGROUP', new IdenReportVar(this, 'CURRENTGROUP')),
185
+ iden('CURRENTPOSX', new IdenReportVar(this, 'CURRENTPOSX')),
186
+ iden('CURRENTPOSY', new IdenReportVar(this, 'CURRENTPOSY')),
187
+ iden('FIRSTSECTION', new IdenReportVar(this, 'FIRSTSECTION')),
188
+ iden('EOF', new IdenEof(this)),
189
+ iden('SETLANGUAGE', new IdenSetLanguage(this)),
190
+ iden('REOPEN', new IdenReOpen(this)),
191
+ iden('GRAPHICOP', new IdenGraphicOp(this)),
192
+ iden('IMAGEOP', new IdenImageOp(this)),
193
+ iden('BARCODEOP', new IdenBarcodeOp(this)),
194
+ iden('TEXTOP', new IdenTextOp(this)),
195
+ iden('TEXTHEIGHT', new IdenTextHeight(this)),
196
+ iden('PARAMINFO', new IdenParamInfo(this)),
197
+ iden('SETPAGESOURCE', new IdenPageOp(this)),
198
+ iden('SETPAGEORIENTATION', new IdenOrientationOp(this)),
199
+ iden('GETVALUEFROMSQL', new IdenGetValueFromSQL(this)),
200
+ iden('GRAPHICNEW', new IdenGraphicNew(this)),
201
+ iden('GRAPHICNEWXY', new IdenGraphicNewXY(this)),
202
+ iden('GRAPHICNEWFUNCTION', new IdenGraphicNewFunction(this)),
203
+ iden('GRAPHICCLEAR', new IdenGraphicClear(this)),
204
+ iden('GRAPHICCOLOR', new IdenGraphicColor(this)),
205
+ iden('GRAPHICSERIECOLOR', new IdenGraphicSerieColor(this)),
206
+ iden('GRAPHICBOUNDS', new IdenGraphicBounds(this)),
207
+ ];
208
+ this.evalIdens = new EvalIdentifiers(options.culture.name);
209
+ for (const [k, v] of idens)
210
+ this.evalIdens.add(k, v);
211
+ this.initEvaluator();
212
+ }
213
+ // -------------------------------------------------------------------------------------------
214
+ // Construction
215
+ buildSubReports() {
216
+ const byName = new Map();
217
+ for (const sm of this.model.subReports) {
218
+ const sub = new SubReportRuntime(this, sm);
219
+ this.subReports.push(sub);
220
+ byName.set(toUpperNet(sm.name), sub);
221
+ for (const secm of sm.sections) {
222
+ const sec = new SectionRuntime(this, secm);
223
+ sub.sections.push(sec);
224
+ if (!byName.has(toUpperNet(secm.name)))
225
+ byName.set(toUpperNet(secm.name), sec);
226
+ for (const cm of secm.components) {
227
+ const item = this.newItem(cm);
228
+ sec.components.push(item);
229
+ }
230
+ }
231
+ }
232
+ // Reload links (ReportReader): parents, child subreports and the subreport of each section
233
+ this.model.subReports.forEach((sm, i) => {
234
+ const sub = this.subReports[i];
235
+ if (sm.parentSub.length > 0)
236
+ sub.parentSubReport = byName.get(sm.parentSub) ?? null;
237
+ if (sm.parentSec.length > 0)
238
+ sub.parentSection = byName.get(sm.parentSec) ?? null;
239
+ sm.sections.forEach((secm, j) => {
240
+ const sec = sub.sections[j];
241
+ if (secm.childSubReportName.length > 0) {
242
+ const child = byName.get(secm.childSubReportName);
243
+ if (!(child instanceof SubReportRuntime))
244
+ throw new NamedException('ChildSubReport not found:' + secm.childSubReportName, secm.childSubReportName);
245
+ sec.childSubReport = child;
246
+ child.parentSection = sec;
247
+ // C# parity: the parent of a child subreport is set to the child itself (only tested for null)
248
+ child.parentSubReport = child;
249
+ }
250
+ if (secm.subReportName.length > 0)
251
+ sec.subReport = sub;
252
+ });
253
+ });
254
+ }
255
+ newItem(cm) {
256
+ switch (cm.className) {
257
+ case 'TRPLABEL':
258
+ return new LabelItem(this, cm);
259
+ case 'TRPEXPRESSION': {
260
+ const item = new ExpressionItem(this, cm);
261
+ this.expressionItems.push(item);
262
+ return item;
263
+ }
264
+ case 'TRPSHAPE':
265
+ return new ShapeItem(this, cm);
266
+ case 'TRPIMAGE':
267
+ return new ImageItem(this, cm);
268
+ case 'TRPBARCODE':
269
+ return new BarcodeItem(this, cm);
270
+ case 'TRPCHART': {
271
+ const item = new ChartItem(this, cm);
272
+ this.chartItems.push(item);
273
+ return item;
274
+ }
275
+ default:
276
+ throw new Error('Unknown report item class: ' + String(cm.className));
277
+ }
278
+ }
279
+ /** A new dataset buffer (DataInfo constructor: new ReportDataset). */
280
+ newDataset() {
281
+ return new ReportDataset(this.locale, () => this.context.culture, this.invariant, () => this.evalHost.now());
282
+ }
283
+ /** The current culture (changes per page with the report language). */
284
+ get culture() {
285
+ return this.context.culture;
286
+ }
287
+ get driver() {
288
+ return this.fDriver;
289
+ }
290
+ /** Language: the evaluator follows it. */
291
+ get language() {
292
+ return this.fLanguage;
293
+ }
294
+ set language(value) {
295
+ this.fLanguage = value;
296
+ if (this.evaluator !== undefined)
297
+ this.evaluator.language = value;
298
+ }
299
+ toUpper(s) {
300
+ return toUpperNet(s);
301
+ }
302
+ convertToInt32(value) {
303
+ return convertDoubleToInt32(value);
304
+ }
305
+ /** Int32.ToString(format) under the current culture, for the page counts. */
306
+ integerFormatter = (value, format) => formatInteger(value, format, this.context.culture.number, 32);
307
+ /** object.ToString() of a value of a dataset row, under the current culture. */
308
+ objectText(cell) {
309
+ const v = cell.value;
310
+ const nfi = this.context.culture.number;
311
+ switch (cell.type) {
312
+ case 'DBNull':
313
+ case 'Null':
314
+ return '';
315
+ case 'String':
316
+ return v;
317
+ case 'Int64':
318
+ case 'Int32':
319
+ case 'Byte':
320
+ return formatInteger(v, '', nfi);
321
+ case 'Double':
322
+ return formatDouble(v, '', nfi);
323
+ case 'Decimal':
324
+ return formatDecimal(v, '', nfi);
325
+ case 'Boolean':
326
+ return v ? 'True' : 'False';
327
+ case 'DateTime':
328
+ return formatDateTime(v, '', this.context.culture);
329
+ case 'Binary':
330
+ return 'System.Byte[]';
331
+ default:
332
+ return String(v);
333
+ }
334
+ }
335
+ paramIndexOf(alias) {
336
+ for (let i = 0; i < this.params.length; i++)
337
+ if (this.params[i].alias === alias)
338
+ return i;
339
+ return -1;
340
+ }
341
+ paramByAlias(alias) {
342
+ const i = this.paramIndexOf(alias);
343
+ return i < 0 ? null : this.params[i];
344
+ }
345
+ /** DataInfos.IndexOf: by alias, case-sensitive. */
346
+ dataInfoIndexOf(alias) {
347
+ // Ignoring the case, as Delphi (TRpDataInfoList.IndexOf): a subreport may name its dataset in
348
+ // other case than the dataset itself
349
+ for (let i = 0; i < this.dataInfos.length; i++)
350
+ if (this.dataInfos[i].alias === alias)
351
+ return i;
352
+ const upper = toUpperNet(alias);
353
+ for (let i = 0; i < this.dataInfos.length; i++)
354
+ if (toUpperNet(this.dataInfos[i].alias) === upper)
355
+ return i;
356
+ return -1;
357
+ }
358
+ dataInfoByAlias(alias) {
359
+ const i = this.dataInfoIndexOf(alias);
360
+ return i < 0 ? null : this.dataInfos[i];
361
+ }
362
+ /** DatabaseInfos.IndexOf: by alias. */
363
+ databaseIndexOf(alias) {
364
+ for (let i = 0; i < this.databases.length; i++)
365
+ if (this.databases[i].alias === alias)
366
+ return i;
367
+ return -1;
368
+ }
369
+ /** Moves a dataset to its next record (its details may execute again). */
370
+ *next(data) {
371
+ return yield* data.next();
372
+ }
373
+ // -------------------------------------------------------------------------------------------
374
+ // Evaluator, parameters, datasets
375
+ /** InitEvaluator: a new evaluator, its dataset needed event and language. */
376
+ initEvaluator() {
377
+ this.evaluator = new Evaluator({ context: this.context, host: this.evalHost, language: this.fLanguage });
378
+ this.evaluator.onDatasetNeeded = (args) => this.onDatasetNeeded(args.dataset);
379
+ this.evaluator.language = this.fLanguage;
380
+ }
381
+ /** A field of a dataset that is not open: the dataset opens (inside the evaluation). */
382
+ onDatasetNeeded(dataset) {
383
+ if (this.openingDatasets.has(dataset))
384
+ return;
385
+ this.openingDatasets.add(dataset);
386
+ try {
387
+ const dinfo = this.dataInfoByAlias(dataset);
388
+ if (dinfo !== null) {
389
+ if (dinfo.dataReader === null) {
390
+ this.updateParamsBeforeOpen(this.dataInfoIndexOf(dataset), true);
391
+ runSync(dinfo.connect(), 'Opening the dataset ' + dataset + ' from an expression');
392
+ }
393
+ }
394
+ }
395
+ finally {
396
+ this.openingDatasets.delete(dataset);
397
+ }
398
+ }
399
+ /** AddReportItemsToEvaluator: parameters, expression identifiers and the report identifiers. */
400
+ addReportItemsToEvaluator(ev) {
401
+ for (const p of this.params)
402
+ ev.addIden('M.' + p.alias, new IdenVariableParam(ev, p));
403
+ for (const item of this.expressionItems) {
404
+ if (item.identifier.length > 0) {
405
+ // EvalIdenExpression of C# keeps the evaluator of the report (for its error messages)
406
+ item.idenExpression.evalObject = ev;
407
+ ev.addVariable(item.identifier, item.idenExpression);
408
+ }
409
+ }
410
+ for (const c of this.chartItems)
411
+ if (c.identifier.length > 0)
412
+ ev.addVariable(c.identifier, c.idenChart);
413
+ for (const aname of this.evalIdens.keys) {
414
+ const i = this.evalIdens.get(aname);
415
+ if (aname !== 'EOF')
416
+ ev.addVariable(aname, i);
417
+ else
418
+ ev.addIden(aname, i);
419
+ }
420
+ }
421
+ /** InitializeParams: the report items in the evaluator and the value of every parameter. */
422
+ initializeParams() {
423
+ this.addReportItemsToEvaluator(this.evaluator);
424
+ const ctx = this.evaluator.context;
425
+ for (const p of this.params) {
426
+ p.updateInitialValue();
427
+ if (p.paramType === ParamType.ExpreB) {
428
+ const paramname = p.alias;
429
+ try {
430
+ if (p.value.varType !== VariantType.Null) {
431
+ const text = 'M.' + paramname + ':=(' + p.value.toString(ctx) + ')';
432
+ this.evaluator.evaluateText(text);
433
+ p.lastValue = this.evaluator.evaluateText(paramname);
434
+ }
435
+ }
436
+ catch (e) {
437
+ throw new ReportException(messageOf(e) + 'Parameter error:' + p.alias, p.name, 'Value');
438
+ }
439
+ }
440
+ else
441
+ p.lastValue = p.listValue;
442
+ }
443
+ this.evaluator.language = this.fLanguage;
444
+ }
445
+ /** UpdateInitialValues: the initial expressions evaluated (what a parameters form shows). */
446
+ updateInitialValues() {
447
+ this.initEvaluator();
448
+ this.addReportItemsToEvaluator(this.evaluator);
449
+ for (const p of this.params)
450
+ p.updateInitialValue();
451
+ }
452
+ /** RestoreInitialValues: the initial expressions back. */
453
+ restoreInitialValues() {
454
+ for (const p of this.params)
455
+ p.restoreInitialValue();
456
+ }
457
+ /** CheckParameters: the alias of the first parameter whose validation fails ("" when none). */
458
+ checkParameters() {
459
+ let aresult = '';
460
+ this.initEvaluator();
461
+ this.addReportItemsToEvaluator(this.evaluator);
462
+ for (const p of this.params) {
463
+ p.updateInitialValue();
464
+ if (p.paramType !== ParamType.ExpreB)
465
+ p.lastValue = p.listValue;
466
+ }
467
+ for (const p of this.params) {
468
+ const validation = trimNet(p.validation);
469
+ if (validation.length > 0) {
470
+ const evalresult = this.evaluator.evaluateText(validation);
471
+ if (!evalresult.isNull) {
472
+ if (evalresult.isBoolean()) {
473
+ if (!evalresult.toBool(this.evaluator.context)) {
474
+ aresult = p.alias;
475
+ break;
476
+ }
477
+ }
478
+ }
479
+ }
480
+ }
481
+ return aresult;
482
+ }
483
+ /** UpdateParamsBeforeOpen: the expressions to evaluate before a dataset opens. */
484
+ updateParamsBeforeOpen(index, doeval) {
485
+ const ctx = this.evaluator.context;
486
+ const alias = this.dataInfos[index].alias;
487
+ for (const aparam of this.params) {
488
+ if (aparam.datasets.indexOf(alias) >= 0 && aparam.paramType === ParamType.ExpreB) {
489
+ const paramname = aparam.alias;
490
+ if (aparam.value.varType !== VariantType.Null) {
491
+ if (doeval) {
492
+ this.evaluator.evaluateText('M.' + paramname + ':=(' + aparam.value.toString(ctx) + ')');
493
+ aparam.lastValue = this.evaluator.evaluateText('M.' + paramname);
494
+ }
495
+ else
496
+ aparam.lastValue = this.evaluator.evaluateText(aparam.value.toString(ctx));
497
+ }
498
+ }
499
+ }
500
+ for (const aparam of this.params) {
501
+ if (aparam.datasets.indexOf(alias) >= 0 &&
502
+ (aparam.paramType === ParamType.SubstExpre || aparam.paramType === ParamType.SubsExpreList)) {
503
+ const paramname = aparam.alias;
504
+ if (aparam.value.varType !== VariantType.Null) {
505
+ if (doeval && this.convertedFromDelphi && aparam.paramType === ParamType.SubsExpreList) {
506
+ // A report of the Delphi engine, as Delphi (TRpBaseReport.UpdateParamsBeforeOpen): the value
507
+ // chosen in the list is the text to substitute, a string is quoted before it is evaluated
508
+ // ('N' stays 'N'). A report of this engine evaluates the value itself, as it always did
509
+ const v = aparam.value;
510
+ const text = v.varType === VariantType.String ? "'" + v.toString(ctx).split("'").join("''") + "'" : v.toString(ctx);
511
+ this.evaluator.evaluateText('M.' + paramname + ':=(' + text + ')');
512
+ aparam.lastValue = this.evaluator.evaluateText('M.' + paramname);
513
+ }
514
+ else if (doeval) {
515
+ const oldvalue = aparam.lastValue;
516
+ this.evaluator.evaluateText('M.' + paramname + ':=(' + aparam.value.toString(ctx) + ')');
517
+ aparam.lastValue = oldvalue;
518
+ }
519
+ else
520
+ aparam.lastValue = this.evaluator.evaluateText(aparam.value.toString(ctx));
521
+ }
522
+ }
523
+ }
524
+ }
525
+ updateParamsAfterOpen(index, doeval) {
526
+ const ctx = this.evaluator.context;
527
+ const alias = this.dataInfos[index].alias;
528
+ for (const aparam of this.params) {
529
+ if (aparam.datasets.indexOf(alias) >= 0 && aparam.paramType === ParamType.ExpreA) {
530
+ const paramname = aparam.alias;
531
+ if (aparam.value.varType !== VariantType.Null) {
532
+ if (doeval) {
533
+ this.evaluator.evaluateText('M.' + paramname + ':=(' + aparam.value.toString(ctx) + ')');
534
+ aparam.lastValue = this.evaluator.evaluateText('M.' + paramname);
535
+ }
536
+ else
537
+ aparam.lastValue = this.evaluator.evaluateText(aparam.value.toString(ctx));
538
+ }
539
+ }
540
+ }
541
+ }
542
+ prepareParamsAfterOpen() {
543
+ for (let i = 0; i < this.dataInfos.length; i++)
544
+ this.updateParamsAfterOpen(i, false);
545
+ const ctx = this.evaluator.context;
546
+ for (const aparam of this.params) {
547
+ if (aparam.paramType === ParamType.ExpreA && aparam.datasets.length === 0) {
548
+ const paramname = aparam.alias;
549
+ if (aparam.value.varType !== VariantType.Null) {
550
+ this.evaluator.evaluateText('M.' + paramname + ':=(' + aparam.value.toString(ctx) + ')');
551
+ aparam.lastValue = this.evaluator.evaluateText('M.' + paramname);
552
+ }
553
+ }
554
+ }
555
+ }
556
+ /** CheckIfDataAvailable: PrintOnlyIfDataAvailable and no subreport dataset has rows. */
557
+ checkIfDataAvailable() {
558
+ if (!this.model.printOnlyIfDataAvailable)
559
+ return;
560
+ let dataavail = false;
561
+ for (const sub of this.subReports) {
562
+ if (sub.alias.length > 0) {
563
+ const index = this.dataInfoIndexOf(sub.alias);
564
+ if (index >= 0) {
565
+ const data = this.dataInfos[index].data;
566
+ if (data.active && !data.eof) {
567
+ dataavail = true;
568
+ break;
569
+ }
570
+ }
571
+ }
572
+ }
573
+ if (!dataavail) {
574
+ this.metaFile.empty = true;
575
+ throw new NoDataToPrintException(this.translator.translateStr(799));
576
+ }
577
+ }
578
+ /** DeActivateDatasets: every dataset and connection closed (connections commit). */
579
+ *deActivateDatasets() {
580
+ for (const d of this.dataInfos) {
581
+ d.disConnect();
582
+ d.disConnectMem();
583
+ }
584
+ for (const db of this.databases)
585
+ yield* db.disConnect();
586
+ }
587
+ /** Every connection closed, HTTP agents too (the end of a run). */
588
+ *closeAll() {
589
+ yield* this.deActivateDatasets();
590
+ for (const db of this.databases)
591
+ yield* db.close(true);
592
+ }
593
+ /** SubreportMustBeExecuted: the ExecuteSubReportIndexes filter. */
594
+ subreportMustBeExecuted(nsubreport) {
595
+ const list = this.executeSubReportIndexes;
596
+ if (list === null || list.length === 0)
597
+ return true;
598
+ const idx = this.subReports.indexOf(nsubreport);
599
+ for (const index of list)
600
+ if (index === idx)
601
+ return true;
602
+ return false;
603
+ }
604
+ /** ActivateDatasets: the datasets that open on start. */
605
+ *activateDatasets() {
606
+ try {
607
+ for (const d of this.dataInfos)
608
+ d.sqlOverride = '';
609
+ for (let i = 0; i < this.dataInfos.length; i++) {
610
+ const dinfo = this.dataInfos[i];
611
+ dinfo.sqlOverride = '';
612
+ if (dinfo.openOnStart) {
613
+ let openDataset = true;
614
+ const list = this.executeSubReportIndexes;
615
+ if (list !== null && list.length > 0) {
616
+ openDataset = false;
617
+ for (const subrep of this.subReports) {
618
+ if (subrep.alias === dinfo.alias && this.subreportMustBeExecuted(subrep))
619
+ openDataset = true;
620
+ }
621
+ }
622
+ if (dinfo.dataReader === null && openDataset) {
623
+ this.updateParamsBeforeOpen(i, true);
624
+ yield* dinfo.connect();
625
+ }
626
+ }
627
+ }
628
+ for (const sub of this.subReports) {
629
+ const alias = sub.alias;
630
+ if (this.subreportMustBeExecuted(sub) && alias.length > 0) {
631
+ if (this.dataInfoIndexOf(alias) < 0)
632
+ throw new NamedException('Data alias not found:' + alias, alias);
633
+ }
634
+ }
635
+ }
636
+ catch (e) {
637
+ yield* this.deActivateDatasets();
638
+ throw e;
639
+ }
640
+ }
641
+ // -------------------------------------------------------------------------------------------
642
+ // Printing
643
+ checkProgress(finished) {
644
+ const mmlast = Date.now();
645
+ // C# parity: the milliseconds component of the elapsed time, not the total
646
+ const difmilis = (mmlast - this.mmfirst) % 1000;
647
+ if (difmilis >= MILIS_PROGRESS_DEFAULT || finished) {
648
+ this.mmfirst = Date.now();
649
+ if (this.onProgress !== undefined && this.onProgress(this.fRecordCount, this.metaFile.pages.currentCount) === true)
650
+ throw new UnNamedException(this.translator.translateStr(503));
651
+ }
652
+ }
653
+ /** AddTotalPagesItem: a text that prints the page count. */
654
+ addTotalPagesItem(apageindex, aobjectindex, adisplayformat) {
655
+ this.fTotalPages.push({ pageIndex: apageindex, objectIndex: aobjectindex, displayFormat: adisplayformat });
656
+ }
657
+ fillGlobalHeaders() {
658
+ this.gHeaders.length = 0;
659
+ this.gFooters.length = 0;
660
+ for (const subrep of this.subReports) {
661
+ let j = subrep.firstPageHeader;
662
+ for (let k = 0; k < subrep.pageHeaderCount; k++)
663
+ if (subrep.sections[j + k].global)
664
+ this.gHeaders.push(subrep.sections[j + k]);
665
+ j = subrep.firstPageFooter;
666
+ for (let k = 0; k < subrep.pageFooterCount; k++)
667
+ if (subrep.sections[j + k].global)
668
+ this.gFooters.push(subrep.sections[j + k]);
669
+ }
670
+ }
671
+ /** EndPrint: datasets closed, page counts written, the metafile finished. */
672
+ *endPrint() {
673
+ yield* this.deActivateDatasets();
674
+ this.section = null;
675
+ this.subreport = null;
676
+ this.printing = false;
677
+ this.fDriver = null;
678
+ this.metaFile.updateTotalPages(this.fTotalPages, this.integerFormatter);
679
+ this.metaFile.finish();
680
+ this.lastPage = true;
681
+ }
682
+ /**
683
+ * RequestPage: generates pages until the one asked for exists (every page for a two pass
684
+ * report); true when the report has finished.
685
+ */
686
+ *requestPage(pageindex) {
687
+ if (pageindex === INT_MAX)
688
+ pageindex--;
689
+ if (this.lastPage)
690
+ return true;
691
+ if (this.model.twoPass)
692
+ pageindex = INT_MAX - 1;
693
+ if (pageindex < this.metaFile.pages.currentCount)
694
+ return this.lastPage;
695
+ this.fintpageindex = pageindex;
696
+ yield* this.doPrintInternal();
697
+ return this.lastPage;
698
+ }
699
+ *doPrintInternal() {
700
+ if (!this.lastPage) {
701
+ this.checkProgress(false);
702
+ while (!(yield* this.printNextPage())) {
703
+ this.checkProgress(false);
704
+ if (this.pageNum > MAX_PAGENUM)
705
+ throw new UnNamedException('Maximum number of pages reached' + String(MAX_PAGENUM));
706
+ if (this.pageNum >= this.fintpageindex)
707
+ break;
708
+ if (this.lastPage)
709
+ break;
710
+ }
711
+ }
712
+ this.checkProgress(false);
713
+ }
714
+ updateChildSubreportIndexes() {
715
+ const list = this.executeSubReportIndexes;
716
+ if (list === null || list.length === 0)
717
+ return;
718
+ this.updateExecuteSubreportIndexes([...list], 0);
719
+ }
720
+ updateExecuteSubreportIndexes(subreportIndexes, recCount) {
721
+ recCount++;
722
+ if (recCount > 100)
723
+ throw new Error('Circular childsubreport reference');
724
+ const list = this.executeSubReportIndexes;
725
+ for (const idx of subreportIndexes) {
726
+ const subreport = this.subReports[idx];
727
+ if (subreport === undefined)
728
+ throw new RangeError('Index was out of range. Must be non-negative and less than the size of the collection.');
729
+ for (const sec of subreport.sections) {
730
+ if (sec.childSubReport !== null) {
731
+ const newIdx = this.subReports.indexOf(sec.childSubReport);
732
+ if (!list.includes(newIdx))
733
+ list.push(newIdx);
734
+ this.updateExecuteSubreportIndexes([newIdx], recCount);
735
+ }
736
+ }
737
+ }
738
+ }
739
+ /** DoUpdatePageSize: the page size of a page, asked to the device when it changes. */
740
+ doUpdatePageSize(page, detail) {
741
+ if (detail === null)
742
+ throw nullReferenceException();
743
+ const nd = new PageSizeDetail();
744
+ page.pageDetail = nd;
745
+ nd.paperSource = detail.paperSource;
746
+ nd.duplex = detail.duplex;
747
+ nd.forcePaperName = detail.forcePaperName;
748
+ nd.physicWidth = detail.physicWidth;
749
+ nd.physicHeight = detail.physicHeight;
750
+ page.orientation = this.currentOrientation;
751
+ nd.index = detail.index;
752
+ nd.custom = detail.custom;
753
+ if (detail.custom) {
754
+ nd.customWidth = detail.customWidth;
755
+ nd.customHeight = detail.customHeight;
756
+ }
757
+ if (!this.updatePageSize)
758
+ return;
759
+ page.updatedPageSize = true;
760
+ const driver = this.requireDriver();
761
+ driver.setOrientation(this.currentOrientation);
762
+ let apagesize;
763
+ if (this.model.pageSize !== PageSizeType.Default)
764
+ apagesize = driver.setPageSize(page.pageDetail);
765
+ else {
766
+ const r = driver.getPageSize();
767
+ apagesize = r.size;
768
+ this.pageSizeIndex = r.indexqt;
769
+ }
770
+ this.internalPageWidth = apagesize.x;
771
+ this.pagespacex = this.internalPageWidth;
772
+ this.internalPageHeight = apagesize.y;
773
+ }
774
+ requireDriver() {
775
+ if (this.fDriver === null)
776
+ throw nullReferenceException();
777
+ return this.fDriver;
778
+ }
779
+ /** BeginPrint: the metafile, the page size, the parameters and the datasets; the first section. */
780
+ *beginPrint(driver) {
781
+ const model = this.model;
782
+ const list = this.executeSubReportIndexes;
783
+ if (list !== null && list.length > 0)
784
+ this.updateChildSubreportIndexes();
785
+ if (!this.fCompose)
786
+ this.fTotalPages.length = 0;
787
+ yield* this.endPrint();
788
+ if (model.twoPass)
789
+ this.metaFile.forwardOnly = false;
790
+ this.mmfirst = Date.now();
791
+ this.fDriver = driver;
792
+ const meta = this.metaFile;
793
+ if (!this.fCompose) {
794
+ meta.clear();
795
+ meta.pdfConformance = model.pdfConformance;
796
+ meta.pdfCompressed = model.pdfCompressed;
797
+ meta.docAuthor = model.docAuthor ?? null;
798
+ meta.docProducer = model.docProducer ?? null;
799
+ meta.docCreator = model.docCreator ?? null;
800
+ meta.docCreationDate = model.docCreationDate ?? null;
801
+ meta.docModificationDate = model.docModificationDate ?? null;
802
+ meta.docSubject = model.docSubject ?? null;
803
+ meta.docKeywords = model.docKeywords ?? null;
804
+ meta.docTitle = model.docTitle ?? null;
805
+ meta.docXMPContent = model.docXMPContent ?? null;
806
+ }
807
+ for (const efile of model.embeddedFiles) {
808
+ if (efile.streamBase64 === undefined)
809
+ throw nullReferenceException();
810
+ meta.newEmbeddedFile(efile.fileName ?? '', efile.mimeType ?? '', efile.afRelationShip, efile.description ?? '', efile.creationDate ?? '', efile.modificationDate ?? '', fromBase64String(efile.streamBase64));
811
+ }
812
+ meta.empty = false;
813
+ try {
814
+ meta.printerFonts = model.printerFonts;
815
+ this.updatePageSize = false;
816
+ this.fillGlobalHeaders();
817
+ this.pendingSections.length = 0;
818
+ this.errorProcessing = false;
819
+ meta.printerSelect = model.printerSelect;
820
+ driver.selectPrinter(model.printerSelect);
821
+ if (this.fCompose) {
822
+ meta.forwardOnly = false;
823
+ this.internalPageWidth = meta.customX;
824
+ this.internalPageHeight = meta.customY;
825
+ this.pageNum = meta.pages.currentCount - 2;
826
+ }
827
+ else {
828
+ let apagesize;
829
+ meta.empty = false;
830
+ meta.printerFonts = model.printerFonts;
831
+ meta.previewAbout = model.previewAbout;
832
+ meta.previewMargins = model.previewMargins;
833
+ meta.linesPerInch = model.linesPerInch;
834
+ meta.paperSource = model.paperSource;
835
+ // Sets page orientation
836
+ this.currentOrientation = model.pageOrientation;
837
+ if (model.pageOrientation !== 0)
838
+ driver.setOrientation(model.pageOrientation);
839
+ const pageDetail = new PageSizeDetail();
840
+ this.initialPageDetail = pageDetail;
841
+ pageDetail.paperSource = model.paperSource;
842
+ pageDetail.duplex = model.duplex;
843
+ pageDetail.forcePaperName = model.forcePaperName ?? null;
844
+ if (model.pageSize !== PageSizeType.Default) {
845
+ if (model.pageSize === PageSizeType.User) {
846
+ meta.pageSizeIndex = -1;
847
+ pageDetail.index = meta.pageSizeIndex;
848
+ pageDetail.custom = true;
849
+ pageDetail.customHeight = model.customPageHeight;
850
+ pageDetail.customWidth = model.customPageWidth;
851
+ meta.customX = model.customPageWidth;
852
+ meta.customY = model.customPageHeight;
853
+ pageDetail.physicHeight = model.customPageHeight;
854
+ pageDetail.physicWidth = model.customPageWidth;
855
+ }
856
+ else {
857
+ meta.pageSizeIndex = this.pageSizeIndex;
858
+ pageDetail.index = this.pageSizeIndex;
859
+ pageDetail.custom = false;
860
+ pageDetail.customWidth = model.customPageWidth;
861
+ pageDetail.customHeight = model.customPageHeight;
862
+ meta.customX = model.customPageWidth;
863
+ meta.customY = model.customPageHeight;
864
+ pageDetail.physicHeight = model.customPageHeight;
865
+ pageDetail.physicWidth = model.customPageWidth;
866
+ }
867
+ apagesize = driver.setPageSize(pageDetail);
868
+ }
869
+ else {
870
+ const r = driver.getPageSize();
871
+ apagesize = r.size;
872
+ meta.pageSizeIndex = r.indexqt;
873
+ meta.customX = model.customPageWidth;
874
+ meta.customY = model.customPageHeight;
875
+ pageDetail.physicHeight = apagesize.y;
876
+ pageDetail.physicWidth = apagesize.x;
877
+ }
878
+ this.internalPageWidth = apagesize.x;
879
+ this.internalPageHeight = apagesize.y;
880
+ meta.orientation = model.pageOrientation;
881
+ meta.backColor = model.pageBackColor;
882
+ meta.customX = this.internalPageWidth;
883
+ meta.customY = this.internalPageHeight;
884
+ this.pageNum = -1;
885
+ }
886
+ meta.printerSelect = model.printerSelect;
887
+ meta.autoScale = model.autoScale;
888
+ meta.previewWindow = model.previewWindow;
889
+ meta.openDrawerAfter = model.actionAfter;
890
+ meta.openDrawerBefore = model.actionBefore;
891
+ for (const sub of this.subReports)
892
+ sub.lastRecord = false;
893
+ this.lastPage = false;
894
+ this.initEvaluator();
895
+ this.pageNumGroup = -1;
896
+ this.fRecordCount = 0;
897
+ this.initializeParams();
898
+ this.fDataAlias.list.length = 0;
899
+ for (const d of this.dataInfos)
900
+ this.fDataAlias.add(d.alias, d.data);
901
+ try {
902
+ yield* this.activateDatasets();
903
+ }
904
+ catch (e) {
905
+ yield* this.deActivateDatasets();
906
+ throw e;
907
+ }
908
+ this.checkIfDataAvailable();
909
+ this.evaluator.aliasList = this.fDataAlias;
910
+ this.prepareParamsAfterOpen();
911
+ for (const sub of this.subReports)
912
+ if (this.subreportMustBeExecuted(sub))
913
+ sub.subReportChanged(SubReportEvent.Start, '');
914
+ this.currentSubReportIndex = -1;
915
+ let dataavail = false;
916
+ do {
917
+ do {
918
+ this.currentSubReportIndex++;
919
+ } while (this.currentSubReportIndex < this.subReports.length &&
920
+ !this.subreportMustBeExecuted(this.subReports[this.currentSubReportIndex]));
921
+ if (this.currentSubReportIndex >= this.subReports.length)
922
+ break;
923
+ const subrep = this.subReports[this.currentSubReportIndex];
924
+ if (subrep.parentSubReport === null) {
925
+ if (subrep.alias.length === 0)
926
+ dataavail = true;
927
+ else if (subrep.printOnlyIfDataAvailable) {
928
+ const index = this.dataInfoIndexOf(subrep.alias);
929
+ if (!this.dataInfos[index].data.eof)
930
+ dataavail = true;
931
+ }
932
+ else
933
+ dataavail = true;
934
+ }
935
+ if (dataavail) {
936
+ subrep.subReportChanged(SubReportEvent.SubReportStart, '');
937
+ subrep.subReportChanged(SubReportEvent.DataChange, '');
938
+ this.currentSectionIndex = -1;
939
+ subrep.currentGroupIndex = -subrep.groupCount;
940
+ if (subrep.currentGroupIndex < 0)
941
+ this.currentSectionIndex = subrep.firstDetail + subrep.currentGroupIndex - 1;
942
+ this.section = null;
943
+ this.subreport = null;
944
+ if (!(yield* this.nextSection(true)))
945
+ dataavail = false;
946
+ }
947
+ } while (!dataavail);
948
+ if (!dataavail) {
949
+ yield* this.endPrint();
950
+ meta.empty = true;
951
+ throw new NoDataToPrintException(this.translator.translateStr(799));
952
+ }
953
+ this.printing = true;
954
+ }
955
+ catch (e) {
956
+ meta.empty = true;
957
+ throw e;
958
+ }
959
+ }
960
+ *nextSection(child) {
961
+ let searchGroupHeader = false;
962
+ const oldsection = this.section;
963
+ this.section = null;
964
+ // If the old selected section has a child subreport then execute first
965
+ if (oldsection !== null && child) {
966
+ if (oldsection.childSubReport !== null) {
967
+ let dataavail = false;
968
+ const subrep = oldsection.childSubReport;
969
+ if (subrep.alias.length === 0)
970
+ dataavail = true;
971
+ else {
972
+ const index = this.dataInfoIndexOf(subrep.alias);
973
+ if (index < 0)
974
+ throw new NamedException('Data alias not found:' + subrep.alias, subrep.alias);
975
+ const dinfo = this.dataInfos[index];
976
+ if (dinfo.dataSource.length === 0) {
977
+ if (dinfo.getDbItem().driver === DriverType.Mybase && dinfo.data.currentView !== null) {
978
+ // A dataset of the MyBase connection (a union) is not built again, its first row is
979
+ // the current one (as the Delphi engine does): its datasets were read already
980
+ dinfo.goFirstMem();
981
+ }
982
+ else {
983
+ dinfo.disConnect();
984
+ this.updateParamsBeforeOpen(index, true);
985
+ yield* dinfo.connect();
986
+ dinfo.goFirstMem();
987
+ }
988
+ }
989
+ else if (dinfo.data.eof) {
990
+ if (subrep.reOpenOnPrint) {
991
+ dinfo.disConnect();
992
+ this.updateParamsBeforeOpen(index, true);
993
+ yield* dinfo.connect();
994
+ dinfo.goFirstMem();
995
+ }
996
+ }
997
+ if (!dinfo.data.eof)
998
+ dataavail = true;
999
+ else
1000
+ searchGroupHeader = true;
1001
+ }
1002
+ subrep.lastRecord = !dataavail;
1003
+ if (dataavail || !subrep.printOnlyIfDataAvailable) {
1004
+ subrep.subReportChanged(SubReportEvent.SubReportStart, '');
1005
+ this.subreport = subrep;
1006
+ this.section = null;
1007
+ this.currentSectionIndex = -1;
1008
+ this.pendingSections.push(oldsection);
1009
+ this.currentSubReportIndex = this.subReports.indexOf(subrep);
1010
+ subrep.subReportChanged(SubReportEvent.DataChange, '');
1011
+ subrep.currentGroupIndex = -subrep.groupCount;
1012
+ if (subrep.currentGroupIndex < 0)
1013
+ this.currentSectionIndex = subrep.firstDetail + subrep.currentGroupIndex - 1;
1014
+ }
1015
+ }
1016
+ else
1017
+ searchGroupHeader = true;
1018
+ }
1019
+ else
1020
+ searchGroupHeader = true;
1021
+ if (this.fGroupHeaders.length === 0)
1022
+ searchGroupHeader = false;
1023
+ if (searchGroupHeader) {
1024
+ const index = oldsection === null ? -1 : this.fGroupHeaders.indexOf(oldsection);
1025
+ if (index >= 0) {
1026
+ this.fGroupHeaders.splice(index, 1);
1027
+ if (this.fGroupHeaders.length > 0) {
1028
+ this.section = this.fGroupHeaders[0];
1029
+ const asec = this.lastPending();
1030
+ this.currentSubReportIndex = this.subReportIndexOf(asec.subReport);
1031
+ if (this.currentSubReportIndex < 0)
1032
+ throw new UnNamedException('SubReport not found');
1033
+ this.subreport = this.section.subReport;
1034
+ }
1035
+ else {
1036
+ this.section = this.lastPending();
1037
+ this.currentSubReportIndex = this.subReportIndexOf(this.section.subReport);
1038
+ if (this.currentSubReportIndex < 0)
1039
+ throw new UnNamedException('SubReport not found');
1040
+ this.pendingSections.pop();
1041
+ this.subreport = this.section.subReport;
1042
+ this.currentSectionIndex = this.subreport.sections.indexOf(this.section);
1043
+ if (this.currentSectionIndex < 0)
1044
+ throw new UnNamedException('Section not found');
1045
+ }
1046
+ }
1047
+ }
1048
+ if (this.section !== null)
1049
+ return true;
1050
+ // Check the condition
1051
+ while (this.currentSubReportIndex < this.subReports.length) {
1052
+ this.checkProgress(false);
1053
+ let subrep = this.subReports[this.currentSubReportIndex];
1054
+ // The first section are the group footers until CurrentGroup
1055
+ while (subrep.currentGroupIndex !== 0) {
1056
+ this.checkProgress(false);
1057
+ const lastdetail = subrep.lastDetail;
1058
+ const firstdetail = subrep.firstDetail;
1059
+ this.currentSectionIndex++;
1060
+ if (subrep.currentGroupIndex > 0) {
1061
+ if (subrep.currentGroupIndex < this.currentSectionIndex - lastdetail) {
1062
+ // Restore position, and the next will be group headers
1063
+ if (subrep.lastRecord) {
1064
+ this.currentSectionIndex = subrep.sections.length;
1065
+ subrep.currentGroupIndex = 0;
1066
+ break;
1067
+ }
1068
+ else {
1069
+ // Send Messages for each group
1070
+ subrep.initGroups(subrep.currentGroupIndex);
1071
+ // Restores position
1072
+ yield* this.nextRecord(true);
1073
+ this.currentSectionIndex = subrep.firstDetail - subrep.currentGroupIndex;
1074
+ subrep.currentGroupIndex = -subrep.currentGroupIndex;
1075
+ const sec = this.sectionOf(subrep, this.currentSectionIndex);
1076
+ if (sec.evaluatePrintCondition()) {
1077
+ this.section = sec;
1078
+ this.subreport = subrep;
1079
+ break;
1080
+ }
1081
+ }
1082
+ }
1083
+ else {
1084
+ const sec = this.sectionOf(subrep, this.currentSectionIndex);
1085
+ if (sec.evaluatePrintCondition()) {
1086
+ this.section = sec;
1087
+ this.subreport = subrep;
1088
+ break;
1089
+ }
1090
+ }
1091
+ }
1092
+ else {
1093
+ // Group headers
1094
+ if (this.currentSectionIndex < firstdetail) {
1095
+ const sec = this.sectionOf(subrep, this.currentSectionIndex);
1096
+ if (sec.evaluatePrintCondition()) {
1097
+ this.section = sec;
1098
+ this.subreport = subrep;
1099
+ break;
1100
+ }
1101
+ }
1102
+ else {
1103
+ subrep.currentGroupIndex = 0;
1104
+ this.currentSectionIndex = -1;
1105
+ }
1106
+ }
1107
+ }
1108
+ if (this.section !== null)
1109
+ break;
1110
+ while (this.currentSectionIndex < subrep.sections.length) {
1111
+ this.checkProgress(false);
1112
+ if (this.currentSectionIndex < 0)
1113
+ this.currentSectionIndex = subrep.firstDetail;
1114
+ else
1115
+ this.currentSectionIndex++;
1116
+ if (!subrep.lastRecord) {
1117
+ if (this.currentSectionIndex > subrep.lastDetail) {
1118
+ if (yield* this.nextRecord(false)) {
1119
+ this.currentSectionIndex = subrep.lastDetail;
1120
+ break;
1121
+ }
1122
+ if (!subrep.lastRecord) {
1123
+ this.currentSectionIndex = subrep.firstDetail;
1124
+ const sec = this.sectionOf(subrep, this.currentSectionIndex);
1125
+ if (sec.evaluatePrintCondition()) {
1126
+ this.section = sec;
1127
+ this.subreport = subrep;
1128
+ break;
1129
+ }
1130
+ }
1131
+ else {
1132
+ this.currentSectionIndex = subrep.lastDetail;
1133
+ subrep.currentGroupIndex = subrep.groupCount;
1134
+ break;
1135
+ }
1136
+ }
1137
+ else if (this.currentSectionIndex <= subrep.lastDetail) {
1138
+ const sec = this.sectionOf(subrep, this.currentSectionIndex);
1139
+ if (sec.evaluatePrintCondition()) {
1140
+ this.section = sec;
1141
+ this.subreport = subrep;
1142
+ break;
1143
+ }
1144
+ }
1145
+ }
1146
+ }
1147
+ if (this.section === null && subrep.currentGroupIndex === 0) {
1148
+ // If it's a child subreport, returns null section so pending will print
1149
+ if (subrep.parentSubReport !== null)
1150
+ break;
1151
+ for (;;) {
1152
+ subrep.subReportChanged(SubReportEvent.SubReportEnd, '');
1153
+ do {
1154
+ this.currentSubReportIndex++;
1155
+ } while (this.currentSubReportIndex < this.subReports.length &&
1156
+ !this.subreportMustBeExecuted(this.subReports[this.currentSubReportIndex]));
1157
+ if (this.currentSubReportIndex >= this.subReports.length)
1158
+ break;
1159
+ subrep = this.subReports[this.currentSubReportIndex];
1160
+ if (subrep.parentSubReport === null) {
1161
+ if (subrep.isDataAvailable()) {
1162
+ subrep.subReportChanged(SubReportEvent.SubReportStart, '');
1163
+ subrep.subReportChanged(SubReportEvent.DataChange, '');
1164
+ break;
1165
+ }
1166
+ }
1167
+ }
1168
+ if (this.currentSubReportIndex >= this.subReports.length)
1169
+ break;
1170
+ this.currentSectionIndex = subrep.firstDetail - subrep.groupCount - 1;
1171
+ subrep.currentGroupIndex = -subrep.groupCount;
1172
+ subrep.lastRecord = false;
1173
+ }
1174
+ else if (subrep.currentGroupIndex === 0)
1175
+ break;
1176
+ }
1177
+ const aresult = this.section !== null;
1178
+ // If there are still pending sections
1179
+ if (this.section === null) {
1180
+ if (this.pendingSections.length > 0) {
1181
+ this.section = this.lastPending();
1182
+ this.currentSubReportIndex = this.subReportIndexOf(this.section.subReport);
1183
+ if (this.currentSubReportIndex < 0)
1184
+ throw new UnNamedException('Subreport not found');
1185
+ this.pendingSections.pop();
1186
+ this.subreport = this.section.subReport;
1187
+ this.currentSectionIndex = this.subreport.sections.indexOf(this.section);
1188
+ if (this.currentSectionIndex < 0)
1189
+ throw new UnNamedException('Subreport not found');
1190
+ yield* this.nextSection(false);
1191
+ }
1192
+ }
1193
+ return aresult;
1194
+ }
1195
+ lastPending() {
1196
+ const s = this.pendingSections[this.pendingSections.length - 1];
1197
+ if (s === undefined)
1198
+ throw new RangeError('Index was out of range. Must be non-negative and less than the size of the collection.');
1199
+ return s;
1200
+ }
1201
+ subReportIndexOf(sub) {
1202
+ return sub === null ? -1 : this.subReports.indexOf(sub);
1203
+ }
1204
+ sectionOf(subrep, index) {
1205
+ const s = subrep.sections[index];
1206
+ if (s === undefined)
1207
+ throw new RangeError('Index was out of range. Must be non-negative and less than the size of the collection.');
1208
+ return s;
1209
+ }
1210
+ skipToPageAndPosition() {
1211
+ const asection = this.asection;
1212
+ const ev = this.evaluator;
1213
+ const ctx = ev.context;
1214
+ let newposx = 0;
1215
+ let newposy = 0;
1216
+ try {
1217
+ // Go to page?
1218
+ if (asection.skipToPageExpre.length > 0) {
1219
+ if (!this.model.twoPass)
1220
+ throw new UnNamedException('Two pass report required for skip to feature');
1221
+ let newpage = convertDoubleToInt32(ev.evaluateText(asection.skipToPageExpre).toDouble(ctx));
1222
+ newpage = newpage - 1;
1223
+ if (newpage < 0)
1224
+ throw new UnNamedException('Can not combine skip to page');
1225
+ const meta = this.metaFile;
1226
+ while (newpage > meta.pages.currentCount) {
1227
+ meta.pages.add(new MetaPage(meta));
1228
+ const last = meta.pages.get(meta.pages.currentCount - 1);
1229
+ last.orientation = this.currentOrientation;
1230
+ this.doUpdatePageSize(last, last.pageDetail);
1231
+ this.checkProgress(false);
1232
+ }
1233
+ meta.currentPage = newpage;
1234
+ this.pageNum = meta.currentPage;
1235
+ }
1236
+ }
1237
+ catch (e) {
1238
+ throw new ReportException(messageOf(e), asection.name, 'SkipToPage');
1239
+ }
1240
+ let moveh = false;
1241
+ try {
1242
+ if (asection.skipExpreH.length > 0) {
1243
+ newposx = convertDoubleToInt32(ev.evaluateText(asection.skipExpreH).toDouble(ctx));
1244
+ moveh = true;
1245
+ }
1246
+ }
1247
+ catch (e) {
1248
+ throw new ReportException(messageOf(e), asection.name, 'SkipExpreH');
1249
+ }
1250
+ let movev = false;
1251
+ try {
1252
+ if (asection.skipExpreV.length > 0) {
1253
+ newposy = convertDoubleToInt32(ev.evaluateText(asection.skipExpreV).toDouble(ctx));
1254
+ movev = true;
1255
+ }
1256
+ }
1257
+ catch (e) {
1258
+ throw new ReportException(messageOf(e), asection.name, 'SkipExpreV');
1259
+ }
1260
+ if (moveh) {
1261
+ if (asection.skipRelativeH)
1262
+ this.pageposx = this.pageposx + newposx;
1263
+ else
1264
+ this.pageposx = newposx;
1265
+ }
1266
+ if (movev) {
1267
+ if (asection.skipRelativeV)
1268
+ this.pageposy = this.pageposy + newposy;
1269
+ else
1270
+ this.pageposy = newposy;
1271
+ }
1272
+ this.freeSpace = this.pagefooterpos - this.pageposy;
1273
+ if (this.freeSpace < 0)
1274
+ this.freeSpace = 0;
1275
+ }
1276
+ checkSpace() {
1277
+ if (this.freeSpace === 0)
1278
+ return false;
1279
+ const maxExtent = pt(this.pagespacex, this.freeSpace);
1280
+ const asection = this.asection;
1281
+ const driver = this.requireDriver();
1282
+ if (!this.sectionextevaluated) {
1283
+ // Skip to page and position
1284
+ if (asection.skipType === SkipType.Before)
1285
+ this.skipToPageAndPosition();
1286
+ this.sectionext = asection.getExtension(driver, maxExtent, false);
1287
+ }
1288
+ let aresult = true;
1289
+ if (this.sectionext.y > this.freeSpace) {
1290
+ if (this.printedSomething)
1291
+ aresult = false;
1292
+ else {
1293
+ // Force partial print for expressions
1294
+ this.sectionext = asection.getExtension(driver, maxExtent, true);
1295
+ if (this.sectionext.y > this.freeSpace)
1296
+ throw new UnNamedException('No Espace to print SubReport ' + String(this.currentSubReportIndex) + ' Section ' + String(this.currentSectionIndex));
1297
+ }
1298
+ }
1299
+ this.sectionextevaluated = false;
1300
+ return aresult;
1301
+ }
1302
+ printSection(datasection, partialPrint) {
1303
+ const section = this.section;
1304
+ const subreport = this.subreport;
1305
+ if (subreport.currentGroupIndex < 0) {
1306
+ if (section.groupName === this.sectionOf(subreport, subreport.firstDetail + subreport.currentGroupIndex).groupName) {
1307
+ if (section.iniNumPage)
1308
+ this.pageNumGroup = 0;
1309
+ section.firstPage = this.metaFile.currentPage;
1310
+ }
1311
+ }
1312
+ this.pagefooterpos = this.pageposy + this.freeSpace;
1313
+ partialPrint.value = false;
1314
+ const maxExtent = pt(this.pagespacex, this.freeSpace);
1315
+ const asection = this.asection;
1316
+ if (datasection) {
1317
+ let ispagerepeat = false;
1318
+ if (asection.sectionType === SectionType.GroupHeader)
1319
+ ispagerepeat = asection.pageRepeat;
1320
+ if (!ispagerepeat) {
1321
+ this.oldprintedsection = section;
1322
+ this.oldprintedsectionext = { ...this.sectionext };
1323
+ if (this.fGroupHeaders.length < 1)
1324
+ this.printedSomething = true;
1325
+ }
1326
+ }
1327
+ const driver = this.requireDriver();
1328
+ if (!asection.alignBottom) {
1329
+ asection.print(driver, this.pageposx, this.pageposy, -1, -1, this.metaFile, maxExtent, partialPrint);
1330
+ this.freeSpace = this.freeSpace - this.sectionext.y;
1331
+ this.pageposy = this.pageposy + this.sectionext.y;
1332
+ }
1333
+ else {
1334
+ // Align to bottom
1335
+ this.pageposy = this.pageposy + this.freeSpace - this.sectionext.y;
1336
+ asection.print(driver, this.pageposx, this.pageposy, -1, -1, this.metaFile, maxExtent, partialPrint);
1337
+ this.freeSpace = 0;
1338
+ }
1339
+ if (asection.skipType === SkipType.After)
1340
+ this.skipToPageAndPosition();
1341
+ }
1342
+ printFixedSections(headers) {
1343
+ const partialPrint = { value: false };
1344
+ const maxExtent = pt(this.pagespacex, this.freeSpace);
1345
+ const subreport = this.subreport;
1346
+ if (headers) {
1347
+ // First the global headers
1348
+ for (const psection of this.gHeaders) {
1349
+ if (psection.evaluatePrintCondition()) {
1350
+ this.asection = psection;
1351
+ this.checkSpace();
1352
+ this.printSection(false, partialPrint);
1353
+ }
1354
+ }
1355
+ // Print the header fixed sections
1356
+ const pheader = subreport.firstPageHeader;
1357
+ const pheadercount = subreport.pageHeaderCount;
1358
+ for (let i = 0; i < pheadercount; i++) {
1359
+ const psection = this.sectionOf(subreport, i + pheader);
1360
+ if (!psection.global) {
1361
+ if (psection.evaluatePrintCondition()) {
1362
+ this.asection = psection;
1363
+ this.checkSpace();
1364
+ this.printSection(false, partialPrint);
1365
+ }
1366
+ }
1367
+ }
1368
+ const psubreports = [];
1369
+ for (const psection of this.pendingSections) {
1370
+ // C# parity: the subreport of a section without one (null) is added as null
1371
+ const sub = psection.subReport;
1372
+ if (sub === null)
1373
+ throw nullReferenceException();
1374
+ if (psubreports.indexOf(sub) < 0)
1375
+ psubreports.push(sub);
1376
+ }
1377
+ if (psubreports.indexOf(subreport) < 0)
1378
+ psubreports.push(subreport);
1379
+ // Now prints repeated group headers
1380
+ for (const subrep of psubreports) {
1381
+ const afirstdetail = subrep.firstDetail;
1382
+ for (let i = subrep.groupCount; i > 0; i--) {
1383
+ const psection = this.sectionOf(subrep, afirstdetail - i);
1384
+ if (psection.pageRepeat) {
1385
+ let dopagerepeat = false;
1386
+ // Allways if there is another active subreport
1387
+ if (subrep !== subreport)
1388
+ dopagerepeat = true;
1389
+ else if (this.section !== psection) {
1390
+ // Never if the current section is just the group header
1391
+ if (this.currentSectionIndex > subrep.firstDetail - i) {
1392
+ // If the section is enclosed between the header and the footer
1393
+ if (psection.forcePrint) {
1394
+ if (this.currentSectionIndex <= subrep.lastDetail + i)
1395
+ dopagerepeat = true;
1396
+ }
1397
+ else if (this.currentSectionIndex < subrep.lastDetail + i)
1398
+ dopagerepeat = true;
1399
+ }
1400
+ }
1401
+ if (dopagerepeat && psection.evaluatePrintCondition()) {
1402
+ // Add group headers to be printed at the main print loop
1403
+ this.fGroupHeaders.push(psection);
1404
+ }
1405
+ }
1406
+ }
1407
+ }
1408
+ this.pagefooterpos = this.pageposy + this.freeSpace;
1409
+ // Reserve space for page footers: print conditions for footers are evaluated at the
1410
+ // begining of the page
1411
+ for (const psection of this.gFooters) {
1412
+ this.asection = psection;
1413
+ this.checkSpace();
1414
+ this.pagefooterpos = this.pageposy + this.freeSpace - this.sectionext.y;
1415
+ this.freeSpace = this.freeSpace - this.sectionext.y;
1416
+ }
1417
+ const pfooter = subreport.firstPageFooter;
1418
+ const pfootercount = subreport.pageFooterCount;
1419
+ for (let i = 0; i < pfootercount; i++) {
1420
+ const psection = this.sectionOf(subreport, i + pfooter);
1421
+ if (!psection.global) {
1422
+ this.asection = psection;
1423
+ this.havepagefooters = true;
1424
+ this.checkSpace();
1425
+ this.pagefooters.push(psection);
1426
+ this.pagefooterpos = this.pageposy + this.freeSpace - this.sectionext.y;
1427
+ this.freeSpace = this.freeSpace - this.sectionext.y;
1428
+ }
1429
+ }
1430
+ }
1431
+ else {
1432
+ // Print page footers
1433
+ const pagefooters = this.pagefooters;
1434
+ if (this.gFooters.length > 0 || pagefooters.length > 0) {
1435
+ this.pageposy = this.pagefooterpos;
1436
+ const driver = this.requireDriver();
1437
+ for (const asection of pagefooters) {
1438
+ this.asection = asection;
1439
+ if (!asection.global) {
1440
+ let printit = true;
1441
+ if (!asection.forcePrint && this.section === null)
1442
+ printit = false;
1443
+ if (printit && asection.evaluatePrintCondition()) {
1444
+ this.sectionext = asection.getExtension(driver, maxExtent, false);
1445
+ this.printSection(false, partialPrint);
1446
+ this.freeSpace = 0;
1447
+ }
1448
+ }
1449
+ }
1450
+ // Global page footers
1451
+ for (const asection of this.gFooters) {
1452
+ this.asection = asection;
1453
+ let printit = true;
1454
+ if (!asection.forcePrint && this.section === null)
1455
+ printit = false;
1456
+ if (printit && asection.evaluatePrintCondition()) {
1457
+ this.sectionext = asection.getExtension(driver, maxExtent, false);
1458
+ this.printSection(false, partialPrint);
1459
+ this.freeSpace = 0;
1460
+ }
1461
+ }
1462
+ }
1463
+ }
1464
+ }
1465
+ *nextRecord(grouprestore) {
1466
+ let aresult = false;
1467
+ const subrep = this.subReports[this.currentSubReportIndex];
1468
+ if (subrep.alias.length === 0)
1469
+ subrep.lastRecord = true;
1470
+ else {
1471
+ const index = this.dataInfoIndexOf(subrep.alias);
1472
+ if (index < 0)
1473
+ throw new NamedException('Alias not exists' + subrep.alias, subrep.alias);
1474
+ const data = this.dataInfos[index].data;
1475
+ yield* data.next();
1476
+ // If its the last record no group change
1477
+ if (!grouprestore)
1478
+ subrep.lastRecord = data.eof;
1479
+ if (!subrep.lastRecord) {
1480
+ if (!grouprestore) {
1481
+ subrep.groupChanged();
1482
+ if (subrep.currentGroupIndex > 0) {
1483
+ aresult = true;
1484
+ yield* data.prior();
1485
+ }
1486
+ else
1487
+ subrep.subReportChanged(SubReportEvent.DataChange, '');
1488
+ }
1489
+ else
1490
+ subrep.subReportChanged(SubReportEvent.DataChange, '');
1491
+ }
1492
+ this.fRecordCount++;
1493
+ this.checkProgress(false);
1494
+ }
1495
+ return aresult;
1496
+ }
1497
+ /** PrintNextPage: generates the next page; true when it is the last one. */
1498
+ *printNextPage() {
1499
+ if (this.errorProcessing)
1500
+ throw new UnNamedException('Error processing\n' + this.lastErrorProcessing);
1501
+ const meta = this.metaFile;
1502
+ this.pageNum++;
1503
+ this.pageNumGroup++;
1504
+ // Updates page size, and orientation
1505
+ if (meta.pages.currentCount <= this.pageNum) {
1506
+ if (this.model.twoPass)
1507
+ meta.forwardOnly = false;
1508
+ meta.pages.add(new MetaPage(meta));
1509
+ }
1510
+ meta.currentPage = this.pageNum;
1511
+ const pageDetail = this.initialPageDetail;
1512
+ this.doUpdatePageSize(meta.pages.get(meta.pages.currentCount - 1), pageDetail);
1513
+ this.fGroupHeaders.length = 0;
1514
+ this.printedSomething = false;
1515
+ if (this.section === null)
1516
+ throw new UnNamedException('Last sectoin reached');
1517
+ if (this.subreport !== null)
1518
+ for (const sub of this.subReports)
1519
+ sub.subReportChanged(SubReportEvent.PageChange, '');
1520
+ this.havepagefooters = false;
1521
+ this.sectionextevaluated = false;
1522
+ this.oldprintedsection = null;
1523
+ const model = this.model;
1524
+ if (!this.fCompose) {
1525
+ this.freeSpace = this.internalPageHeight;
1526
+ this.freeSpace = this.freeSpace - model.topMargin - model.bottomMargin;
1527
+ this.pageposy = model.topMargin;
1528
+ this.pageposx = model.leftMargin;
1529
+ }
1530
+ else {
1531
+ if (this.gHeaders.length > 0 || this.subreport.pageHeaderCount > 0) {
1532
+ meta.pages.add(new MetaPage(meta));
1533
+ this.pageNum++;
1534
+ meta.currentPage = meta.pages.currentCount - 1;
1535
+ this.freeSpace = this.internalPageHeight;
1536
+ this.freeSpace = this.freeSpace - model.topMargin - model.bottomMargin;
1537
+ this.pageposy = model.topMargin;
1538
+ this.pageposx = model.leftMargin;
1539
+ this.doUpdatePageSize(meta.pages.get(meta.pages.currentCount - 1), pageDetail);
1540
+ }
1541
+ else
1542
+ this.printedSomething = true;
1543
+ }
1544
+ this.pagespacex = this.internalPageWidth;
1545
+ let oldhorzdespposition = model.leftMargin;
1546
+ const oldculture = this.context.culture;
1547
+ // Change culture
1548
+ const pageCulture = languageCulture(this.fLanguage);
1549
+ if (pageCulture !== undefined)
1550
+ this.context.culture = pageCulture;
1551
+ this.pagefooters = [];
1552
+ try {
1553
+ const partialPrint = { value: false };
1554
+ // Fills the page with fixed sections
1555
+ this.printFixedSections(true);
1556
+ // Group headers with child subreports
1557
+ if (this.fGroupHeaders.length > 0) {
1558
+ this.pendingSections.push(this.section);
1559
+ this.section = this.fGroupHeaders[0];
1560
+ }
1561
+ this.oldsubreport = this.subreport;
1562
+ const lastvertpos = pt(this.pageposx, this.pageposy);
1563
+ while (this.section !== null) {
1564
+ const section = this.section;
1565
+ if (this.printedSomething) {
1566
+ if (section.evaluateBeginPage())
1567
+ break;
1568
+ }
1569
+ this.asection = section;
1570
+ const driver = this.requireDriver();
1571
+ // Horz.Desp.
1572
+ const oldprinted = this.oldprintedsection;
1573
+ if (oldprinted !== null) {
1574
+ if (oldprinted.horzDesp) {
1575
+ if (section.horzDesp) {
1576
+ const maxExtent = pt(this.pagespacex, this.freeSpace);
1577
+ this.sectionext = section.getExtension(driver, maxExtent, false);
1578
+ this.sectionextevaluated = true;
1579
+ if (this.pageposx + this.oldprintedsectionext.x + this.sectionext.x <= this.pagespacex) {
1580
+ this.pageposx = this.pageposx + this.oldprintedsectionext.x;
1581
+ this.pageposy = this.pageposy - this.oldprintedsectionext.y;
1582
+ this.freeSpace = this.freeSpace + this.oldprintedsectionext.y;
1583
+ }
1584
+ else
1585
+ this.pageposx = model.leftMargin;
1586
+ }
1587
+ else
1588
+ this.pageposx = oldhorzdespposition;
1589
+ }
1590
+ else
1591
+ oldhorzdespposition = this.pageposx;
1592
+ }
1593
+ if (!this.checkSpace()) {
1594
+ // If the current section have vert desp, do a vertical and horz. desp if possible
1595
+ if (section.vertDesp) {
1596
+ // Go to old vertical position if fits horizontally
1597
+ const maxExtent = pt(this.pagespacex, lastvertpos.y - model.bottomMargin);
1598
+ this.sectionext = section.getExtension(driver, maxExtent, false);
1599
+ this.sectionextevaluated = true;
1600
+ if (this.pageposx + this.sectionext.x * 2 <= this.pagespacex) {
1601
+ this.freeSpace = this.freeSpace + (this.pageposy - lastvertpos.y);
1602
+ this.pageposx = this.pageposx + this.sectionext.x;
1603
+ this.pageposy = lastvertpos.y;
1604
+ }
1605
+ else {
1606
+ this.pageposx = model.leftMargin;
1607
+ break;
1608
+ }
1609
+ if (!this.checkSpace())
1610
+ break;
1611
+ }
1612
+ else
1613
+ break;
1614
+ }
1615
+ partialPrint.value = false;
1616
+ this.printSection(true, partialPrint);
1617
+ if (!partialPrint.value) {
1618
+ if (!section.vertDesp) {
1619
+ lastvertpos.x = this.pageposx;
1620
+ lastvertpos.y = this.pageposy;
1621
+ }
1622
+ yield* this.nextSection(true);
1623
+ if (this.section !== null) {
1624
+ if (!this.section.vertDesp) {
1625
+ lastvertpos.x = this.pageposx;
1626
+ lastvertpos.y = this.pageposy;
1627
+ }
1628
+ }
1629
+ }
1630
+ if (this.printedSomething) {
1631
+ if (this.asection.skipPage)
1632
+ break;
1633
+ }
1634
+ // if Subreport changed and has have pagefooter
1635
+ if (this.oldsubreport !== this.subreport && this.havepagefooters)
1636
+ break;
1637
+ this.oldsubreport = this.subreport;
1638
+ }
1639
+ // Fills the page with fixed sections
1640
+ if (this.printedSomething) {
1641
+ const oldprinted = this.oldprintedsection;
1642
+ if (oldprinted !== null && oldprinted.horzDesp)
1643
+ this.pageposx = oldhorzdespposition;
1644
+ }
1645
+ this.printFixedSections(false);
1646
+ this.pagefooters = null;
1647
+ this.context.culture = oldculture;
1648
+ }
1649
+ catch (e) {
1650
+ this.context.culture = oldculture;
1651
+ this.pagefooters = null;
1652
+ this.errorProcessing = true;
1653
+ this.lastErrorProcessing = messageOf(e);
1654
+ throw e;
1655
+ }
1656
+ const aresult = this.section === null;
1657
+ this.lastPage = aresult;
1658
+ if (this.lastPage) {
1659
+ meta.finish();
1660
+ this.checkProgress(true);
1661
+ }
1662
+ if (aresult)
1663
+ yield* this.endPrint();
1664
+ return aresult;
1665
+ }
1666
+ // -------------------------------------------------------------------------------------------
1667
+ // The operations of the report identifiers
1668
+ graphicOp(left, top, width, height, drawStyle, brushStyle, brushColor, penStyle, penWidth, penColor) {
1669
+ const obj = new MetaObjectDraw();
1670
+ obj.metaType = MetaObjectType.Draw;
1671
+ obj.top = top;
1672
+ obj.left = left;
1673
+ obj.height = height;
1674
+ obj.width = width;
1675
+ obj.drawStyle = drawStyle;
1676
+ obj.brushStyle = brushStyle;
1677
+ obj.brushColor = brushColor;
1678
+ obj.penStyle = penStyle;
1679
+ obj.penWidth = penWidth;
1680
+ obj.penColor = penColor;
1681
+ this.metaFile.pages.get(this.metaFile.currentPage).objects.push(obj);
1682
+ return true;
1683
+ }
1684
+ orientationOp(orientation) {
1685
+ if (orientation < 0 || orientation > 2)
1686
+ throw new UnNamedException('Invalid page orientation');
1687
+ this.currentOrientation = orientation;
1688
+ this.updatePageSize = true;
1689
+ const meta = this.metaFile;
1690
+ const page = meta.pages.get(meta.pages.currentCount - 1);
1691
+ this.doUpdatePageSize(page, page.pageDetail);
1692
+ }
1693
+ pageOp(pageIndex, custom, customwidth, customheight, papersource, forcepapername, duplex) {
1694
+ const meta = this.metaFile;
1695
+ // C# parity: Pages.Count generates every page first (a request of every page from inside an
1696
+ // expression); a page not generated yet is not supported here
1697
+ if (pageIndex >= meta.pages.currentCount && !meta.finished)
1698
+ throw new NotSupportedYetError('SETPAGESOURCE for a page that is not generated yet (page ' + String(pageIndex) + ')');
1699
+ if (pageIndex < meta.pages.currentCount) {
1700
+ const page = meta.pages.get(pageIndex);
1701
+ page.updatedPageSize = true;
1702
+ const d = page.pageDetail;
1703
+ // C# parity: the report's Duplex, not the one given
1704
+ void duplex;
1705
+ d.duplex = this.model.duplex;
1706
+ d.index = pageIndex;
1707
+ d.custom = custom;
1708
+ d.customHeight = customheight;
1709
+ d.customWidth = customwidth;
1710
+ d.paperSource = papersource;
1711
+ d.forcePaperName = forcepapername;
1712
+ }
1713
+ return true;
1714
+ }
1715
+ imageOp(left, top, width, height, drawStyle, dpires, previewOnly, image) {
1716
+ const astream = this.evaluator.getStreamFromExpression(image);
1717
+ if (astream !== null) {
1718
+ const obj = new MetaObjectImage();
1719
+ obj.metaType = MetaObjectType.Image;
1720
+ obj.top = top;
1721
+ obj.left = left;
1722
+ obj.height = height;
1723
+ obj.width = width;
1724
+ obj.drawImageStyle = drawStyle;
1725
+ obj.dpiRes = dpires;
1726
+ obj.previewOnly = previewOnly;
1727
+ const page = this.metaFile.pages.get(this.metaFile.currentPage);
1728
+ obj.streamPos = page.addStream(astream, false);
1729
+ obj.streamSize = astream.length;
1730
+ page.objects.push(obj);
1731
+ }
1732
+ // C# parity: ImageOp returns false
1733
+ return false;
1734
+ }
1735
+ /** BarcodeOp (BARCODEOP): a barcode drawn in the current page (barcode/barcodeitem.ts). */
1736
+ barcodeOp(left, top, width, height, expression, displayFormat, barType, modul, ratio, rotation, calcChecksum, brushColor) {
1737
+ return barcodeOp(this, left, top, width, height, expression, displayFormat, barType, modul, ratio, rotation, calcChecksum, brushColor);
1738
+ }
1739
+ textOp(left, top, width, height, text, lFontName, wFontName, fontSize, fontRotation, fontStyle, fontColor, type1Font, cutText, alignment, wordWrap, rightToLeft, printStep, backColor, transparent) {
1740
+ const obj = new MetaObjectText();
1741
+ obj.left = left;
1742
+ obj.top = top;
1743
+ obj.height = height;
1744
+ obj.width = width;
1745
+ obj.fontSize = (fontSize << 16) >> 16;
1746
+ obj.fontRotation = (fontRotation << 16) >> 16;
1747
+ obj.fontStyle = (fontStyle << 16) >> 16;
1748
+ obj.fontColor = fontColor;
1749
+ obj.rightToLeft = rightToLeft;
1750
+ obj.cutText = cutText;
1751
+ obj.alignment = alignment;
1752
+ obj.wordWrap = wordWrap;
1753
+ obj.printStep = printStep;
1754
+ obj.backColor = backColor;
1755
+ obj.transparent = transparent;
1756
+ obj.type1Font = type1Font;
1757
+ const page = this.metaFile.pages.get(this.metaFile.currentPage);
1758
+ obj.textP = page.addString(text);
1759
+ obj.textS = text.length;
1760
+ obj.lFontNameP = page.addString(lFontName);
1761
+ obj.lFontNameS = lFontName.length;
1762
+ obj.wFontNameP = page.addString(wFontName);
1763
+ obj.wFontNameS = wFontName.length;
1764
+ page.objects.push(obj);
1765
+ return true;
1766
+ }
1767
+ textHeightOp(text, lFontName, _wFontName, recWidth, fontSize, fontStyle, type1Font, printStep) {
1768
+ const extent = this.requireDriver().textExtent({
1769
+ text,
1770
+ lFontName,
1771
+ // C# parity: the report's default Windows font, not the one given (a misspelt argument)
1772
+ wFontName: this.model.wFontName,
1773
+ fontSize: (fontSize << 16) >> 16,
1774
+ fontRotation: 0,
1775
+ fontStyle: (fontStyle << 16) >> 16,
1776
+ fontColor: 0,
1777
+ type1Font,
1778
+ cutText: false,
1779
+ alignment: 0,
1780
+ wordWrap: true,
1781
+ rightToLeft: false,
1782
+ printStep,
1783
+ isHtml: false,
1784
+ }, pt(recWidth, 0));
1785
+ return extent.y;
1786
+ }
1787
+ paramInfoOp(paramName, index) {
1788
+ const ctx = this.evaluator.context;
1789
+ let aresult = Variant.fromString('');
1790
+ const ind0 = this.paramIndexOf(toUpperNet(paramName));
1791
+ if (ind0 < 0)
1792
+ throw new NamedException('Parameter not found:' + paramName, paramName);
1793
+ const param = this.params[ind0];
1794
+ const textOf = (v) => v.toString(ctx);
1795
+ // aresult + "\n" + s (values of a multiple selection) or aresult + (char)10 + s (the others)
1796
+ const append = (s, sep) => {
1797
+ if (textOf(aresult).length > 0) {
1798
+ const separator = sep === 'char' ? Variant.fromChar(10) : Variant.fromString('\n');
1799
+ aresult = Variant.add(Variant.add(aresult, separator, ctx), Variant.fromString(s), ctx);
1800
+ }
1801
+ else
1802
+ aresult = Variant.fromString(s);
1803
+ };
1804
+ const toIndex = (s) => parseInt32(s, NumberStyles.Integer, ctx.culture.number);
1805
+ const datasetsAndTexts = () => {
1806
+ switch (index) {
1807
+ case 6:
1808
+ for (const d of param.datasets)
1809
+ append(d, 'char');
1810
+ return true;
1811
+ case 7:
1812
+ aresult = Variant.fromString(param.description);
1813
+ return true;
1814
+ case 8:
1815
+ aresult = Variant.fromString(param.hint);
1816
+ return true;
1817
+ case 9:
1818
+ aresult = Variant.fromString(param.errorMessage);
1819
+ return true;
1820
+ case 10:
1821
+ aresult = Variant.fromString(param.validation);
1822
+ return true;
1823
+ }
1824
+ return false;
1825
+ };
1826
+ const pt2 = param.paramType;
1827
+ if (pt2 === ParamType.Multiple || pt2 === ParamType.List || pt2 === ParamType.SubsExpreList) {
1828
+ switch (index) {
1829
+ case 0:
1830
+ aresult = param.lastValue;
1831
+ break;
1832
+ case 1:
1833
+ if (pt2 === ParamType.Multiple) {
1834
+ for (const s of param.selected) {
1835
+ const ind = toIndex(s);
1836
+ if (param.values.length > ind)
1837
+ append(param.values[ind], 'string');
1838
+ }
1839
+ }
1840
+ else
1841
+ aresult = param.listValue;
1842
+ break;
1843
+ case 2:
1844
+ if (pt2 === ParamType.Multiple) {
1845
+ for (const s of param.selected)
1846
+ append(String(toIndex(s)), 'char');
1847
+ }
1848
+ else
1849
+ aresult = Variant.fromString(param.listValue.toString(ctx));
1850
+ break;
1851
+ case 3:
1852
+ if (pt2 === ParamType.Multiple) {
1853
+ for (const s of param.selected) {
1854
+ const ind = toIndex(s);
1855
+ if (param.items.length > ind)
1856
+ append(param.items[ind], 'char');
1857
+ }
1858
+ }
1859
+ else
1860
+ aresult = Variant.fromString(param.lastValue.toString(ctx));
1861
+ break;
1862
+ case 4:
1863
+ for (const s of param.items)
1864
+ append(s, 'char');
1865
+ break;
1866
+ case 5:
1867
+ for (const s of param.values)
1868
+ append(s, 'char');
1869
+ break;
1870
+ default:
1871
+ datasetsAndTexts();
1872
+ break;
1873
+ }
1874
+ }
1875
+ else if (!datasetsAndTexts())
1876
+ aresult = Variant.fromString(param.lastValue.toString(ctx));
1877
+ return aresult;
1878
+ }
1879
+ reOpenOp(datasetName, sql) {
1880
+ const index = this.dataInfoIndexOf(datasetName);
1881
+ if (index < 0)
1882
+ throw new NamedException('No data info found:' + datasetName, datasetName);
1883
+ const adata = this.dataInfos[index];
1884
+ adata.disConnect();
1885
+ // Evaluates from evaluator all parameters
1886
+ for (const p of this.params)
1887
+ p.lastValue = this.evaluator.evaluateText('M.' + p.alias);
1888
+ adata.sqlOverride = sql;
1889
+ runSync(adata.connect(), 'REOPEN of the dataset ' + datasetName);
1890
+ return true;
1891
+ }
1892
+ getSQLValueOp(connectionname, sql) {
1893
+ const index = this.databaseIndexOf(toUpperNet(connectionname));
1894
+ if (index < 0)
1895
+ throw new NamedException('Connection name not found:' + connectionname, connectionname);
1896
+ return runSync(this.getValueFromSQL(this.databases[index], sql), 'GETVALUEFROMSQL');
1897
+ }
1898
+ /**
1899
+ * DatabaseInfo.GetDataReaderFromSQL with the first column of the first row. As the commands of
1900
+ * the datasets, the command runs inside the implicit transaction of the connection (an HTTP agent
1901
+ * one through its executor); the result is read whole, as C# closes its reader at once.
1902
+ */
1903
+ *getValueFromSQL(db, sqlsentence) {
1904
+ yield* db.connect();
1905
+ // C# parity: Connection.CreateCommand; a Mybase connection has no Connection
1906
+ if (db.driver === DriverType.Mybase)
1907
+ throw nullReferenceException();
1908
+ const connection = db.connection;
1909
+ if (connection === null)
1910
+ throw nullReferenceException();
1911
+ const ctx = this.evaluator.context;
1912
+ const dataalias = '';
1913
+ for (const aparam of this.params) {
1914
+ switch (aparam.paramType) {
1915
+ case ParamType.Subst:
1916
+ case ParamType.Multiple:
1917
+ if (aparam.datasets.indexOf(dataalias) >= 0)
1918
+ sqlsentence = replaceNet(sqlsentence, aparam.search, aparam.value.toImplicitString(ctx) ?? '');
1919
+ break;
1920
+ case ParamType.SubstExpre:
1921
+ case ParamType.SubsExpreList:
1922
+ // C# parity: the datasets are searched for the alias of the connection, and the value
1923
+ // is evaluated by a new evaluator without the report's identifiers
1924
+ if (aparam.datasets.indexOf(db.alias) >= 0) {
1925
+ const ev = new Evaluator({ context: this.context, host: this.evalHost });
1926
+ ev.expression = aparam.value.toString(ctx);
1927
+ const nvalue = ev.evaluate().toString(ctx);
1928
+ sqlsentence = replaceNet(sqlsentence, aparam.search, nvalue);
1929
+ }
1930
+ break;
1931
+ }
1932
+ }
1933
+ const parameters = [];
1934
+ for (const aparam of this.params) {
1935
+ if (aparam.datasets.indexOf(dataalias) >= 0) {
1936
+ const t = aparam.paramType;
1937
+ if (t !== ParamType.Subst && t !== ParamType.Multiple && t !== ParamType.SubstExpre && t !== ParamType.SubsExpreList) {
1938
+ // C# parity: the value assigned is the Variant itself (no provider can bind it)
1939
+ const pv = variantParameterValue(aparam.value);
1940
+ parameters.push({ name: '@' + sqlParameterName(sqlsentence, aparam.alias), value: pv.value, valueType: 'Object', dbType: variantDbType(aparam.value) });
1941
+ }
1942
+ }
1943
+ }
1944
+ const result = yield* wait(connection.query({ sql: sqlsentence, parameters, dataset: dataalias }));
1945
+ const first = result.rows[0];
1946
+ if (first === undefined)
1947
+ return Variant.null;
1948
+ // Variant.AssignFromObject(reader[0]): the value as the reader gives it, by its type
1949
+ const value = first[0];
1950
+ if (value === null || value === undefined)
1951
+ return Variant.null;
1952
+ if (typeof value === 'number') {
1953
+ switch (result.columns[0]?.type) {
1954
+ case 'Int64':
1955
+ return Number.isInteger(value) ? Variant.fromLong(value) : Variant.fromDouble(value);
1956
+ case 'Int32':
1957
+ case 'Int16':
1958
+ return Number.isInteger(value) ? Variant.fromInteger(value) : Variant.fromDouble(value);
1959
+ case 'Byte':
1960
+ return Number.isInteger(value) ? Variant.fromByte(value) : Variant.fromDouble(value);
1961
+ default:
1962
+ return Variant.fromDouble(value);
1963
+ }
1964
+ }
1965
+ return Variant.fromHost(value);
1966
+ }
1967
+ }
1968
+ //# sourceMappingURL=report.js.map