// cCSVReportView.pkg //--------------------------------------------------------------------> // cCSVReportView modifed for CSV // Ordinarily the WinReport2 Class doesn't use the print mode // setting OUTPUT_TO_FILE for some unknown reason. It is used // in the Crystal classes, but if you don't use Crystal, what // then? This class activates OUTPUT_TO_FILE for non-Crystal // use. // // cPrintContainer - A class to hold the CSV Radio button, output // file name field and call to Excel if a CSV file is output. // // Sysfile - The output file and whether or not to ask which printer // are kept in a system data file. These both could be populated // via some other method if necessary // // 9/4/2008 RLW - Add checkbox for outputting the CSV header or not // 9/4/2009 JAC - Added psOutputFullname - filename as keyed by the user. // 9/5/2009 RLW - Resized controls to better fit under VDF-15 // 1/16/2010 RLW - Added hoReport to StartReport - Jim Albright //--------------------------------------------------------------------> Use DfRptVw.pkg //Open SysFile Register_Object oCSVFilename Register_Object oShowInExcel Register_Object oOutputHeader Register_Object oOutputToText Register_Function psOutputFolderName Returns String Register_Function psOutputFileName Returns String Register_Function psOutputFullName Returns String // 09/04/2009 Register_Function pbOutputHeader Returns Boolean Class cShowInExcel is a CheckBox Procedure Construct_Object Forward Send Construct_Object Set Label to "Show in Excel after report" Set Checked_State to True End_Procedure Procedure OnChange Boolean bChecked Handle hoReport Get Report_Object_Id to hoReport If (Focus(Self) and hoReport <> 0) Begin Get Checked_State to bChecked Set pbShowInExcel of hoReport to bChecked End End_Procedure End_Class Class cOutputHeader is a CheckBox Procedure Construct_Object Forward Send Construct_Object Set Label to "Output CSV Header" Set Checked_State to True End_Procedure Procedure OnChange Boolean bChecked Handle hoReport Get Report_Object_Id to hoReport If (Focus(Self) and hoReport <> 0) Begin Get Checked_State to bChecked Set pbOutputHeader of hoReport to bChecked End End_Procedure End_Class Class cPrintTo is a RadioGroup Procedure Construct_Object Forward Send Construct_Object Set Label to "Send Report to" Object oRadio1 is a Radio Set Label to "Report Viewer" Set Size to 10 61 Set Location to 12 8 Set Status_Help to "Prints the report to screen" End_Object // oRadio1 Object oRadio2 is a Radio Set Label to "Printer" Set Size to 10 42 Set Location to 24 8 Set Status_Help to "Prints the report to printer" End_Object // oRadio2 Object oRadio3 is a Radio Set Size to 10 50 Set Location to 37 8 Set Label to "CSV" Set Status_Help to "Prints the report to a CSV file for Excel" End_Object Object oShowInExcel is a cShowInExcel Set Size to 10 105 Set Location to 37 47 End_Object Object oOutputHeader is a cOutputHeader Set Size to 10 80 Set Location to 47 47 End_Object End_Procedure Procedure Notify_Select_State Integer iToItem Integer iFromItem Handle hoReport Get Report_Object_Id to hoReport Forward Send Notify_Select_State iToItem iFromItem Send DoSetEnabled to oCSVFileName (iToItem = 2) Set piPrintSelection to iToItem Send DoCheckSelection to hoReport iToItem End_Procedure End_Class // oPrintTo Class cBtnCancel is a Button Procedure Construct_Object Forward Send Construct_Object Set Label to "Cancel" Set Status_Help to "Close this Panel" Set peAnchors to anBottomRight End_Procedure Procedure OnClick Send Close_Panel End_Procedure End_Class // oBtnCancel Class cBtnPrinterSetup is a Button Procedure Construct_Object Forward Send Construct_Object Set Label to "Printer Setup" Set Status_Help to "Set up printer for report" Set peAnchors to anBottomRight End_Procedure Procedure OnClick Handle hoReport Get Report_Object_Id to hoReport Send DFPrintSetup of hoReport End_Procedure End_Class // oBtnPrinterSetup Class cBtnPrint is a Button Procedure Construct_Object Forward Send Construct_Object Set Label to "Print" Set Status_Help to "Print the Selected report" Set Default_State to True Set peAnchors to anBottomRight End_Procedure Procedure OnClick Send DoPreProcess Send StartReport Send DoPostProcess End_Procedure End_Class // oBtnPrint Class cCSVFileName is a Form Procedure Construct_Object Forward Send Construct_Object Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set peAnchors to anBottomLeft Set Status_Help to "CSV File Name and Path" End_Procedure Procedure DoSetEnabled Integer iState Set Enabled_State to iState Set Visible_State to iState Set Enabled_State of oShowInExcel to iState Set Visible_State of oShowInExcel to iState Set Enabled_State of oOutputHeader to iState Set Visible_State of oOutputHeader to iState Set Visible_State of oOutputToText to iState Set Value to (psOutputFolderName(Self) + psOutputFileName(Self)) End_Procedure // 09/04/2009 Procedure OnChange String sFullname Get Value to sFullname Set psOutputFullname to sFullname End_Procedure // Item_Change // 09/04/2009 end End_Class //----------------------------------------------------------> // Container to hold the whole output/printer assembly //----------------------------------------------------------> Class cPrintContainer is a Container3d Procedure Construct_Object Forward Send Construct_Object Object oPrintTo is a cPrintTo // Set Size to 51 145 Set Size to 62 149 Set Location to 4 8 End_Object // oPrintTo Object oOutputToText is a TextBox Set Size to 50 10 Set Location to 67 4 Set Label to "Output To:" End_Object Object oCSVFileName is a cCSVFileName Set Size to 13 207 Set Location to 78 7 End_Object Object oBtnPrint is a cBtnPrint Set Location to 7 162 End_Object // oBtnPrint Object oBtnPrinterSetup is a cBtnPrinterSetup Set Location to 24 162 End_Object // oBtnPrinterSetup Object oBtnCancel is a cBtnCancel Set Location to 41 162 End_Object // oBtnCancel End_Procedure End_Class //----------------------------------------------------------> // cCSVReportView // CSV class for ReportView // Contains extra radio button for CSV file // and output file name field //----------------------------------------------------------> Class cCSVReportView is a ReportView Procedure Construct_Object Forward Send Construct_Object Property String psOutputFileName "Outfile.csv" Property String psOutputFolderName "C:\Temp\" Property String psOutputFullName "C:\Temp\Outfile.csv" // 09/04/2009 Property String psUseDefaultPrinter Property Integer piPrintSelection 0 End_Procedure //----------------------------------------------------------> // Called prior to and after RunReport in case any // pre or post processing is required //----------------------------------------------------------> Procedure DoPreProcess End_Procedure Procedure DoPostProcess End_Procedure //----------------------------------------------------------> // Called by "Send Report To" radio button to change any // selection criteria - i.e. if CSV is selected //----------------------------------------------------------> Procedure DoCheckSelection Integer iPrintMode End_Procedure //----------------------------------------------------------> // Get the output directory if specified in a setup system // file, Otherwise use c:\temp // Use default printer or not //----------------------------------------------------------> Procedure End_Construct_Object String sOutFolder Forward Send End_Construct_Object // If (trim(SYSFILE.Default_CSV_Dir) <> "") Begin // Move (trim(SYSFRT.Default_CSV_Dir)) to sOutFolder // Set psOutputFolderName to sOutFolder // End Set psUseDefaultPrinter to "N" // SYSFILE.No_Ask_Printer Get vFolderFormat sOutFolder to sOutFolder End_Procedure //----------------------------------------------------------> // Get CSV column header names from the array and output // as a string for Excel //----------------------------------------------------------> Function sGetAssembleHeader Returns String String[] sOutputHeaderString String sHeader Integer iElementCount iCounter Handle hoReport Get Report_Object_Id to hoReport Get psOutputHeaderString of hoReport to sOutputHeaderString Move (SizeOfArray(sOutputHeaderString)) to iElementCount For iCounter from 0 to (iElementCount -1) If (iCounter < (iElementCount-1)) Move (sHeader+'"'+sOutputHeaderString[iCounter]+'",') to sHeader Else Move (sHeader+'"'+sOutputHeaderString[iCounter]+'"') to sHeader // last one, no trailing comma Loop Function_Return sHeader End_Function //----------------------------------------------------------> // StartReport - Called by a forward send in the .rv itself // Determines print mode // If CSV sets channel // Opens output file // Writes CSV header row //----------------------------------------------------------> Procedure StartReport Integer iToPrinter iChO String sOutputFileName sOutFolder sHeader sUseDefaultPrinter String sOutputFullName // 09/04/2009 String[] sOutputHeaderString Handle hoReport Get Report_Object_Id to hoReport // determine if direct print Get piPrintSelection to iToPrinter Get psUseDefaultPrinter to sUseDefaultPrinter If (iToPrinter = 0) Set OutPut_Device_Mode of hoReport to PRINT_TO_WINDOW // Preview Else If (iToPrinter = 1 and sUseDefaultPrinter = "N") Set OutPut_Device_Mode of hoReport to PRINT_TO_PRINTER // Ask which Printer Else If (iToPrinter = 1 and sUseDefaultPrinter = "Y") Set OutPut_Device_Mode of hoReport to PRINT_TO_PRINTER_NO_DIALOG // No ask Else Begin // Output to file Get psOutputFileName to sOutputFileName Get psOutputFolderName to sOutFolder Get psOutputFullName to sOutputFullName // 09/04/2009 Set Output_Device_Mode of hoReport to PRINT_TO_FILE Get Seq_New_Channel to iChO Set piChannelOut of hoReport to iChO // 1/16/2010 Direct_Output channel iChO (sOutputFullName) // Output the header... or not If (pbOutputHeader(hoReport)) Begin // 1/16/2010 Get sGetAssembleHeader to sHeader Writeln channel iCho sHeader End End End_Procedure // StartReport End_Class