二开案例.过滤插件.列表过滤窗体上隐藏分录

【应用场景】列表过滤窗体上隐藏分录,同时将该分录的字段在过滤条件的字段集合中移除。

【案例演示】采购订单列表过滤界面,仅显示单据头【基本信息】,其它分录全部隐藏,对应字段也在过滤,高级过滤,快捷过滤的字段集合中移除。

【解决方案】
<1>编写列表过滤插件,控制列表过滤界面上的分录不可见,过滤条件下的字段不可见。
<2>编写列表插件,控制列表界面上的快捷过滤下的字段不可见。
【实现步骤】
<1>编写列表过滤插件,代码如下。
using Kingdee.BOS.Core.CommonFilter;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.List.PlugIn.Args;
using Kingdee.BOS.Core.ListFilter;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【过滤插件】列表过滤窗体上隐藏分录
/// </summary>
[Description("【过滤插件】列表过滤窗体上隐藏分录"), HotUpdate]
public class HideFilterEntityListFilterPlugIn : AbstractListFilterPlugIn
{
/// <summary>
///在过滤窗体中可见的单据体Key集合(注意:单据头必须显示和选中)
/// </summary>
private string[] showEntityKeys = { "FBillHead" };
public override void FireBeforeBindFilterMetadata(EventArgs e)
{
base.FireBeforeBindFilterMetadata(e);
if (this.Model.BillBusinessInfo != null && this.Model.BillBusinessInfo.GetForm().Id.Equals("PUR_PurchaseOrder", StringComparison.OrdinalIgnoreCase))
{
var filterModel = (IListFilterModelService)this.Model;
// 方案1:移除指定分录,移除了一了百了,不再需要配合AfterBindData事件使用(此方案反射调用了私有变量,未来可能存在兼容性风险,使用需慎重)
// EntityObject._filterEntities定义:Dictionary<string, FilterEntity> _filterEntities
var filterEntities = (Dictionary<string, FilterEntity>)GetValue(filterModel.EntityObject, "_filterEntities");
var removeFilterEntityKeys = filterEntities.Keys.Where(o => !showEntityKeys.Contains(o, StringComparer.OrdinalIgnoreCase)).ToArray();
foreach (var key in removeFilterEntityKeys)
{
filterEntities.Remove(key);
}
return;
// 方案2:不移除指定分录,仅反选和禁用指定分录,需配合AfterBindData事件使用(推荐使用此方案)
ResetSelectedEntityKeys(filterModel.EntityObject, showEntityKeys);
// 获取当前单据的所有分录标识
var entities = this.Model.BillBusinessInfo.Entrys;
foreach (var entity in entities)
{
var filterEntity = filterModel.EntityObject.GetEntity(entity.Key);
if (filterEntity == null)
{
continue;
}
if (!showEntityKeys.Contains(filterEntity.Key, StringComparer.OrdinalIgnoreCase))
{
filterEntity.Selected = false; // 此设置无效,后续版本会修复......
filterEntity.Visible = false; // 隐藏前必须先将分录取消勾选
}
}
}
}
public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);
if (this.Model.BillBusinessInfo != null && this.Model.BillBusinessInfo.GetForm().Id.Equals("PUR_PurchaseOrder", StringComparison.OrdinalIgnoreCase))
{
var filterModel = (IListFilterModelService) this.Model;
ResetSelectedEntityKeys(filterModel.EntityObject, showEntityKeys);
}
}
/// <summary>
/// 不可见的分录,取消勾选
/// </summary>
/// <param name="entityObject"></param>
/// <param name="showEntityKeys"></param>
private static void ResetSelectedEntityKeys(En
二开案例.过滤插件.列表过滤窗体上隐藏分录
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



