二开单据需要做单据转换时,出现选单操作可以重复选相同的单,业务需求在选单时要控制已选的单在过滤列表中过滤掉;
处理方式:
一、通过转换插件OnCreateDrawTarget事件构建选单数据包前清空原来单据体数据;
参考路径:https://vip.kingdee.com/article/197799254830438400?productLineId=1
二、通过下游单单据插件控制,在OnChangeConvertRuleEnumList方法中,将选单条件策列中的附加条件CustFilter重新设置;需要注意重新设置的条件会存入缓存中,再次新做单时,要先将上次存入的附加条件清空;具体代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.List.PlugIn.Args;
using System.Collections.ObjectModel;
using Kingdee.BOS.Core.Metadata.ConvertElement;
using Kingdee.BOS.Core.Metadata.EntityElement;
namespace FinancialBillPlugIn
{
public class FPPPBill : AbstractBillPlugIn
{
private bool _isDraw = false; //是否为选单操作
/// <summary>
/// 选单时控制不能重复选单
/// </summary>
/// <param name="e"></param>
public override void OnChangeConvertRuleEnumList(ChangeConvertRuleEnumListEventArgs e)
{
base.OnChangeConvertRuleEnumList(e);
if (this._isDraw)
{
//获取OA流水号
String OaBillNo = Convert.ToString(this.Model.GetValue("下游OA流水号标识"));
//获取分录明细
Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
DynamicObjectCollection entryRows = this.Model.GetEntityDataObject(entity);
List<string> srcBillList = new List<string>();
foreach (DynamicObject row in entryRows)
{
//获取源单分录中存放的上游单据编号
if (!row["FSourceBillNo"].IsNullOrEmptyOrWhiteSpace())
{
srcBillList.Add(Convert.ToString(row["FSourceBillNo"]));
}
}
if (!OaBillNo.IsNullOrEmptyOrWhiteSpace() && srcBillList.Count > 0)
{
Collection<ConvertPolicyElement> dynamicObjects = e.Convertrules[0].Policies;
foreach (ConvertPolicyElement convertPolicyElement in dynamicObjects)
{
ConvertFilterPolicyElement billTypeMapPolicy = convertPolicyElement as ConvertFilterPolicyElement;
if (billTypeMapPolicy != null)
{
//将过滤条件存入选单条件策列中
billTypeMapPolicy.CustFilter = string.Format("上游OA流水号标识 = '{0}' AND FBillNo NOT IN ('{1}')", OaBillNo, string.Join("','", srcBillList.ToArray()));
}
}
}
else
{
Collection<ConvertPolicyElement> dynamicObjects = e.Convertrules[0].Policies;
foreach (ConvertPolicyElement convertPolicyElement in dynamicObjects)
{
ConvertFilterPolicyElement billTypeMapPolicy = convertPolicyElement as ConvertFilterPolicyElement;
if (billTypeMapPolicy != null)
{
//清空存入的选单条件策列
billTypeMapPolicy.CustFilter = "";
}
}
}
}
}
/// <summary>
/// 操作前事件,确定什么操作
/// </summary>
/// <param name="e"></param>
public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
{
base.BeforeDoOperation(e);
this._isDraw = false;
if (e.Operation.FormOperation.Operation == "Draw")
{
this._isDraw = true;
}
}
}
}
效果图:
未选单时,过滤出所有可选数据
选单后,根据下游单据界面获取的条件过滤
再次选择追加分录数据,不清除原有数据
推荐阅读