Module ReportInformationCR.rv
1Use DfAllRpt.pkg
2Use Crystal\CheckForCrystal.dg
3Use dfrptvw.pkg
4Use Windows.pkg
5Use DfLine.Pkg
6Use cRichEdit.pkg
7Use File_dlg.Pkg
8Use cCrystal.pkg
9
10DEFERRED_VIEW Activate_oReportInformationCR FOR ;
11;
12Object oReportInformationCR is a ReportView
13
14 // This ReportView is a sample of the use of cCrystal.pkg. This package
15 // allows a connection to Crystal Reports by calling the RDC COM methods.
16 // It is based on Crystal Reports XI. This sample shows how to get information from
17 // a Crystal Report. It gets the selection formula, the sort order defintion
18 // and all formulas of the report.
19
20 Set Border_Style to Border_Thick
21 Set Label to "Report Information"
22 Set Location to 6 7
23 Set Size to 326 359
24 Set piMinSize to 326 359
25
26 Object oReportnameTextBox is a Textbox
27 Set Label to "Last report read:"
28 Set FontSize to 4 0
29 Set Location to 36 8
30 Set Size to 10 53
31 Set TypeFace to "MS Sans Serif"
32 End_Object // oReportnameTextBox
33
34 Object oReportNameForm is a Form
35 Set Label to "Crystal Report:"
36 Set Size to 13 244
37 Set Location to 10 56
38 Set peAnchors to anTopLeftRight
39 Set Label_Col_Offset to 2
40 Set Label_Justification_Mode to jMode_Right
41 Set Prompt_Button_Mode to pb_PromptOn
42
43 Procedure Entering
44 // clear information from previous report
45 Send ClearAllData
46
47 // clear report name
48 Set value to ""
49
50 // disable the run button
51 Set enabled_state of oRunButton to False
52 End_Procedure
53
54 // Sent when the prompt key is pressed, start selection list
55 Procedure Prompt
56 Integer iSelected iNumPaths
57 String sSelectedFile
58 String sDataDir
59
60 Get psDataPath of (phoWorkspace(ghoApplication)) to sDataDir
61 Get CountOfPaths of (phoWorkspace(ghoApplication)) sDataDir to iNumPaths
62 If (iNumPaths > 1) Get PathAtIndex of (phoWorkspace(ghoApplication)) sDataDir 1 to sDataDir
63 Set Initial_Folder of oNewDialog to sDataDir
64
65 // disable the run button
66 Set enabled_state of oRunButton to False
67
68 // Start the save as dialog
69 Get Show_Dialog of oNewDialog to iSelected
70 If iSelected Begin
71 Get File_Name of oNewDialog to sSelectedFile
72 Set Value to sSelectedFile
73 End
74 End_Procedure // Start_Prompt
75
76 End_Object // oReportNameForm
77
78 Object oReadReportButton is a Button
79 Set Label to "Read Report"
80 Set Size to 14 51
81 Set Location to 10 304
82 Set peAnchors to anTopRight
83 Set Default_State to True
84
85 Procedure OnClick
86 Boolean bReportOK bCrystalOK
87 String sReportName
88
89 Get Value of oReportNameForm to sReportName
90
91 // Check if the report name was specified and report actually exists
92 Get ValidateReportName sReportName to bReportOK
93 If (bReportOK) Begin
94 Get CheckCrystalEnvironment of oCheckForCrystal to bCrystalOK
95 If (bCrystalOK) Begin
96 Send ReadReport of oCrystalReport1 sReportName
97 End
98 Else Begin
99 Send DisplayDialog of oCheckForCrystal
100 End
101 End
102 Else Begin
103 Send activate of oReportNameForm
104 End
105
106 End_Procedure // OnClick
107
108 End_Object // oReadReportButton
109
110 Object oLineControl1 is a LineControl
111 Set Size to 2 349
112 Set Location to 26 6
113 Set peAnchors to anLeftRight
114
115 End_Object // oLineControl1
116
117 Object oSelectionEdit is a cRichEdit
118 Set Label to "Selection"
119 Set Size to 38 349
120 Set Location to 63 6
121 Set Color to clWhite
122 Set TextColor to clBlack
123 Set peAnchors to anLeftRight
124 Set Read_Only_State to True
125
126 End_Object // oSelectionEdit
127
128 Object oSortOrderList is a List
129 Set Label to "Sort Order"
130 Set Size to 52 349
131 Set Location to 114 6
132 Set peAnchors to anTopLeftRight
133 Set Label_Col_Offset to 0
134 Set Label_Row_Offset to 1
135 Set Label_Justification_Mode to jMode_Top
136
137 End_Object // oSortOrderList
138
139 Object oFormulas is a cRichEdit
140 Set Label to "Formulas"
141 Set Size to 52 349
142 Set Location to 180 6
143 Set Color to clWhite
144 Set TextColor to clBlack
145 Set peAnchors to anBottomLeftRight
146 Set Label_Col_Offset to -1
147 Set Read_Only_State to True
148
149 End_Object // oFormulas
150
151 Object oTablesAndFields is a cRichEdit
152 Set Size to 52 349
153 Set Location to 249 6
154 Set Label to "Tables and Fields"
155 End_Object
156
157 Object oRunButton is a Button
158 Set Label to "Run Report"
159 Set Location to 308 251
160 Set peAnchors to anBottomRight
161 Set Enabled_State to False
162
163 Procedure OnClick
164 Send RunReport of oCrystalReport1
165 End_Procedure // OnClick
166
167 End_Object // oRunButton
168
169 Object oCancelButton is a Button
170 Set Label to "Cancel"
171 Set Location to 308 304
172 Set peAnchors to anBottomRight
173
174 Procedure OnClick
175 Send Request_Cancel
176 End_Procedure // OnClick
177
178 End_Object // oCancelButton
179
180 Object oNewDialog is a OpenDialog
181 Set Dialog_Caption to "Select Crystal Report"
182 Set Filter_String to "Crystal Report (*.rpt)|*.rpt|All Files|*.*"
183 Set HideReadOnly_State to True
184
185 End_Object // oNewDialog
186
187 Object oCrystalReport1 is a cCrystal
188 Set psReportName to ""
189
190 Procedure ProcessReportData
191 Handle hoReport
192 Handle hoSortFields hoSortField hoField hoFormulas hoFormula
193 Integer iSortItem iSortCount iFormulaItem iFormulaCount
194 Boolean bAttached
195 String sRptTitle sSelection sCurSortField sCurFormName sCurFormContents
196 Variant vSortField vField vFormulaField
197 Handle hoGroups hoGroup
198 Variant vGroups vGroup
199 Integer iGroups iGroup
200
201 // for Tables and Fields
202 Handle hoDatabaseTable hoFieldDefinitions hoFieldDefinition
203 Handle[] hoTables
204 String sDLL sTableFullName sTableAliasName sFilePath sConnectString
205 String sFieldDisplayName sFieldName sTableAliasFieldIn
206 Integer iNumTables iTableItem iNumFields iFieldItem
207 Variant vFieldDefinitions vFieldDefinition
208 Boolean bSuccess
209
210
211 Get ReportObject to hoReport
212
213 // Show report title. If no title exists, just show file name
214 Get ComReportTitle of hoReport to sRptTitle
215 If (sRptTitle='') Get psReportName to sRptTitle
216 Set Label of oReportNameTextBox to ("Last report read:" * sRptTitle)
217
218 // Get Selection
219 Get ComRecordSelectionFormula of hoReport to sSelection
220 Send AppendText of oSelectionEdit sSelection
221
222 // Get sort order
223 // First show group sort fields, then regular sort fields
224 Get Create of hoReport U_cCrystalGroupNameFieldDefinitions to hoGroups
225 Get Create of hoReport U_cCrystalGroupNameFieldDefinition to hoGroup
226
227 Get ComGroupNameFields of hoReport to vGroups
228 Set pvComObject of hoGroups to vGroups
229 Get IsComObjectCreated of hoGroups to bAttached
230 If (bAttached) Begin
231 Get ComCount of hoGroups to iGroups
232 For iGroup From 1 to iGroups
233 Get ComItem of hoGroups iGroup to vGroup
234 Set pvComObject of hoGroup to vGroup
235 Get IsComObjectCreated of hoGroup to bAttached
236 If (bAttached) Begin
237 Get ComName of hoGroup to sCurSortField
238 Send Add_Item of oSortOrderList MSG_None sCurSortField
239 End
240 Loop
241 End
242
243 Get SortFieldsObject of hoReport to hoSortFields
244 If (hoSortFields) Begin
245 Get Create of hoSortFields U_cCrystalSortField to hoSortField
246 Get Create of hoSortFields U_cCrystalFieldObject to hoField
247 Get ComCount of hoSortFields to iSortCount
248 For iSortItem From 1 to iSortCount
249 Get ComItem of hoSortFields iSortItem to vSortField
250 Set pvComObject of hoSortField to vSortField
251 Get IsComObjectCreated of hoSortField to bAttached
252 If (bAttached) Begin
253 Get ComField of hoSortField to vField
254 Set pvComObject of hoField to vField
255 Get IsComObjectCreated of hoField to bAttached
256 If (bAttached) Begin
257 Get ComName of hoField to sCurSortField
258 Send Add_Item of oSortOrderList MSG_None sCurSortField
259 End
260 End
261 Loop
262 End
263
264 // Get formulas
265 Get FormulaFieldDefinitionsObject of hoReport to hoFormulas
266 If (hoFormulas) Begin
267 Get Create of hoFormulas U_cCrystalFormulaFieldDefinition to hoFormula
268 Get ComCount of hoFormulas to iFormulaCount
269 For iFormulaItem From 1 to iFormulaCount
270 Get ComItem of hoFormulas iFormulaItem to vFormulaField
271 Set pvComObject of hoFormula to vFormulaField
272 Get IsComObjectCreated of hoFormula to bAttached
273 If (bAttached) Begin
274 Get ComFormulaFieldName of hoFormula to sCurFormName
275 Get ComText of hoFormula to sCurFormContents
276 Send AppendText of oFormulas (sCurFormName + ":" + sCurFormContents +Character(10)+Character(13))
277 End
278 Loop
279 End
280
281
282
283
284 // Get Tables and Fields information
285 // Tables
286 Get TableObjects of hoReport to hoTables
287 Move (SizeOfArray(hoTables)) to iNumTables
288
289 // Loop through all tables
290 For iTableItem from 0 to (iNumTables-1)
291 Move hoTables[iTableItem] to hoDatabaseTable
292 If (hoDatabaseTable) Begin
293 Get ComConnectBufferString of hoDatabaseTable to sConnectString
294 Get ComDllName of hoDatabaseTable to sDLL
295 Get ComLocation of hoDatabaseTable to sTableFullName
296 Get ComName of hoDatabaseTable to sTableAliasName
297 Set pbBold of oTablesAndFields to True
298 Send AppendTextLn of oTablesAndFields ("Table Name:" * sTableFullName)
299 Send AppendTextLn of oTablesAndFields ("Alias Name:" * sTableAliasName)
300 Set pbBold of oTablesAndFields to False
301
302 // Read fields from table
303 Get Create of hoTables[iTableItem] U_cCrystalDatabaseFieldDefinitions to hoFieldDefinitions
304 Get ComFields of hoTables[iTableItem] to vFieldDefinitions
305 Set pvComObject of hoFieldDefinitions to vFieldDefinitions
306 Get IsComObjectCreated of hoFieldDefinitions to bAttached
307 If (bAttached) Begin
308 Get ComCount of hoFieldDefinitions to iNumFields
309
310 If (iNumFields > 0) Begin
311 Set pbBold of oTablesAndFields to True
312 Send AppendTextLn of oTablesAndFields ""
313 Send AppendTextLn of oTablesAndFields ("Fields from" * sTableAliasName - ":")
314 Set pbBold of oTablesAndFields to False
315 End
316
317 // loop through all fields from that table that are in the report
318 For iFieldItem from 1 to iNumFields
319 Get ComItem of hoFieldDefinitions item iFieldItem to vFieldDefinition
320 Get Create of hoFieldDefinitions U_cCrystalDatabaseFieldDefinition to hoFieldDefinition
321
322 Set pvComObject of hoFieldDefinition to vFieldDefinition
323 Get IsComObjectCreated of hoFieldDefinition to bAttached
324 If (bAttached) Begin
325 Get ComDatabaseFieldDisplayName of hoFieldDefinition to sFieldDisplayName
326 Get ComDatabaseFieldName of hoFieldDefinition to sFieldName
327 Get ComTableAliasName of hoFieldDefinition to sTableAliasFieldIn
328 Set peBullets of oTablesAndFields to buBullets
329 Send AppendTextln of oTablesAndFields ("Display Name:" * sFieldDisplayName)
330 Set peBullets of oTablesAndFields to buNone
331 Send AppendTextLn of oTablesAndFields ("Field Name:" * sFieldName)
332 Send AppendTextLn of oTablesAndFields ""
333
334 End
335 Loop
336
337 End
338
339 End
340
341 Loop
342
343
344
345 End_Procedure // ProcessReportData
346
347 Procedure ReadReport String sReportName
348 Boolean bReportOK
349 Boolean bOk
350
351 // Clear all child object
352 Send ClearAllData
353
354 // Setup the reportname and open the report so we can query information from it
355 Set psReportName to sReportName
356
357 Get OpenReport to bOk
358 If bOk Begin
359 Send ProcessReportData
360 Send CloseReport
361 Set enabled_state of oRunButton to True
362 End
363 End_Procedure // ReadReport
364
365 End_Object // oCrystalReport1
366
367 Procedure ClearAllData
368 Send Delete_Data of oSelectionEdit
369 Send Delete_Data of oSortOrderList
370 Send Delete_Data of oFormulas
371 End_Procedure
372
373 Function ReportExists String sRPTName Returns Boolean
374 Boolean bReportExists
375
376 // Check if the report actually exists
377 File_Exist sRPTName bReportExists
378
379 Function_Return bReportExists
380 End_Function
381
382 Function ValidateReportName String sReportName Returns Boolean
383 Boolean bReportNameOK
384
385 Move False to bReportNameOK
386
387 If (sReportName="") Begin
388 Send Info_Box "Select or specify a report." "Report Information"
389 End
390 Else Begin
391 Get ReportExists sReportName to bReportNameOK
392 If (not(bReportNameOK)) Begin
393 Send Info_Box ("The report file " + sReportName + " does not exist. Select or specify another one.") "Report Information"
394 End
395 End
396
397 Function_Return bReportNameOK
398 End_Function
399
400CD_End_Object // oReportInformationCR
401