二开案例.单据插件.单据审核中字段解锁(加强版)
【应用场景】
单据已进入审核中状态,通过插件解锁某些字段,使之可以被修改保存。
【案例演示】
采购申请单,单据状态审核中,解锁申请人字段。
【实现步骤】
<1>编写单据插件,代码如下。
using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Util; using System; using System.ComponentModel; using System.Reflection; namespace Jac.XkDemo.BOS.Business.PlugIn { /// <summary> /// 【单据插件】单据审核中字段解锁 /// 普通版:https://vip.kingdee.com/article/348435650867523328 /// 加强版:https://vip.kingdee.com/article/352121538449613312 /// </summary> [Description("【单据插件】单据审核中字段解锁"), HotUpdate] public class UnLockFieldWhenAuditBillPlugIn : AbstractBillPlugIn { private const string FieldKey = "FApplicantId"; public override void AfterBindData(EventArgs e) { base.AfterBindData(e); UnLockField(FieldKey); } public override void BeforeBindData(EventArgs e) { base.BeforeBindData(e); UnLockField(FieldKey); } public override void AfterLoadData(EventArgs e) { base.AfterLoadData(e); UnLockField(FieldKey); } public override void AfterUpdateViewState(EventArgs e) { base.AfterUpdateViewState(e); UnLockField(FieldKey); } public override void AfterDoOperation(AfterDoOperationEventArgs e) { base.AfterDoOperation(e); if (e.Operation.OperationId == 8) { UnLockField(FieldKey); } } /// <summary> /// 解锁字段 /// </summary> /// <param name="key"></param> private void UnLockField(string key) { // 工作流插件:Kingdee.BOS.Workflow.PlugIns.WorkflowControl.WorkflowControlEdit.AfterLoadData,该插件会判断当前用户是否是当前单据的当前流程节点的处理人,如果不是,会把单据状态从编辑状态改为查看状态。 // 如果仍然不能解锁字段,请把此段代码的取消注释 //if (this.View.OpenParameter.Status == OperationStatus.VIEW) //{ // this.View.OpenParameter.Status = OperationStatus.EDIT; // // 启动修改网控 // var result = this.View.StartNetworkCtrl(); // if (!result.StartSuccess) // { // // 启动网控失败,为避免数据修改冲突,改回查看状态 // this.View.OpenParameter.Status = OperationStatus.VIEW; // } //} // 解锁保存按钮 this.View.GetMainBarItem("tbSplitSave").Enabled = true; // 解锁实体服务规则产生的锁定控制 //var entityServiceRuleUd = "14642d1f-46c6-4afa-aa52-f7e19a21c776";// 实体服务规则的内码要去元数据XML中获取 //this.View.StyleManager.SetEnabled(key, entityServiceRuleUd, true); // 解锁单据状态产生的锁定控制 //this.View.StyleManager.SetEnabled(key, "BillStatusByHead", true); //this.View.StyleManager.SetEnabled(key, "BillStatusByEntry", true); // 解锁其它未知的锁定控制 this.View.StyleManager.SetEnabled(key, "", true); // 解锁初始状态的锁定控制 UnLockFieldInitStatus(key); // 解锁初始状态的锁定控制 UnLockFieldFormState(key); //this.View.ShowMessage("字段已解锁!"); } /// <summary> /// 解锁初始状态的锁定控制 /// </summary> /// <param name="key"></param> /// <returns></returns> private void UnLockFieldInitStatus(string key) { try { var bosStyleManager = this.View.StyleManager; var _enabledStore = RefUtils.GetFieldValue(bosStyleManager, BindingFlags.Instance | BindingFlags.NonPublic, "_enabledStore"); if (_enabledStore == null) { return; } var _controlInitAppearanceStyles = RefUtils.GetFieldValue(_enabledStore, _enabledStore.GetType().BaseType.BaseType.BaseType, BindingFlags.Instance | BindingFlags.NonPublic, "_controlInitAppearanceStyles"); if (_controlInitAppearanceStyles == null) { return; } var hasKey = RefUtils.GetMethodInvokeValue(_controlInitAppearanceStyles, BindingFlags.Instance | BindingFlags.Public, "ContainsKey", new object[] { key }); if (hasKey == null || !Convert.ToBoolean(hasKey)) { return; } object value2 = null; var enabledValue = RefUtils.GetMethodInvokeValue(_controlInitAppearanceStyles, BindingFlags.Instance | BindingFlags.Public, "TryRemove", new object[] { key, value2 }); } catch { } } /// <summary> /// 解锁界面状态管理器的锁定控制 /// </summary> /// <param name="key"></param> private void UnLockFieldFormState(string key) { try { //_formState.SetEnabled(key, newValue); var bosStyleManager = this.View.StyleManager; var _formState = RefUtils.GetFieldValue(bosStyleManager, BindingFlags.Instance | BindingFlags.NonPublic, "_formState") as IDynamicFormState; if (_formState == null) { return; } _formState.SetEnabled(key, true); } catch { } } #region 反射工具类 /// <summary> /// 反射工具类 /// </summary> public static class RefUtils { /// <summary> /// 获取字段值 /// </summary> /// <param name="instance"></param> /// <param name="bindingAttr"></param> /// <param name="fieldName"></param> /// <returns></returns> public static object GetFieldValue(object instance, BindingFlags bindingAttr, string fieldName) { return GetFieldValue(instance, instance.GetType(), bindingAttr, fieldName); } /// <summary> /// 获取字段值 /// </summary> /// <param name="instance"></param> /// <param name="instranceType"></param> /// <param name="bindingAttr"></param> /// <param name="fieldName"></param> /// <returns></returns> public static object GetFieldValue(object instance, Type instranceType, BindingFlags bindingAttr, string fieldName) { var field = instranceType.GetField(fieldName, bindingAttr); if (field == null) { return null; } return field.GetValue(instance); } /// <summary> /// 调用方法,获取方法返回值 /// </summary> /// <param name="instance"></param> /// <param name="bindingAttr"></param> /// <param name="methodName"></param> /// <param name="methodArgs"></param> /// <returns></returns> public static object GetMethodInvokeValue(object instance, BindingFlags bindingAttr, string methodName, object[] methodArgs) { return GetMethodInvokeValue(instance, instance.GetType(), bindingAttr, methodName, methodArgs); } /// <summary> /// 调用方法,获取方法返回值 /// </summary> /// <param name="instance"></param> /// <param name="instranceType"></param> /// <param name="bindingAttr"></param> /// <param name="methodName"></param> /// <param name="methodArgs"></param> /// <returns></returns> public static object GetMethodInvokeValue(object instance, Type instranceType, BindingFlags bindingAttr, string methodName, object[] methodArgs) { var method = instranceType.GetMethod(methodName, bindingAttr); return method.Invoke(instance, methodArgs); } } #endregion } }
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购申请单,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开采购申请单编辑界面,此时,申请人字段已解释,可进行修改保存。
---------------------------------------------------------------------------------------------------------
【参考资料】
【二开案例.单据插件.获取字段的锁定性策略集合】https://vip.kingdee.com/article/350580818924171008
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.单据审核中字段解锁(加强版)
【应用场景】单据已进入审核中状态,通过插件解锁某些字段,使之可以被修改保存。【案例演示】采购申请单,单据状态审核中,解锁申请人字段...
点击下载文档
本文2024-09-23 03:59:05发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162358.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章