在表单插件中通过过滤方案得到数据原创
13人赞赏了该文章
1,751次浏览
编辑于2021年10月24日 15:12:50
一、说明:
在表单插件中通过过滤方案得到相关的数据, 在列表插件中修改过滤方案条件
二、表单插件代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using Kingdee.BOS.Util; using Kingdee.BOS.Core; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.List; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Core.Metadata.PreInsertData; using Kingdee.BOS.Core.CommonFilter; using Kingdee.BOS.Model.List; using Kingdee.BOS.Core.ListFilter; using Kingdee.BOS.Model.ListFilter; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.Web.List; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.List.PlugIn; namespace Kingdee.BOS.TestPlugIn22.FormPlugin { [HotUpdate] [Description("单据测试插件")] public class TestFormPlugIn : AbstractDynamicFormPlugIn { public override void ButtonClick(ButtonClickEventArgs e) { var bInfo= this.View.BillBusinessInfo; var form = bInfo.GetForm(); //得到所有的过滤方案 var lstSchemes = BusinessDataServiceHelper.LoadSchemeList(this.Context, form.Id, true, true); var testScheme = lstSchemes.FirstOrDefault(x => x.SchemeName.EqualsIgnoreCase("Test")); if (testScheme != null) { var provider = this.CreateProvider(bInfo); var lstView = (IListViewService)provider.GetService(typeof(IDynamicFormView)); var openParam = this.BuilderOpenParameter(bInfo, testScheme.Id); lstView.Initialize(openParam,provider); lstView.FilterSchemeChanged(KeyConst.CT_QKFILTERPANEL, testScheme.Id); var lstModel = (ListModel)provider.GetService(typeof(IDynamicFormModelService)); //得到数据,得到pk数据之前要先查询一下数据 var datas = lstModel.GetData(0, 90000, false); //rows可以是任何值 var data2 = lstModel.GetPKData(); //得到查询脚本 var sql = lstModel.GetSelectSql(); } } /// <summary> ///构建列表输入参数 /// </summary> private ListOpenParameter BuilderOpenParameter(BusinessInfo bInfo,string schemeId) { var pForm = bInfo.GetForm(); //父表单 var param = new ListOpenParameter(pForm.Id, string.Empty); //列表输入参数 param.Context = this.Context; //上下文 param.FormMetaData = FormMetaDataCache.GetCachedFormMetaData(this.View.Context, pForm.Id);//父表单元数据 param.ListFormMetaData = FormMetaDataCache.GetCachedFormMetaData(this.View.Context, FormIdConst.BOS_List); //列表元数据 param.SetCustomParameter(FormConst.PlugIns, pForm.CreateListPlugIns()); //父表单列表插件 param.SetCustomParameter("filterschemeid", schemeId); //当前过滤方案Id param.SetCustomParameter("listfilterparameter", new ListRegularFilterParameter()); //过滤参数 return param; } /// <summary> /// 构建服务 /// </summary> private IResourceServiceProvider CreateProvider(BusinessInfo bInfo) { FormServiceProvider provider = new FormServiceProvider(); provider.Add(typeof(IDynamicFormView), this.CreateListView(bInfo)); provider.Add(typeof(DynamicFormViewPlugInProxy), new ListViewPlugInProxy()); provider.Add(typeof(DynamicFormModelPlugInProxy), new ListModelPlugInProxy()); provider.Add(typeof(IDynamicFormModelService), this.CreateListModel(bInfo)); Type type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.ListFilter.ListFilterModel,Kingdee.BOS.Model"); var filterModel = (IListFilterModelService)Activator.CreateInstance(type); provider.Add(typeof(IListFilterModelService), filterModel); // 序时簿过滤器模型层实例 type = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DefaultValue.DefaultValueCalculator,Kingdee.BOS.Business.DynamicForm"); provider.Add(typeof(IDefaultValueCalculator), Activator.CreateInstance(type)); // 注册IDBModelService type = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DBModel.DBModelService,Kingdee.BOS.Business.DynamicForm"); provider.Add(typeof(IDBModelService), Activator.CreateInstance(type)); return provider; } /// <summary> /// 创建model /// </summary> private IDynamicFormModelService CreateListModel(BusinessInfo bInfo) { var form = bInfo.GetForm(); Type type = null; if (form.FormGroups != null && form.FormGroups.Count > 0) { var gs = (from g in form.FormGroups where !(g.GroupField.Entity is EntryEntity) select g).ToList(); if (gs.Count > 0) { type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.TreeListModel,Kingdee.BOS.Model"); } } else { type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.ListModel,Kingdee.BOS.Model"); } return (IDynamicFormModelService)Activator.CreateInstance(type); } /// <summary> /// 创建view /// </summary> private IDynamicFormView CreateListView(BusinessInfo bInfo) { var form = bInfo.GetForm(); if (form.FormGroups != null && form.FormGroups.Count > 0) { var gs = (from g in form.FormGroups where !(g.GroupField.Entity is EntryEntity) select g).ToList(); if (gs.Count > 0) { return new TreeListView(); } } return new ListView(); } } }
三、列表插件代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.App.Data; using Kingdee.BOS.Util; using Kingdee.BOS.Core.List.PlugIn.Args; namespace Kingdee.BOS.TestPlugIn.ListPlugIn { [HotUpdate] [Description("单据A列表插件")] public class BillAListPlugIn : AbstractListPlugIn { public override void PrepareFilterParameter(FilterArgs e) { base.PrepareFilterParameter(e); e.FilterString = e.FilterString.Replace("51", "111"); } } }
赞 13
13人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读