说明:
通过转换插件事件实现自定义排序,比如子单据体,目前没有任何默认排序,可能源单数据会错乱。
案例:
实现每行分录下的子单据体按序号排序,前提条件单据体和子单据体都有序号。
实现:
1.在构建参数事件中加入子单据体序号作为需要取的来源数据
2.在取到源单据数据后事件中先按单据体序号排序后按子单据体序号排序
插件代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
namespace Kingdee.BOS.TestPlugIn.Demo
{
[HotUpdate]
[Description("按子单据内码或序号进行排序")]
public class ConvertSortDemoPlugIn : AbstractConvertPlugIn
{
//子单据体序号
private string _subEntrySeqPropertyName;
//单据体序号
private string _entrySeqPropertyName;
/// <summary>
/// 得到相关属性和加入序号字段
/// </summary>
/// <param name="e"></param>
public override void OnQueryBuilderParemeter(QueryBuilderParemeterEventArgs e)
{
base.OnQueryBuilderParemeter(e);
//前提得存在子单据体的携带,假设子单据的key为FSubEntityKey
//子单据体默认内码已加入需要查询的字段
var subEntryEntity = e.SourceBusinessInfo.GetEntryEntity("FSubEntityKey") as SubEntryEntity;
if(String.IsNullOrWhiteSpace(subEntryEntity.ParentEntity.SeqFieldKey)) return;
this._entrySeqPropertyName = string.Concat(subEntryEntity.ParentEntity.Key, "_", subEntryEntity.ParentEntity.SeqFieldKey);
if (!string.IsNullOrWhiteSpace(subEntryEntity.SeqFieldKey))
{
//加入子单据提序号查询字段
string seq = string.Concat(subEntryEntity.Key, "_", subEntryEntity.SeqFieldKey);
e.DicFieldAlias[seq] = seq;
SelectorItemInfo selectItem = new SelectorItemInfo(seq);
e.SelectItems.Add(selectItem);
this._subEntrySeqPropertyName = seq;
}
}
/// <summary>
/// 直接对取到的源单数据报进行排序
/// </summary>
/// <param name="e"></param>
public override void OnGetSourceData(GetSourceDataEventArgs e)
{
base.OnGetSourceData(e);
//按单据体序号和子单据体序号排序
if(String.IsNullOrWhiteSpace(_entrySeqPropertyName) || String.IsNullOrWhiteSpace(_subEntrySeqPropertyName)) return;
var sortData = e.SourceData.OrderBy(x => x[this._entrySeqPropertyName]).ThenBy(x => x[this._subEntrySeqPropertyName]);
DynamicObjectCollection sortedData = new DynamicObjectCollection(e.SourceData[0].DynamicObjectType);
foreach(var data in sortData)
{
sortedData.Add(data);
}
//改成排序后的数据
e.SourceData = sortedData;
}
}
}
推荐阅读