LPARAMETERS tcReportName, tlDuplexOn, tcTempNumber *TMT 12/01/2015 Add duplexing to the report ***************************************************************************************************************************************************************************************** LOCAL lcReportName, laExpr, lnLen, ln, lcExpr, llFoundDuplex, lcOrientation, llOrientation LOCAL lcTempReportName LOCAL lcAliasName lcAliasName = '' *TMT 2016/04/14 Save the table name we are selected to, so we can reset to this when we exit this routine... LOCAL lcInitialTable lcInitialTable = ALIAS() *TMT DIMENSION laExpr[1] llFoundDuplex = .F. llOrientation = .F. lcReportName = ALLTRIM(tcReportName) lcTempReportName = gcpVistemp + '\' + "_" + lcReportName + tcTempNumber *TMT 12/03/2015 Close the temporary table used for the output data if it is already open... *sometimes these temporary tables are named the same as the name of the report, which can cause problems *below when we are creating the temp report table which may be the same name.... can't have the two *tables open at the same time with the same name..... IF USED(lcReportName) USE IN SELECT(lcReportname) ENDIF *TMT 12/02/2015 Delete the temporary cursor table _DailyLog DELETE FILE (lcTempReportName + '.*') *-- TMT 12/02/2015 Since we don't send the REPORTS folder with the Reports to the customer, and the reports are stored in the EXE as cursors, I will need to copy the cursor FRX to the *-- Temp folder and modify the copy. I will use the copy to print from, then delete it when finished. *-- * First, copy the cursor to the temp folder.... USE (lcReportName + '.frx') IN 0 SELECT (lcReportName) *COPY STRUCTURE TO (lcTempReportName) *USE (lcTempReportName) * Now copy the FRX data to the new copied table structure *APPEND FROM lcReportName COPY TO (lcTempReportName) USE IN SELECT(lcTempReportName) USE IN SELECT(lcReportName) RENAME (lcTempReportName + '.DBF') TO (lcTempReportName + '.FRX') RENAME (lcTempReportName + '.FPT') TO (lcTempReportName + '.FRT') *TMT 04/28/2016 Add an extension to duplexreport lcAliasName = 'duplexreport' + SYS(2015) *TMT 2016/04/14 Assign an alias name so we can easily refer to it later *TMT 04/28/2016 Use new duplexreport name *USE (lcTempReportName + '.FRX') IN 0 ALIAS duplexreport USE (lcTempReportName + '.FRX') IN 0 ALIAS (lcAliasName) *TMT 04/28/2016 Select the alias table SELECT (lcAliasName) *-- Put EXPR in an array GOTO TOP lnLen = ALINES(laExpr, expr) *-- Find the Orientation of the page - this will determine how we wish to duplex the pages - Portrait orientation will need the Vertical Duplex - 2 *-- Landscape Orientation requires the Horizontal Duplex - 3 FOR ln = 1 TO lnLen IF LEFT(laExpr[ln], 12) = 'ORIENTATION=' lcOrientation = SUBSTR(laExpr[ln],13,2) && if duplex_reports is TRUE, then send 2 to printer in the report for duplex, else send 1 for simplex EXIT ENDIF ENDFOR *-- Find the DUPLEX= line and change it FOR ln = 1 TO lnLen IF LEFT(laExpr[ln], 7) = 'DUPLEX=' llFoundDuplex = .T. DO CASE CASE tlDuplexOn = .F. && Turn off the duplexing laExpr[ln] = LEFT(laExpr[ln], 7) + '1' CASE ALLTRIM(lcOrientation) = '0' && Portrait - make the Orientation to be Vertical Duplex * laExpr[ln] = LEFT(laExpr[ln], 7) + '3' && Send 2 to printer in the report for Vertical duplex laExpr[ln] = LEFT(laExpr[ln], 7) + '2' && Send 2 to printer in the report for Vertical duplex CASE ALLTRIM(lcOrientation) = '1' && Lanscape - make the Orientation to be Horizontal Duplex laExpr[ln] = LEFT(laExpr[ln], 7) + '2' && Send 3 to printer in the report for Horizontal duplex OTHERWISE * laExpr[ln] = LEFT(laExpr[ln], 7) + '3' && Send 2 to printer in the report for Vertical duplex laExpr[ln] = LEFT(laExpr[ln], 7) + '2' && Send 2 to printer in the report for Vertical duplex ENDCASE EXIT ENDIF ENDFOR IF NOT llFoundDuplex AND tlDuplexOn lnLen = lnLen + 1 DIMENSION laExpr(lnLen) DO CASE CASE ALLTRIM(lcOrientation) = '0' && Portrait - make the Orientation to be Vertical Duplex * laExpr(lnLen) = 'DUPLEX=3' laExpr(lnLen) = 'DUPLEX=2' CASE ALLTRIM(lcOrientation) = '1' && Lanscape - make the Orientation to be Horizontal Duplex laExpr(lnLen) = 'DUPLEX=2' OTHERWISE * laExpr(lnLen) = 'DUPLEX=3' laExpr(lnLen) = 'DUPLEX=2' ENDCASE ENDIF *-- Convert the array back to a string and save it in EXPR lcExpr = '' FOR ln = 1 TO lnLen lcExpr = lcExpr + laExpr[ln] + CHR(13) ENDFOR *TMT 2016/04/14 Fix problem of the USE not looking at the lcTempReportName table because of timers firing.... *REPLACE expr WITH lcExpr && IN (lcTempReportName) *TMT 04/28/2016 Select the alias report *REPLACE expr WITH lcExpr IN duplexreport && IN (lcTempReportName) REPLACE expr WITH lcExpr IN (lcAliasName) && IN (lcTempReportName) *TMT *-- Close the table *TMT 2016/04/14 Fix problem of the USE not looking at the lcTempReportName table because of timers firing.... *USE *TMT 04/28/2016 Close the duplexreport *USE IN SELECT('duplexreport') USE IN SELECT(lcAliasname) *TMT *TMT 2016/04/14 now have the routine select the initial table we were looking at when we started the routine, in case a timer has us looking elsewhere... IF NOT EMPTY(lcInitialTable) SELECT &lcInitialTable ENDIF RETURNAny other things like this to look for, for accidentally closing a table when it should still be open?