
【场景】套打重复打印多份
【案例】采购订单,根据输入的打印份数重复打印多份(两个方案)
方案一:完全根据生成的纸张生成多份,不支持节纸
方案二:针对行数据生成多次
```csharp
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.NotePrint;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DynamicFormPlugIn.NotePrint
{
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("套打 重复份数打印")]
public class NotePrintRepearPlugIn : AbstractBillPlugIn
{
private int RepearVersion = 0;
public override void BarItemClick(BarItemClickEventArgs e)
{
RepearVersion = 0;
if (string.Equals(e.BarItemKey, "tb_CustomPreviewV1", StringComparison.OrdinalIgnoreCase))
{
RepearVersion = 1;
this.View.InvokeFormOperation("PrintPreview");
return;
}
if (string.Equals(e.BarItemKey, "tb_CustomPreviewV2", StringComparison.OrdinalIgnoreCase))
{
RepearVersion = 2;
this.View.InvokeFormOperation("PrintPreview");
return;
}
}
/// <summary>
/// 方案一:套打打印任务干预事件,复制生成多个打印任务
/// 缺点:打印任务之间不支持合并在一个纸张
/// </summary>
/// <param name="e"></param>
public override void BeforeNotePrintCommand(BeforeNotePrintEventArgs e)
{
if (RepearVersion != 1)
return;
RepearVersion = 0;
//重复份数
int repactCount = GetRepeatCnt();
List<PrintJob> newPrintJobs = new List<PrintJob>();
foreach (var oldPrintJob in e.PrintJobs)
{
if (oldPrintJob == null)
continue;
if(oldPrintJob.IsEconomizePaper)
{
//节纸不处理
newPrintJobs.Add(oldPrintJob);
continue;
}
foreach (var oldJobItem in oldPrintJob.PrintJobItems)
{
if (oldJobItem == null)
continue;
//对一个单据重复多次打印
PrintJob economizeJob = new PrintJob()
{
FormId = oldPrintJob.FormId,
PrintJobItems = new List<PrintJobItem>(),
};
for (int i = 0; i < repactCount; ++i)
{
economizeJob.PrintJobItems.Add(new PrintJobItem(oldJobItem.BillId, oldJobItem.TemplateId));
}
newPrintJobs.A