从代码打开报告打印对话框

时间:2013-01-18 14:26:34

标签: axapta dynamics-ax-2009 x++

我试图强制打开打印对话框,以便用户所要做的就是设置电子邮件地址并按确定。我找到了关于如何在没有打印对话框的情况下将报表打印到文件或打印机的多个教程,但这不是我正在寻找的。

通常,要通过电子邮件发送报告,用户会显示报告,单击工具栏中的打印图标,然后选择电子邮件并发送。我想自动删除前两个步骤。

到目前为止,这是我多次尝试这样做的尝试之一,但无济于事。

void emailInvoice()
{
Args                args;
ReportRun           rr;
Report              rb;
PrintJobSettings    pjs;
CustInvoiceJour     record;
;

select record where record.RecId == 5637175089;

args = new Args("SalesInvoice");
args.record(record);
args.parmEnum(PrintCopyOriginal::OriginalPrint);

// Set report run properties
rr = new ReportRun(args,'');
rr.suppressReportIsEmptyMessage(true);
rr.query().interactive(false);

// set report properties
rb = rr.report();
rb.interactive(true);

// set print job settings
pjs = rr.printJobSettings();
pjs.fileName(strfmt("C:\\Users\\gbonzo\\Desktop\\%1.pdf", record.SalesId));
pjs.fitToPage(true);
// break the report info pages using the height of the current printer's paper
pjs.virtualPageHeight(-1);


// force PDF printing
pjs.format(PrintFormat::PDF);
pjs.setTarget(PrintMedium::Mail);
pjs.viewerType(ReportOutputUserType::PDF);

// lock the print job settings so can't be changed
// X++ code int the report may try to change the destination
// to the screen for example but this does not make
// sense when running a report here
pjs.lockDestinationProperties(true);

// Initialize the report
rr.init();

rr.run();
}

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

您是否尝试开发RunBase标准对话框类(RunBaseBatchPrintable,如果您需要选择打印机),它会获取您需要的所有对话框字段,并从那里以编程方式运行报告,传递所有需要的参数?我确信它会起作用,并且可能会留下一个更清晰的代码,将用户交互所需逻辑的报告分开。

在这里阅读一个例子:

http://waikeatng.blogspot.com.es/2010/10/using-runbasebatchprintable-class.html

答案 1 :(得分:0)

在调用run()方法之前,必须调用ReportRun类的prompt()方法。

if (rr.prompt())
{
    rr.run();
}

prompt()方法将显示打印对话框。如果您希望用户更容易使用SysMailer类,请查看quickSend()方法。

相关问题