Use Crystal\CheckForCrystal.dg Use dfrptvw.pkg Use DataDict.pkg Use dfRadio.pkg Use Windows.pkg Use dfCmbFrm.pkg Use File_dlg.Pkg Use cCrystal.pkg Use Customer.DD DEFERRED_VIEW Activate_oCustomerListCR FOR ; ; Object oCustomerListCR is a ReportView // This ReportView is a sample of the use of cCrystal.pkg. This package // allows a connection to Crystal Reports using COM Automation objects. // It is based on Crystal Reports XI or higher. The sample shows a simple // report in which the user can aplly the following actions: // - Adjust the sort order // - Adjust the selection. // - Adjust a formula in the report // - Select the output destination. (Window, Printer, or Disk) Set Label to "Customer List" Set Location to 2 3 Set Size to 216 380 Set piMinSize to 216 380 Object Customer_DD is a Customer_DataDictionary End_Object // Customer_DD Set Main_DD to Customer_DD Set Server to Customer_DD Object oSortOrderRadioGroup is a RadioGroup Set Size to 102 86 Set Location to 10 10 Set Label to "Sort Order" Object oNumberSortRadio is a Radio Set Label to "Sort by Number" Set Size to 10 65 Set Location to 13 10 End_Object // oNumberSortRadio Object oNameSortRadio is a Radio Set Label to "Sort by Name" Set Size to 10 59 Set Location to 27 10 End_Object // oNameSortRadio Object oDescAscCheckBox is a CheckBox Set Label to "Descending" Set Size to 10 55 Set Location to 82 10 End_Object // oDescAscCheckBox // Adjust the shadow of the boundary groups Procedure AdjustBoundaryShadow Integer iGroupNum Set Enabled_State of oNumberSelGroup to (iGroupNum = 0) Set Enabled_State of oNameSelGroup to (iGroupNum <> 0) End_Procedure // AdjustBoundaryShadow // Augemented to setup the output destination of the Crystal // Report. The procedure is sent when the user changes the // selection. Procedure Notify_Select_State Integer iNewItem Integer iOldItem Forward Send Notify_Select_State iNewItem iOldItem // Dynamically shadow the boundary groups Send AdjustBoundaryShadow iNewItem End_Procedure // Notify_Select_State // Returns the sort order selected by the user Function IsNameOrder Returns Boolean Integer iCurrent Get Current_radio to iCurrent Function_Return (iCurrent=1) End_Function // IsNameOrder // Returns if the sort order is descending or ascending Function IsDesc Returns Boolean Boolean bChecked Get Checked_state of oDescAscCheckBox to bChecked Function_Return bChecked End_Function // IsDesc End_Object // oSortOrderRadioGroup Object oNumberSelGroup is a Group Set Size to 49 275 Set Location to 10 101 Set Label to "Number Criteria" Object oStartCustNumber is a Form Set Label to "Start reporting at number:" Set Size to 13 85 Set Location to 10 92 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Form_DataType to 0 Set Prompt_Button_Mode to pb_PromptOn // The following code connects the customer selection list to this form Set Prompt_Object to Customer_sl // this is called by the prompt list upon initialization. This will let us // set special properties for the list's one time use. In this case we // want the intial column and the export column to be name (col 0) Procedure Prompt_Callback Integer hPrompt Set peUpdateMode of hPrompt to umPromptValue Set piUpdateColumn of hPrompt to 0 End_Procedure End_Object // oStartCustNumber Object oEndCustNumber is a Form Set Label to "Stop reporting at number:" Set Size to 13 85 Set Location to 26 92 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Form_DataType to 0 Set Prompt_Button_Mode to pb_PromptOn // The following code connects the customer selection list to this form Set Prompt_Object to Customer_sl // this is called by the prompt list upon initialization. This will let us // set special properties for the list's one time use. In this case we // want the intial column and the export column to be number (col 0) Procedure Prompt_Callback Integer hPrompt Set peUpdateMode of hPrompt to umPromptValue Set piUpdateColumn of hPrompt to 0 End_Procedure End_Object // oEndCustNumber // The start customer number Function StartNumber Returns Integer Integer iValue Get Value of oStartCustNumber to iValue Function_Return iValue End_Function // StartNumber // The end customer number Function EndNumber Returns Integer Integer iValue Get Value of oEndCustNumber to iValue Function_Return iValue End_Function // StartNumber End_Object // oNumberSelGroup Object oNameSelGroup is a Group Set Size to 49 275 Set Location to 63 101 Set Label to "Name Criteria" Object oStartCustName is a Form Set Label to "Start reporting at customer:" Set Size to 13 178 Set Location to 10 92 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Prompt_Button_Mode to pb_PromptOn // The following code connects the customer selection list to this form Set Prompt_Object to Customer_sl // this is called by the prompt list upon initialization. This will let us // set special properties for the list's one time use. In this case we // want the intial column and the export column to be name (col 1) Procedure Prompt_Callback Integer hPrompt Set peUpdateMode of hPrompt to umPromptValue Set piUpdateColumn of hPrompt to 1 End_Procedure End_Object // oStartCustName Object oEndCustName is a Form Set Label to "End reporting at customer:" Set Size to 13 178 Set Location to 26 92 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Prompt_Button_Mode to pb_PromptOn // The following code connects the customer selection list to this form Set Prompt_Object to Customer_sl // this is called by the prompt list upon initialization. This will let us // set special properties for the list's one time use. In this case we // want the intial column and the export column to be name (col 1) Procedure Prompt_Callback Integer hPrompt Set peUpdateMode of hPrompt to umPromptValue Set piUpdateColumn of hPrompt to 1 End_Procedure End_Object // oEndCustName // The start customer name Function StartCustomer Returns String String sName Get Value of oStartCustName to sName Function_Return sName End_Function // StartCustomer // The end customer name Function EndCustomer Returns String String sName Get Value of oEndCustName to sName Function_Return sName End_Function // StartCustomer End_Object // oNameSelGroup Object oDestRadioGroup is a RadioGroup Set Size to 76 122 Set Location to 116 10 Set Label to "Output destination" Object oWindowRadio is a Radio Set Label to "Print to Window" Set Size to 10 67 Set Location to 17 10 End_Object // oWindowRadio Object oPrinterRadio is a Radio Set Label to "Print to Printer" Set Size to 10 61 Set Location to 31 10 End_Object // oPrinterRadio Object oExportFileRadio is a Radio Set Label to "Export to File" Set Size to 10 57 Set Location to 46 10 End_Object // oExportFileRadio Object oExportOptionsRadio is a Radio Set Label to "Prompt for Export Options" Set Size to 10 97 Set Location to 60 10 End_Object // oExportOptionsRadio // Augemented to setup the output destination of the Crystal // Report. The procedure is sent when the user changes the // selection. Procedure Notify_Select_State Integer iNewItem Integer iOldItem Forward Send Notify_Select_State iNewItem iOldItem Set Enabled_State of oFileTypeGroup to (iNewItem = 2) End_Procedure Enum_List Define rdWindow Define rdPrinter Define rdExport Define rdExportPrompt End_Enum_List Function ReportDestination Returns Integer Integer iVal Get Current_Radio to iVal If (iVal = 0) Function_Return rdWindow Else If (iVal = 1) Function_Return rdPrinter Else If (iVal = 2) Function_Return rdExport Else Function_Return rdExportPrompt End_Function // ReportDestination End_Object // oDestRadioGroup Object oFileTypeGroup is a Group Set Size to 76 238 Set Location to 116 137 Set Label to "Export File Settings" Object oFileNameForm is a Form Set Label to "File Name:" Set Size to 13 131 Set Location to 13 48 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Prompt_Button_Mode to pb_PromptOn // Default item value Set Value to "Custlst.doc" // Send when the prompt key is pressed, start selection list Procedure Prompt String sSelectedFile String sExtension String sFilter Integer iType Integer iSelected // Setup initial file name Get Value to sSelectedFile If (sSelectedFile="") Begin Get FileExt of oTypeCombo to sExtension Move ("CustLst" + sExtension) to sSelectedFile End // Create a filter for the save as dialog Get FileType of oTypeCombo to iType If (iType=crEFTWordForWindows) Move "Word (*.doc)|*.doc" to sFilter Else If (iType=crEFTPortableDocFormat) Move "Adobe PDF (*.doc)|*.doc" to sFilter Else If (iType=crEFTExactRichText) Move "Rich Text (*.rtf)|*.rtf" to sFilter Else If (iType=crEFTHTML40) Move "HTML (*.html)|*.html" to sFilter Else If (iType=crEFTXML) Move "XML (*.xml)|*.xml" to sFilter Move (sFilter + "|All Files|*.*") to sFilter Set Filter_String of oNewDialog to sFilter Set File_Title of oNewDialog to sSelectedFile // Start the save as dialog Get Show_Dialog of oNewDialog to iSelected If iSelected Begin Get File_Name of oNewDialog to sSelectedFile Set Value to sSelectedFile End End_Procedure // Start_Prompt // Returns the name of the file to export to Function FileName Returns String String sSelectedFile sExt // Get file name Get Value to sSelectedFile If (sSelectedFile="") Begin Get FileExt of oTypeCombo to sExt Move ("Custlst"-sExt) to sSelectedFile End Function_Return sSelectedFile End_Function // FileName End_Object // oFileNameForm Object oTypeCombo is a ComboForm Set Label to "File Type:" Set Size to 13 131 Set Location to 29 48 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Combo_Sort_State to False Set Entry_State to False // Augmented to fill the list with export file types. Procedure Combo_Fill_List Send Combo_Add_Item "Word" // 0 Send Combo_Add_Item "Adobe PDF" // 1 Send Combo_Add_Item "Rich Text Format" // 2 Send Combo_Add_Item "HTML" // 3 Send Combo_Add_Item "XML" // 4 End_Procedure // Combo_Fill_List // Type to export to Function FileType Returns Integer String sFileTypeName Integer iFileTypeValue Integer iSelectedItem Get Value 0 to sFileTypeName Get Combo_Item_Matching sFileTypeName to iSelectedItem If (iSelectedItem=0) Move crEFTWordForWindows to iFileTypeValue Else If (iSelectedItem=1) Move crEFTPortableDocFormat to iFileTypeValue Else If (iSelectedItem=2) Move crEFTExactRichText to iFileTypeValue Else If (iSelectedItem=3) Move crEFTHTML40 to iFileTypeValue Else Move crEFTXML to iFileTypeValue Function_Return iFileTypeValue End_Function // FileType // Function: FileExt // Purpose : Extension for the type to export to Function FileExt Returns String String sFileTypeExt Integer iFileTypeValue Get FileType to iFileTypeValue If (iFileTypeValue=crEFTWordForWindows) Move ".doc" to sFileTypeExt Else If (iFileTypeValue=crEFTPortableDocFormat) Move ".pdf" to sFileTypeExt Else If (iFileTypeValue=crEFTExactRichText) Move ".rtf" to sFileTypeExt Else If (iFileTypeValue=crEFTHTML40) Move ".html" to sFileTypeExt Else Move ".xml" to sFileTypeExt Function_Return sFileTypeExt End_Function // FileExt // Function: ChangeExtension // Purpose : Must extension be dynamically updated? Function ChangeExtension Returns Integer Function_Return (Checked_State(oApplyExtCheckBox)) End_Function // ChangeExtension // Procedure: OnCloseUp // Purpose : Augemented to auto,matically change the extension of the // filename Procedure OnChange String sOldName String sExtension Integer sChangeExt Get ChangeExtension to sChangeExt If sChangeExt Begin Get FileName of oFileNameForm to sOldName Get FileExt to sExtension Set Value of oFileNameForm to (Left(sOldName, (Pos(".", sOldName) - 1)) + sExtension) End End_Procedure // OnChange End_Object // oTypeCombo Object oApplyExtCheckBox is a CheckBox Set Label to "Apply combo extension" Set Size to 10 89 Set Location to 46 48 // Apply extensions by default Set Checked_State to True End_Object // oApplyExtCheckBox Object oNewDialog is a SaveAsDialog Set Dialog_Caption to "Customer report export to disk, give file name" Set HideReadOnly_State to True End_Object // oNewDialog End_Object // oFileTypeGroup Object oRunButton is a Button Set Label to "Run Report" Set Size to 14 51 Set Location to 198 271 Set Default_State to True Procedure OnClick Boolean bCrystalOK Get CheckCrystalEnvironment of oCheckForCrystal to bCrystalOK If (bCrystalOK) Begin Send RunReport of oCustCrystalReport End Else Begin Send DisplayDialog of oCheckForCrystal End End_Procedure // OnClick End_Object // oRunButton Object oCancelButton is a Button Set Label to "Cancel" Set Location to 198 325 Procedure OnClick Send Request_Cancel End_Procedure // OnClick End_Object // oCancelButton Object oCustCrystalReport is a cCrystal Set psReportName to "CustomerList.rpt" // Procedure: OnInitializeReport // Purpose : This is a hook message sent by the Open_report procedure. You may use this // procedure to set selection values, print options, etc. This procedure is // intended for augmentation; it has no action by default. Procedure OnInitializeReport Handle hoReport String sStartCust sEndCust sSelection Integer iStartCustomerNumber iEndCustomerNumber iSortDirection Integer eDest eOutputDestination Boolean bDesc bSortByName Get ReportDestination of oDestRadioGroup to eDest If (eDest=rdWindow) Move Print_to_Window to eOutputDestination Else If (eDest=rdPrinter) Move Print_to_Printer to eOutputDestination Else Move Print_to_File to eOutputDestination Set peOutputDestination to eOutputDestination Get IsNameOrder of oSortOrderRadioGroup to bSortByName Get IsDesc of oSortOrderRadioGroup to bDesc // Setup the selection formula Move "" to sSelection If (bSortByName) Begin // Set a selection formula for the report. Get StartCustomer of oNameSelGroup to sStartCust Get EndCustomer of oNameSelGroup to sEndCust If (Trim(sStartCust)<>"") ; Append sSelection "{Customer.Name} >= " '"' (Trim(sStartCust)) '"' If (Trim(sEndCust)<>"") ; Append sSelection (If(sSelection<>"", " and ", "")) "{Customer.Name} <= " '"' (Trim(sEndCust)) '"' End Else Begin Get StartNumber of oNumberSelGroup to iStartCustomerNumber Get EndNumber of oNumberSelGroup to iEndCustomerNumber If (iStartCustomerNumber>0) ; Append sSelection "{Customer.Customer_Number} >= " iStartCustomerNumber If (iEndCustomerNumber>0) ; Append sSelection (If(sSelection<>"", " and ", "")) "{Customer.Customer_Number} <= " iEndCustomerNumber End Set ComRecordSelectionFormula of hoReport to sSelection // Change the formula so the report reflects the selection. Remove // quotes from the formula. If (sSelection="") ; Send AssignFormula of hoReport "SelTxt" ('"' + "NONE" + '"') Else ; Send AssignFormula of hoReport "SelTxt" ('"' + (Replaces('"', sSelection, "")) + '"') // Delete old sort order Send DeleteSortOrder of hoReport // Setup new sort order Move (If(bDesc, crDescendingOrder, crAscendingOrder)) to iSortDirection If (bSortByName) Begin Send AppendSortField of hoReport "Customer" "Name" iSortDirection End Else Begin Send AppendSortField of hoReport "Customer" "Customer_Number" iSortDirection End End_Procedure // OnInitializeReport Procedure OnPrintReport Handle hoReport // prompt to set-up printer Forward Send OnPrintReport hoReport Set pbPrinterPrompt of hoReport to True End_Procedure // OnPrintReport Procedure OnExportReport Handle hoReport String sFileName Integer iFileType eDest Handle hoExport Boolean bExists Forward Send OnExportReport hoReport // Export object receives export information Get ExportObject of hoReport to hoExport Get ReportDestination of oDestRadioGroup to eDest // Use Export Options on Screen // if rdExportPrompt, it will already just do a prompt. // if rdExport we must set all the values If (eDest=rdExport) Begin // don't prompt for export information, we will set it below. Set pbExportPrompt of hoReport to False Get FileName of oFileNameForm to sFileName Get FileType of oTypeCombo to iFileType // Where the report is being exported to, and what type of // file is being created. Set ComDestinationType of hoExport to crEDTDiskFile Set ComFormatType of hoExport to iFileType //Sample for export to disk file (word) If (iFileType=crEFTWordForWindows) Begin Set ComDiskFileName of hoExport to sFileName End //Sample for export to disk file (pdf) If (iFileType=crEFTPortableDocFormat) Begin Set ComDiskFileName of hoExport to sFileName End //Sample for export to disk file (rtf) If (iFileType=crEFTExactRichText) Begin Set ComDiskFileName of hoExport to sFileName End //Sample for export to disk file (XML) If (iFileType=crEFTXML) Begin Set ComXMLFileName of hoExport to sFileName End //Sample for export to disk file (HTML) If (iFileType=crEFTHTML40) Begin Set ComHTMLFileName of hoExport to sFileName End End End_Procedure // OnExportReport End_Object // oCustCrystalReport CD_End_Object // oCustomerListCR