套打实现分组之间排序
金蝶云社区-天冥异
天冥异
2人赞赏了该文章 1490次浏览 未经作者许可,禁止转载编辑于2018年08月02日 20:23:05

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

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

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

打印预览效果


现在通过插件把备注为空的分组放到后面,直接上插件代码
  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using System.Threading.Tasks;


  6. using Kingdee.BOS.Core.Bill.PlugIn;

  7. using Kingdee.BOS.Orm.DataEntity;



  8. namespace TestPrintPlugin

  9. {

  10.     public class GroupSortPrintPlugin : AbstractBillPlugIn

  11.     {


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

  13.         {


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

  15.             {


  16.                 List<DynamicObject> notePrintEntryRows = new List<DynamicObject>();

  17.                 foreach (DynamicObject obj in e.DataObjects)

  18.                 {

  19.                     notePrintEntryRows.Add(obj);

  20.                 }


  21.                 //升序

  22.                 //notePrintEntryRows = notePrintEntryRows.OrderBy(o => o["FNoteEntry"]).ToList();

  23.                 //降序

  24.                 notePrintEntryRows = notePrintEntryRows.OrderByDescending(o => o["FNoteEntry"]).ToList();


  25.                 e.DataObjects = notePrintEntryRows.ToArray();


  26.             }


  27.             base.OnPrepareNotePrintData(e);


  28.         }

  29.     }

  30. }


复制代码

编译后将插件注册到表单插件中



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




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


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



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


赞 2