报表打印管理Print management
添加一个新的Report format
如下图为Customer invoice添加两个新的Report format
图中的两个Report format可以通过添加一下代码可以实现
[ExtensionOf(classStr(PrintMgmtReportFormatPopulator))] public final class PrintMgmtReportFormatPopulator_Demo_Extension { #PrintMgmtSetup protected void addDocuments() { // Add new customized reports this.addOther(PrintMgmtDocumentType::SalesOrderInvoice, ssrsReportStr(DocSalesInvoice, Report), ssrsReportStr(DocSalesInvoice, Report), #NoCountryRegionId); this.addOther(PrintMgmtDocumentType::SalesOrderInvoice, ssrsReportStr(DocSalesInvoiceExt, Report), ssrsReportStr(DocSalesInvoiceExt, Report), #NoCountryRegionId); // Add the standard report design, because of PrintMgmtDocType.getDefaultReportFormatDelegate() this.addOther(PrintMgmtDocumentType::SalesOrderInvoice, ssrsReportStr(SalesInvoice, Report), ssrsReportStr(Sal next addDocuments(); } }
下次打开Print management setup的时候,PrintMgmtReportFormat 表中就会添加了 2 条新记录。
改变默认的 Report format
如果您需要更改Original/Copy preview的默认的 Report format,Microsoft 建议修改PrintMgmtDocType.getDefaultReportFormatDelegate():
class THK_PrintMgmtDocTypeEventHandler { [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))] public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result) { switch (_docType) { case PrintMgmtDocumentType::SalesOrderInvoice: _result.result(ssrsReportStr(DocSalesInvoice, Report)); break; } } }
打印Original/Copy preview的时候,系统目前仍然会打印默认的Report format,而非用户下拉选择的Format(Bug?),因此需要通过一下代码修复:
class THK_PrintMgmtDocTypeEventHandler { [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))] public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result) { switch (_docType) { case PrintMgmtDocumentType::SalesOrderInvoice: _result.result(ssrsReportStr(DocSalesInvoice, Report)); PrintMgmtReportFormatName formatName = THK_PrintMgmtDocTypeEventHandler::getPrintMgmtReportFormat(_docType); if (formatName) { _result.result(formatName); } else { _result.result(ssrsReportStr(SalesInvoice, Report)); } break; } } public static PrintMgmtReportFormatName getPrintMgmtReportFormat(PrintMgmtDocumentType _printMgmtDocumentType) { PrintMgmtDocInstance printMgmtDocInstance; PrintMgmtReportFormat printMgmtReportFormat; PrintMgmtSettings printMgmtSettings; select firstonly DocumentType, RecId from printMgmtDocInstance where printMgmtDocInstance.DocumentType == _printMgmtDocumentType join ParentId, ReportFormat from printMgmtSettings where printMgmtSettings.ParentId == printMgmtDocInstance.RecId join RecId, DocumentType, Name from printMgmtReportFormat where printMgmtReportFormat.RecId == printMgmtSettings.ReportFormat && printMgmtReportFormat.DocumentType == _printMgmtDocumentType; return printMgmtReportFormat.Name; } }
添加一个新的Document type
通过以下步骤可以添加一个新的Document type
创建PrintMgmtDocumentType的Coc扩展,添加一个新的节点
创建Node class ( 例如PrintMgmtNode_Purch
)中方法getDocumentTypes
的Coc扩展
[ExtensionOf(classStr(PrintMgmtNode_Purch))] public final class PrintMgmtNode_Purch_Demo_Extension { /// /// Gets a list of valid document types for the node. /// /// /// A list of valid document types for the node. /// /// /// The results can vary based on what is configured in the application because configuration keys are /// used to determine this list. /// public List getDocumentTypes() { List ret = next getDocumentTypes(); ret.addEnd(PrintMgmtDocumentType::customPurchPromptLetter); return ret; } }
之后就可以在Print management 中看到我们新加的节点了
创建新的Form letter类
这个类用来返回 hierarchy 和前面创建的document type
[PrintMgmtDocumentTypeFactoryAttribute(PrintMgmtDocumentType::customPurchPromptLetter)] public class customPurchFormLetterReport_PromptLetter extends PurchFormLetterReport { /// /// Returns the default printer settings for the specified PrintSetupOriginalCopy enumeration value. /// /// /// The PrintSetupOriginalCopy enumeration value that specifies whether the Original /// or Copy destinations should be retrieved. /// /// /// The default printer settings for the specified PrintSetupOriginalCopy enumeration value. /// /// /// The general pattern for implementing this method is to use the printer destinations from the appropriate /// FormLetter class. These printer destinations will be used if no Print Management destinations are /// found or used. /// protected container getDefaultPrintJobSettings(PrintSetupOriginalCopy _printCopyOriginal) { if (_printCopyOriginal == PrintSetupOriginalCopy::Original) { return PurchFormLetter::getPrinterSettingsFormletter(DocumentStatus::None,PrintSetupOriginalCopy::Original); } else { return PurchFormLetter::getPrinterSettingsFormletter(DocumentStatus::None,PrintSetupOriginalCopy::Copy); } } /// /// Returns the PrintMgmtDocumentType enumeration value that specifies what document this FormLetterReport class controls. /// /// /// The PrintMgmtDocumentType enumeration value that specifies what document this FormLetterReport class controls. /// /// /// This value is used to retrieve the appropriate Print Management settings for the report. /// public PrintMgmtDocumentType getPrintMgmtDocumentType() { return PrintMgmtDocumentType::customPurchPromptLetter; } /// /// Returns the PrintMgmtHierarchyType enumeration value that specifies what hierarchy this FormLetterReport class uses. /// /// /// The PrintMgmtHierarchyType enumeration value that specifies what hierarchy this FormLetterReport class uses. /// /// /// This value is used to retrieve the appropriate Print Management settings for the report. /// protected PrintMgmtHierarchyType getPrintMgmtHierarchyType() { return PrintMgmtHierarchyType::Purch; } /// /// Returns the PrintMgmtNodeType enumeration value that specifies what node this FormLetterReport class uses. /// /// /// The PrintMgmtNodeType enumeration value that specifies what node this FormLetterReport class uses. /// /// /// This value is used to retrieve the appropriate Print Management settings for the report. /// protected PrintMgmtNodeType getPrintMgmtNodeType() { return PrintMgmtNodeType::PurchTable; } }
最后Coc扩展populator类
这个类的作用可以参考前文“添加一个新的Report format”
/// /// Populates the PrintMgmtReportFormat table used for print management with the MyProject documents. /// [ExtensionOf(classStr(PrintMgmtReportFormatPopulator))] public final class PrintMgmtReportFormatPopulatorAppSuite_custom_Extension { #ISOCountryRegionCodes #PrintMgmtSetup protected void addDocuments() { // Purchasing documents this.customAddPurchaseDocuments(); next addDocuments(); } /// /// Adds purchase records to the PrintMgmtReportFormat table. /// protected void customAddPurchaseDocuments() { this.addOther(PrintMgmtDocumentType::customPurchPromptLetter, ssrsReportStr(customPurchPromptLetterReport, Report), ssrsReportStr(customPurchPromptLetterReport, Report), #NoCountryRegionId); } }