
【场景】套打模板打印一个单据体的多个子单据体,且子单据体需要上下布局;
一般的客户的配置结构如下:

但是系统不支持数据表格嵌套布局表格的行高自适应。
比如系统中的检验单 检测项目 + 使用决策
【变通方案1】单据逐分录打印,需要写二开代码
(0)说明:该方案适用于每一明细显示一页的场景
(1)将模板外层的数据表格去掉,仅保留布局表格的逻辑,布局表格的逻辑一般都是取当前行的明细和对应的子单据体的所有行

(2)验证连续套打所选分录,选中一个分录,能够使用该模板打印选中分录的子单据体

(3)插件代码,本质就是模拟选中每一个分录单独打印的逻辑,所以每个分录单独放一页

```csharp
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.NotePrint;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DynamicFormPlugIn.NotePrint
{
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("单据按照明细分录逐行打印")]
public class NotePrintPlugIn_PrintByEachSingleRow : AbstractBillPlugIn
{
public override void OnInitialize(InitializeEventArgs e)
{
this.View.ConcurrentSession["PrintByEachSingleRow"] = new PrintByEachSingleRow(this.Context, this.View.BillBusinessInfo, "FEntity");
}
public override void BarItemClick(BarItemClickEventArgs e)
{
(this.View.ConcurrentSession["PrintByEachSingleRow"] as PrintByEachSingleRow).Check(e);
}
public override void BeforeNotePrintCommand(BeforeNotePrintEventArgs e)
{
(this.View.ConcurrentSession["PrintByEachSingleRow"] as PrintByEachSingleRow).PreparePrintJob(e.PrintJobs);
}
}
public class PrintByEachSingleRow
{
private readonly Context Ctx;
private readonly BusinessInfo BillBusinessInfo;
private readonly string EntityKey;
private bool printByEachSingleRow;
public PrintByEachSingleRow(Context ctx, BusinessInfo businessInfo, string entityKey)
{
Ctx = ctx;
BillBusinessInfo = businessInfo;
EntityKey = entityKey;
}
public void Check(BarItemClickEventArgs e)
{
printByEachSingleRow = false;
if (string.Equals(e.BarItemKey, "tb_PrintByEachSingleRow", StringComparison.OrdinalIgnoreCase))
printByEachSingleRow = true;
}
/// <summary>
/// 将打印任务替换为逐行分录执行的逻辑
/// </summary>
/// <param name="printJobList"></param>
public void PreparePrintJob(List<PrintJob> printJobList)
{
if (!printByEachSingleRow)
return;
List<PrintJob> newPrintJobList = new List<PrintJob>();
foreach (var printJob in printJobList)
{
if (printJob == null || printJob.PrintJobItems == null || !printJob.PrintJobItems.Any())
continue;
foreach (var printJobItem in printJob.PrintJobItems)
{
if (printJobItem == null)
continue;
newPrintJobList.AddRange(GenerateSingleRowJob(printJob.FormId, printJobItem));
}
}
printJobList.Clear();
newPrintJobList.ForEach(x => printJobList.Add(x));
}
/// <summary>
/// 获取指定单据的所有分录内码,按照序号排序
/// </summary>
/// <param name="billId"></param>
/// <returns></returns>
private List<string> GetAllEntityIdsOrderBySeq(string billId)
{
Entity entity = this.BillBusinessInfo.GetEntity(EntityKey);
string strSql = string.Format("SELECT {0} FROM {1} WHERE {2}=@billId ORDER BY {3} ASC",
entity.EntryPkFieldName, entity.TableName,
this.BillBusinessInfo.GetForm().PkFieldName, entity.SeqFieldKey);
KDDbType dbType = KDDbType.Int32;
switch (this.BillBusinessInfo.GetForm().PkFieldTy