1Use Crystal\CheckForCrystal.dg 2Use dfrptvw.pkg 3Use DataDict.pkg 4Use Windows.pkg 5Use dfSpnFrm.pkg 6Use dfRadio.pkg 7Use cCrystal.pkg 8Use Vendor.DD 9Use Customer.DD 10 11ACTIVATE_VIEW Activate_oAddressLabelsCR FOR oAddressLabelsCR 12 13Object oAddressLabelsCR is a ReportView 14 Set Label to "Address Labels" 15 Set Location to 10 13 16 Set Size to 114 165 17 Set piMinSize to 114 165 18 19 Object Vendor_DD is a Vendor_DataDictionary 20 Send DefineAllExtendedFields 21 End_Object // Vendor_DD 22 23 Object Customer_DD is a Customer_DataDictionary 24 Send DefineAllExtendedFields 25 End_Object // Customer_DD 26 27 Set Main_DD to Customer_DD 28 Set Server to Customer_DD 29 30 Object oCopiesGroup is a Group 31 Set Size to 32 154 32 Set Location to 3 6 33 Set Label to "Number of Labels to Print per Record:" 34 Object oCopies is a SpinForm 35 Set Label to "Print " 36 Set Size to 13 39 37 Set Location to 13 30 38 Set Label_Col_Offset to 2 39 Set Label_Justification_Mode to jMode_Right 40 Set Minimum_Position to 1 41 42 // Procedure : Activating 43 // Purpose : This is used to default the number of labels to print 44 Procedure Activating 45 Forward Send Activating 46 Set Value to 1 47 End_Procedure // Activating 48 49 End_Object // oCopies 50 51 Object oTextBox1 is a Textbox 52 Set Label to "Labels per Record" 53 Set Location to 15 72 54 Set Size to 10 59 55 Set TypeFace to "MS Sans Serif" 56 End_Object // oTextBox1 57 58 Function NumberOfCopies Returns Integer 59 Integer iCopies 60 Get Value of oCopies to iCopies 61 Function_Return iCopies 62 End_Function // NumberOfCopies 63 64 End_Object // oCopiesGroup 65 66 Object oPrintGroup is a RadioGroup 67 Set Size to 54 71 68 Set Location to 38 7 69 Set Label to "Print For:" 70 Object oRadio1 is a Radio 71 Set Label to "Customers" 72 Set Size to 10 49 73 Set Location to 13 9 74 End_Object // oRadio1 75 76 Object oRadio2 is a Radio 77 Set Label to "Vendors" 78 Set Size to 10 43 79 Set Location to 26 9 80 End_Object // oRadio2 81 82 Object oRadio3 is a Radio 83 Set Label to "Both" 84 Set Size to 10 31 85 Set Location to 39 9 86 End_Object // oRadio3 87 88 Procedure Notify_Select_State Integer iToItem Integer iFromItem 89 Forward Send Notify_Select_State iToItem iFromItem 90 //for augmentation 91 End_Procedure // Notify_Select_State 92 93 //If you set Current_Radio, you must set it AFTER the 94 //radio objects have been created AND AFTER Notify_Select_State has been 95 //created. i.e. Set in bottom-code of object at the end!! 96 //Set Current_Radio To 0 97 98 End_Object // oPrintGroup 99 100 Object oDestGroup is a RadioGroup 101 Set Size to 54 76 102 Set Location to 38 84 103 Set Label to "Output Destination:" 104 Object oScreen is a Radio 105 Set Label to "Screen" 106 Set Size to 10 39 107 Set Location to 17 14 108 End_Object // oScreen 109 110 Object oPrinter is a Radio 111 Set Label to "Printer" 112 Set Size to 10 37 113 Set Location to 31 14 114 End_Object // oPrinter 115 116 Procedure Notify_Select_State Integer iToItem Integer iFromItem 117 Forward Send Notify_Select_State iToItem iFromItem 118 119 If (iToItem = 0) Begin 120 Set peOutputDestination of oCrystalReport1 to PRINT_TO_WINDOW 121 End 122 Else Begin 123 Set peOutputDestination of oCrystalReport1 to PRINT_TO_PRINTER 124 End 125 126 End_Procedure // Notify_Select_State 127 128 End_Object // oDestGroup 129 130 Object oOkButton is a Button 131 Set Label to "&OK" 132 Set Size to 14 51 133 Set Location to 96 57 134 Set Default_State to True 135 136 Procedure OnClick 137 Boolean bCrystalOK 138 139 Get CheckCrystalEnvironment of oCheckForCrystal to bCrystalOK 140 If (bCrystalOK) Begin 141 Send RunReport of oCrystalReport1 142 End 143 Else Begin 144 Send DisplayDialog of oCheckForCrystal 145 End 146 147 End_Procedure 148 149 End_Object // oOkButton 150 151 Object oCancelButton is a Button 152 Set Label to "&Cancel" 153 Set Location to 96 110 154 155 Procedure OnClick 156 Send Request_Cancel 157 End_Procedure // OnClick 158 159 End_Object // oCancelButton 160 161 Object oCrystalReport1 is a cCrystal 162 163 Use Customer.DD 164 165 Set psReportName to "Labels.rpt" 166 167 // Array of strings 168 Property String[] pStates 169 170 // This is called for each customer or vendor we create 171 // a label for. It adds the state if it does not already 172 // exist in the array. 173 Procedure AddState String sState 174 Integer iItem iCount 175 String sVal 176 String[] hoStates 177 Get pStates to hoStates 178 Move (SizeOfArray(hoStates)) to iCount 179 For iItem From 0 to (iCount-1) 180 If (sState = (hoStates[iItem])) Procedure_Return 181 Loop 182 Move sState to hoStates[iCount] 183 Set pStates to hoStates 184 End_Procedure // AddState 185 186 // This returns an array of vendors. 187 Function LoadVendors Returns Variant[][5] 188 Integer iItem iCopies iLabel 189 Boolean bFound 190 Variant[][5] vData 191 192 Get NumberOfCopies of oCopiesGroup to iCopies 193 Clear Vendor 194 Find gt Vendor by 1 195 Move (Found) to bFound 196 While bFound 197 // Must have a City, State, and Zip code to create a label 198 If ((Vendor.City <> "") and (Vendor.State <> "") and (Vendor.Zip <> "")) Begin 199 // copy 200 For iItem From 1 to iCopies 201 Move (Trim(Vendor.Name)) to vData[iLabel][0] 202 Move (Trim(Vendor.Address)) to vData[iLabel][1] 203 Move (Trim(Vendor.City)) to vData[iLabel][2] 204 Move (Trim(Vendor.State)) to vData[iLabel][3] 205 Move (Trim(Vendor.Zip)) to vData[iLabel][4] 206 Increment iLabel 207 Loop 208 // Add state to list 209 Send AddState Vendor.State 210 End 211 Find gt Vendor by 1 212 Move (Found) to bFound 213 End 214 Function_Return vData 215 End_Function // LoadVendors 216 217 // This returns an array of customers. 218 Function LoadCustomers Returns Variant[][5] 219 Integer iItem iCopies iLabel 220 Boolean bFound 221 String sCSZ 222 Variant[][5] vData 223 224 Get NumberOfCopies of oCopiesGroup to iCopies 225 Clear Customer 226 Find gt Customer by 1 227 Move (Found) to bFound 228 While bFound 229 // Must have a City, State, and Zip code to create a label 230 If ((Customer.City <> "") and (Customer.State <> "") and (Customer.Zip <> "")) Begin 231 Move (Trim(Customer.City)) to sCSZ 232 Append sCSZ ", " (Trim(Customer.State)) " " (Trim(Customer.Zip)) 233 // copy 234 For iItem From 1 to iCopies 235 Move (Trim(Customer.Name)) to vData[iLabel][0] 236 Move (Trim(Customer.Address)) to vData[iLabel][1] 237 Move (Trim(Customer.City)) to vData[iLabel][2] 238 Move (Trim(Customer.State)) to vData[iLabel][3] 239 Move (Trim(Customer.Zip)) to vData[iLabel][4] 240 Increment iLabel 241 Loop 242 // Add state to list 243 Send AddState Customer.State 244 End 245 Find gt Customer by Index.1 246 Move (Found) to bFound 247 End 248 Function_Return vData 249 End_Function // LoadCustomers 250 251 Procedure OnInitializeReport Handle hoReport 252 Handle hoParam hoLabels 253 String[] hoStates 254 Variant[][5] vData 255 Integer iItem iCount 256 String sDesc 257 258 // Clear states 259 Set pStates to hoStates 260 // Create data to print labels 261 Get CreateCDO of hoReport "Label.ttx" to hoLabels 262 If (hoLabels) Begin 263 // Load Vendors 264 If (Current_Radio(oPrintGroup)<>1) Begin 265 Get LoadVendors to vData 266 Send AppendCDOData of hoReport hoLabels vData 267 End 268 // Load Customers 269 If (Current_Radio(oPrintGroup)<>0) Begin 270 Get LoadCustomers to vData 271 Send AppendCDOData of hoReport hoLabels vData 272 End 273 End 274 275 // Prompt a list of states based on customers and/or vendors 276 Set ComEnableParameterPrompting of hoReport to True 277 // Create Parameter object 278 Get GetParamObjectByName of hoReport "ChoiceOfStates" to hoParam 279 If (hoParam) Begin 280 // Set prompt string 281 Set ComPrompt of hoParam to "Please Select All States to Print Labels For:" 282 // Don't allow user to add states to the list 283 Set ComDisallowEditing of hoParam to True 284 // Allow the user to select more than one state 285 Set ComEnableMultipleValues of hoParam to True 286 287 // Get list if states 288 Get pStates to hoStates 289 Move (SizeOfArray(hoStates)) to iCount 290 For iItem From 1 to iCount 291 // Add each state to the parameter object 292 Send ComSetNthDefaultValue of hoParam iItem (hoStates[iItem-1]) 293 // Get state code description from validation table 294 Get Find_Code_Description of Customer_State_VT (hoStates[iItem-1]) to sDesc 295 Set ComNthValueDescription of hoParam iItem to (Trim(sDesc)) 296 Loop 297 End 298 End_Procedure // OnInitializeReport 299 300 End_Object // oCrystalReport1 301 302 On_Key Key_Alt+Key_O Send KeyAction of oOkButton 303 On_Key Key_Alt+Key_C Send KeyAction of oCancelButton 304 305End_Object // oAddressLabelsCR