For one reason we need to prevent report printing options.
We gave user permission to preview report with a stamp “Preview” and with another button allowed to be printed directly to the pre-configured printer. By this way you can limit reports printed on which printer / how many times could be printed.
First part is preventing print on preview.
public static class LELR_SRSPrintDestinationDelegate
{
static str rrname ;
static boolean closing;
/// <summary>
///
/// </summary>
/// <param name="sendToImageList"></param>
/// <param name="formList"></param>
[SubscribesTo(classStr(SRSPrintDestinationSettingsDelegates), delegateStr(SRSPrintDestinationSettingsDelegates, buildSendToList))]
public static void SRSPrintDestinationSettingsDelegates_buildSendToList(ImageListAppl sendToImageList, FormListControl formList)
{
if (rrname == "Stock List with Min Max")
{
if (!closing)
{
formList.delete(5);
formList.delete(4);
formList.delete(3);
formList.delete(2);
formList.delete(0);
}
else
{
formList.delete(0);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="args"></param>
[PostHandlerFor(formStr(SRSPrintDestinationSettingsForm), formMethodStr(SRSPrintDestinationSettingsForm, init))]
public static void SRSPrintDestinationSettingsForm_Post_init(XppPrePostArgs args)
{
if (rrname == "Stock List with Min Max")
{
FormRun fr = args.getThis();
fr.changeTarget(SRSPrintMediumType::Screen);
}
}
/// <summary>
///
/// </summary>
/// <param name="args"></param>
[PostHandlerFor(formStr(SysOperationTemplateForm), formMethodStr(SysOperationTemplateForm, run))]
public static void SysOperationTemplateForm_Post_run(XppPrePostArgs args)
{
FormRun fr = args.getThis();
rrname = fr.design().caption();
}
/// <summary>
///
/// </summary>
/// <param name="settingsForm"></param>
/// <param name="mediumType"></param>
[SubscribesTo(classStr(SRSPrintDestinationSettingsDelegates), delegateStr(SRSPrintDestinationSettingsDelegates, changeTarget))]
public static void SRSPrintDestinationSettingsDelegates_changeTarget(FormRun settingsForm, SRSPrintMediumType mediumType)
{
if (rrname == "Stock List with Min Max")
{
settingsForm.setSendToSelection(SRSPrintMediumType::Screen);
}
}
/// <summary>
///
/// </summary>
/// <param name="args"></param>
[PreHandlerFor(formStr(SRSPrintDestinationSettingsForm), formMethodStr(SRSPrintDestinationSettingsForm, closeOk))]
public static void SRSPrintDestinationSettingsForm_Pre_closeOk(XppPrePostArgs args)
{
FormRun fr = args.getThis();
if (rrname == "Stock List with Min Max")
{
closing = true;
fr.buildSendToList();
fr.setSendtoSelection(SRSPrintMediumType::Screen);
fr.changeTarget(SRSPrintMediumType::Screen);
closing = false;
}
}
}
second part is sending report directly to preconfigured printer
class LELRProjectListsAllRptController extends SrsReportRunController
{
public static void main(Args _args)
{
LELRProjectListsAllRptController controller = new LELRProjectListsAllRptController();
LELRProjListAuthorizedRptContract rdpContract = new LELRProjListAuthorizedRptContract();
controller.parmReportName(ssrsReportStr(LELRProjListAuthorizedRpt, LELRDesign));
controller.parmArgs(_args);
controller.parmDialogCaption("Test");
SRSPrintDestinationSettings settings;
controller.parmShowDialog(false);
// Explicitly provide all required parameters
rdpContract.parmFromDate(systemDateGet()-30);
rdpContract.parmToDate(systemDateGet()+30);
controller.parmReportContract().parmRdpContract(rdpContract);
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
// settings.printMediumType(SRSPrintMediumType::Screen);
settings.printMediumType(SRSPrintMediumType::Printer);
settings.printerName(printer.printername); // should be fetched from a parameter
// settings.fileFormat(SRSReportFileFormat::Excel);
// settings.fileName(@'c:\tmp\Text.xlsx');
controller.startOperation();
}
}