二开案例.单据插件.切换视图
【应用场景】
通过插件的方式,切换单据视图,刷新单据界面。
【案例演示】
采购订单,通过下拉列表显示所有扩展上的视图,并且可任意切换视图。
【实现步骤】
<1>编写单据插件,代码如下。
using Kingdee.BOS; using Kingdee.BOS.App.Data; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace Jac.XkDemo.BOS.Business.PlugIn { /// <summary> /// 【单据插件】切换视图 /// </summary> [Description("【单据插件】切换视图"), HotUpdate] public class ChangeLayoutFormPlugIn : AbstractBillPlugIn { public override void AfterBindData(EventArgs e) { base.AfterBindData(e); BindComboField(); var layoutId = Convert.ToString(this.View.OpenParameter.GetCustomParameter("Jac_LayoutId", true)); if (!string.IsNullOrWhiteSpace(layoutId)) { // 切换视图后,下拉列表绑定当前视图 this.Model.DataObject["F_Jac_Combo"] = layoutId; this.View.UpdateView("F_Jac_Combo"); } } public override void DataChanged(DataChangedEventArgs e) { base.DataChanged(e); if (e.Field.Key.EqualsIgnoreCase("F_Jac_Combo")) { var layoutId = e.NewValue as string; var para = new BillShowParameter(); CopyCustomeParameter(para); para.OpenStyle.ShowType = ShowType.InCurrentForm; para.FormId = this.View.OpenParameter.FormId; para.DefaultBillTypeId = ((DynamicObject)this.Model.GetValue(this.View.BillBusinessInfo.GetBillTypeField())).ToString(); 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; para.CustomParams["Jac_LayoutId"] = layoutId; this.View.ShowForm(para); } } /// <summary> /// 复制用户定制的属性 /// </summary> /// <param name="para"></param> private void CopyCustomeParameter(BillShowParameter para) { var openParamType = this.View.OpenParameter.GetType(); var properties = openParamType.GetProperties(); var 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); } } } /// <summary> /// 将当前业务对象的扩展节点上的视图,绑定到下拉列表 /// </summary> private void BindComboField() { var enumList = GetEnumItems(this.Context); var comboList = this.View.GetFieldEditor<ComboFieldEditor>("F_Jac_Combo", 0); if (comboList != null) { comboList.SetComboItems(enumList); } } /// <summary> /// 从数据库读取自定义数据源并转换成枚举项集合 /// </summary> /// <param name="ctx"></param> /// <returns></returns> private List<EnumItem> GetEnumItems(Context ctx) { // 获取视图数据 var enumList = new List<EnumItem>(); var enumItem = new EnumItem(); enumItem.Caption = new LocaleValue("默认"); enumItem.EnumId = ""; enumItem.Invalid = false; enumItem.Value = ""; enumList.Add(enumItem); var sql = string.Format(@"SELECT a.FID,b.FNAME FROM T_META_OBJECTTYPEVIEW a LEFT JOIN T_META_OBJECTTYPEVIEW_L b ON a.FID=b.FID AND b.FLOCALEID=2052 JOIN T_META_OBJECTTYPE c ON a.FDEPENDENCYOBJECTID=c.FID WHERE c.FINHERITPATH LIKE '%,{0},%' AND c.FMODELTYPEID=100 AND c.FDEVTYPE=2 ", this.View.BillBusinessInfo.GetForm().Id); var objs = DBUtils.ExecuteDynamicObject(ctx, sql); if (objs != null && objs.Count > 0) { foreach (var obj in objs) { enumItem = new EnumItem(); enumItem.Caption = new LocaleValue(obj["FNAME"].ToString()); enumItem.EnumId = obj["FID"].ToString(); enumItem.Invalid = false; enumItem.Value = obj["FID"].ToString(); enumList.Add(enumItem); } } return enumList; } } }
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,新增一个下拉列表字段用于绑定视图数据,新建两个视图,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开采购订单新增界面,切换视图,效果如下图。
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.切换视图
【应用场景】通过插件的方式,切换单据视图,刷新单据界面。【案例演示】采购订单,通过下拉列表显示所有扩展上的视图,并且可任意切换视图...
点击下载文档
本文2024-09-23 04:01:38发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162637.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章