套打实现分组之间排序
金蝶云社区-王文亮
王文亮
7人赞赏了该文章 1509次浏览 未经作者许可,禁止转载编辑于2018年04月18日 15:11:53

套打数据表格具备分组功能,可以指定一个分组依据字段进行分组打印,那么分组间的顺序是否可以指定呢?答案是可以通过二开实现。如发货通知单打印


套打模板里面指定了按"备注"进行分组


打印预览效果

现在通过插件把备注为空的分组放到后面,直接上插件代码
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Orm.DataEntity;

namespace TestPrintPlugin
{
public class GroupSortPrintPlugin : AbstractBillPlugIn
{

public override void OnPrepareNotePrintData(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePrintDataEventArgs e)
{

if (e.DataSourceId.Equals("FEntity", StringComparison.OrdinalIgnoreCase))
{

List notePrintEntryRows = new List();
foreach (DynamicObject obj in e.DataObjects)
{
notePrintEntryRows.Add(obj);
}

//升序
//notePrintEntryRows = notePrintEntryRows.OrderBy(o => o["FNoteEntry"]).ToList();
//降序
notePrintEntryRows = notePrintEntryRows.OrderByDescending(o => o["FNoteEntry"]).ToList();

e.DataObjects = notePrintEntryRows.ToArray();

}

base.OnPrepareNotePrintData(e);

}
}
}
[/code]编译后将插件注册到表单插件中

重启IIS后,再次执行打印预览,可以看到分组间顺序已经调整

那么问题又来了,分组内的顺序是否可以指定呢,比如分组内根据销售数量进行排序?答案是可以的,在数据表格属性里面指定排序字段即可

保存模板看下打印预览效果,分组内已经按销售数量从大到小排序

当然,既然已经二开了,分组内的排序也可以在二开代码里通过直接指定多个排序字段实现。
notePrintEntryRows = notePrintEntryRows.OrderByDescending(o => o["FNoteEntry"]).ThenByDescending(o => o["FQty"]).ToList();