Thursday, 7 July 2016

Print no. of copies separaterly using x++ code in SSRS

Add method for Controller for separate copy of reports.
protected void dialogShow()
{
    SysOperationDialog sysOperationDialog;
    FormRun formRun;

    if (useReportViewerForm)
    {
        dialog.run();
        this.dialogPostRun();

        sysOperationDialog = dialog as SysOperationDialog;
        formRun = sysOperationDialog.formRun();
        formRun.detach();
    }
    else
    {
        super();
    }
}
Add method for Controller for separate copy of reports.
protected void dialogClose()
{
    if(!useReportViewerForm)
    {
        super();
    }
}
class CartonLabelController extends SrsReportRunController
{
    container       printerSettings;
    SRSPrintDestinationSettings printDestinationSettings;
}

protected void prePromptModifyContract()
{
    CartonLabelContract contract;
    PurchParmTable      purchParmTable;

    if(this.parmArgs() && this.parmArgs().record())
    {
        contract = this.parmReportContract().parmRdpContract() as CartonLabelContract;
        purchParmTable = this.parmArgs().record();
        contract.parmPurchParmTable(purchParmTable.parmId);
        contract.parmTableRefId(purchParmTable.TableRefId);
    }
}

public void setPrinterSettings(container _settings)
{
    printerSettings = _settings;

    printDestinationSettings = new SRSPrintDestinationSettings(_settings);

    if (conlen(printerSettings) > 0)
    {
        printDestinationSettings.unpack(printerSettings);
    }
}
public boolean showQueryValues(str parameterName)
{
    return false;
}

public static void main(Args args)
{
    CartonLabelController   cartonLabelController;
    PurchParmTable          purchParmTable;

    cartonLabelController = new CartonLabelController();

    purchParmTable = args.record() as PurchParmTable;

    cartonLabelController.parmArgs(args);

    cartonLabelController.parmReportName(ssrsReportStr(CartonLabelReport,Report));
    cartonLabelController.parmShowDialog(false);
    cartonLabelController.parmDialogCaption("@CIT132");
    cartonLabelController.startOperation();
}

Button Click Method to run the two reports synchronously.

void clicked()
{
    args args = new Args();
    CartonLabelController       cartonLabelController;
    ItemLabelController         itemLabelController;
    container                   printSettingsLoc;
    SecurityRights              sr;
    int                         i;
    ;

    sr = SecurityRights::construct();
    super();

    args.record(PurchParmTable);
    args.parm(PurchParmTable.ParmId);
    for(i=0;i<PurchParmLine.CartonLabels;i++)
    {
        if(PrintCartonLabels.value() == NoYes::Yes  && Global::hasMenuItemAccess(menuitemOutputStr(CartonLabels),MenuItemType::Output))
        {

            cartonLabelController  = new cartonLabelController();

            cartonLabelController.parmArgs(args);

            cartonLabelController.parmReportName(ssrsReportStr(CartonLabelReport,Report));
            cartonLabelController.parmDialogCaption("@CIT132");
            cartonLabelController.parmShowDialog(false);

            if(PurchParmTable.CartonLabelPrintSettings)
            {
                printSettingsLoc = PurchParmTable.CartonLabelPrintSettings;
                cartonLabelController.setPrinterSettings(printSettingsLoc);
            }

            cartonLabelController.parmReportContract().parmPrintSettings().printMediumType(conPeek(printSettingsLoc,3));
            cartonLabelController.parmReportContract().parmPrintSettings().overwriteFile(true);
            cartonLabelController.parmReportContract().parmPrintSettings().fileFormat(conPeek(printSettingsLoc,18));
            cartonLabelController.parmReportContract().parmPrintSettings().fileName(conPeek(printSettingsLoc,20));
            cartonLabelController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            cartonLabelController.startOperation();
        }
    }
    for(i=0;i<PurchParmLine.ItemLabels;i++)// Loop to run no.of reports based on the field.
    {
        if(PrintItemLabels.value() == NoYes::Yes && Global::hasMenuItemAccess(menuitemOutputStr(ItemLabels),MenuItemType::Output))
        {
            ItemLabelController  = new ItemLabelController();

            ItemLabelController.parmArgs(args);
            ItemLabelController.parmReportName(ssrsReportStr(ItemLabelReport,Report));
            ItemLabelController.parmDialogCaption("@CIT130");
            ItemLabelController.parmShowDialog(false);
            if(PurchParmTable.ItemLabelPrintSettings)
            {
                printSettingsLoc = PurchParmTable.ItemLabelPrintSettings;
                ItemLabelController.setPrinterSettings(printSettingsLoc);
            }
            ItemLabelController.parmReportContract().parmPrintSettings().printMediumType(conPeek(printSettingsLoc,3));
            ItemLabelController.parmReportContract().parmPrintSettings().overwriteFile(true);
            ItemLabelController.parmReportContract().parmPrintSettings().fileName(conPeek(printSettingsLoc,20));
            ItemLabelController.parmExecutionMode(SysOperationExecutionMode::Synchronous);// Added this line to open synchronously.
            ItemLabelController.startOperation();
        }
    }
}

Button Click method to set the printer settings

void clicked()
{
    printSettings = new SRSPrintDestinationSettings();

    super();

    if(SrsReportRunUtil::showSettingsDialog(printSettings))
    {
        PurchParmTable.ItemLabelPrintSettings = printSettings.pack();
    }
}

No comments:

Post a Comment