插件二开:单据插件.根据单据类型动态切换视图
一、概述
本篇主要介绍单据插件.根据单据类型动态切换视图。
二、详情
客户案例:客户通过实体服务规则设置了单据类型在不同条件的值,在新增打开后,单据类型是按预期设置正确的,但单据类型对应的视图并未刷新。
以下通过【表单插件】方式实现动态切换视图,参考如下:
using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.Linq; namespace BOS.Debug.PCPlugIn { /// <summary> /// 表单插件 /// </summary> [System.ComponentModel.Description("表单插件---根据单据类型切换视图"),HotUpdate] public class BillPlugIn_BillTypeChangeView : AbstractBillPlugIn { public override void AfterBindData(EventArgs e) { base.AfterBindData(e); //按单据类型切换视图(这里只是按当前案例需要放在AfterBindData,实际以业务需要调整如:BarItemClick) var billTypeId = ((DynamicObject)this.Model.GetValue("FBillTypeID"))[0] as String; this.BillTypeChanged(billTypeId); } /// <summary> /// 获取单据类型对应的视图ID /// </summary> /// <param name="billTypeId">单据类型ID</param> /// <returns></returns> private string GetLayoutId(string billTypeId=null) { var billTypeField = this.View.BillBusinessInfo.GetBillTypeField(); if (string.IsNullOrWhiteSpace(billTypeId)) { //获取单据类型ID //var enumList = billTypeField.BuildEnumList(); billTypeId = ((DynamicObject)this.Model.GetValue(billTypeField))[0].ToString(); } var BillType = billTypeField.BillTypeInfo.First(o => o["Id"].ToString() == billTypeId); var layoutId = BillType["LayoutSolution_Id"].ToString(); return layoutId; } /// <summary> /// 切换单据类型(通过ShowForm刷新视图) /// </summary> /// <param name="billTypeId"></param> /// <param name="layoutId"></param> private void BillTypeChanged(string billTypeId) { //只在新增时可切换单据类型的视图 if (this.View.OpenParameter.Status == OperationStatus.ADDNEW) { var layoutId = GetLayoutId(billTypeId); if (layoutId == this.View.OpenParameter.LayoutId) return; var para = new BillShowParameter(); this.CopyCustomeParameter(para); para.OpenStyle.ShowType = ShowType.InCurrentForm; para.FormId = this.View.OpenParameter.FormId; para.DefaultBillTypeId = billTypeId; para.LayoutId = layoutId; para.Status = this.View.OpenParameter.Status; para.PKey = null; para.ParentPageId = this.View.OpenParameter.ParentPageId; // PageId必须确保一致 para.PageId = this.View.PageId; // 本view标记为已经失效,需要重新构建 this.View.OpenParameter.IsOutOfTime = true; this.View.ShowForm(para); } } /// <summary> /// 复制用户定制的属性 /// </summary> /// <param name="para"></param> private void CopyCustomeParameter(BillShowParameter para) { Type openParamType = this.View.OpenParameter.GetType(); var properties = openParamType.GetProperties(); List<string> IsnotCustomerPropertyKeys = new List<string>() { "pk", "billType" }; // 复制定制参数 var customerParams = this.View.OpenParameter.GetCustomParameters(); if (customerParams != null && customerParams.Count > 0) { foreach (var item in customerParams) { if (IsnotCustomerPropertyKeys.Contains(item.Key)) continue; if (item.Value == null) continue; if (!(item.Value is string)) continue; // 只复制字符串参数 var prop = properties.FirstOrDefault((p) => p.Name.EqualsIgnoreCase(item.Key)); if (prop != null) continue; para.CustomParams[item.Key] = Convert.ToString(item.Value); } } } } }
注:编译的组件需要放在站点的bin目录,并注册在【表单插件】中,保存后,记得IIS重启
插件二开:单据插件.根据单据类型动态切换视图
一、概述本篇主要介绍单据插件.根据单据类型动态切换视图。二、详情客户案例:客户通过实体服务规则设置了单据类型在不同条件的值,在新增...
点击下载文档
本文2024-09-23 03:57:25发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162184.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章