二开案例.单据插件.设置单据类型可选项
【应用场景】
通过插件控制单据类型的可选项和默认项。
【案例演示】
采购订单,当登录用户为demo时,仅显示标准采购订单和标准委外订单。
【实现步骤】
<1>编写单据插件,代码如下。
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【单据插件】设置单据类型可选项
/// </summary>
[Description("【单据插件】设置单据类型可选项"), HotUpdate]
public class SetBillTypeItemsBillPlugIn : AbstractBillPlugIn
{
public override void BeforeBindData(EventArgs e)
{
base.BeforeBindData(e);
var billTypeField = this.Model.BusinessInfo.GetBillTypeField();
if (billTypeField == null)
{
return;
}
// 设置单据类型的下拉列表可选项
var editor = this.View.GetFieldEditor<ComboFieldEditor>(billTypeField.Key, 0);
var items = billTypeField.BuildEnumList();
if (this.Context.UserName == "demo")
{
if (items.Count > 2)
{
items.RemoveRange(2, items.Count - 2);
}
}
// 设置默认单据类型
var defalutBillTypeId = this.View.OpenParameter.GetCustomParameter("jac_defalutBillTypeId") as string;
if (string.IsNullOrWhiteSpace(defalutBillTypeId))
{
defalutBillTypeId = items[1].Value;
}
SetBillTypeDefValue(billTypeField, defalutBillTypeId);
editor.SetComboItems(items);
}
public override void DataChanged(DataChangedEventArgs e)
{
base.DataChanged(e);
var billTypeField = this.Model.BusinessInfo.GetBillTypeField();
if (billTypeField == null)
{
return;
}
if (e.Field.Key == billTypeField.Key)
{
var billTypeObjs = this.Model.GetValue(billTypeField.Key) as DynamicObject;
if (billTypeObjs != null)
{
this.View.OpenParameter.SetCustomParameter("jac_defalutBillTypeId", billTypeObjs[0].ToString());
}
}
}
/// <summary>
/// 设置单据类型默认值
/// </summary>
private void SetBillTypeDefValue(BillTypeField billTypeField, string defBillTypeId)
{
if (billTypeField != null && !string.IsNullOrWhiteSpace(defBillTypeId))
{
var billTypeObj = this.Model.LoadReferenceData(billTypeField.RefFormDynamicObjectType, defBillTypeId);
billTypeField.RefIDDynamicProperty.SetValue(this.Model.DataObject, defBillTypeId);
billTypeField.DynamicProperty.SetValue(this.Model.DataObject, billTypeObj);
}
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>用demo用户登录业务站点,打开采购订单新增界面,此时单据类型可选项已只剩下两项。
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.设置单据类型可选项
本文2024-09-23 04:19:16发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164556.html