分享 单据/动态表单 大批量Setvalue循环优化技巧
应用场景:单据或者动态表单的单据体需通过setvalue循环赋值时,数据量较多的情况下会出现严重的性能问题
以下是个人项目实战的一些处理技巧:
//第一步 获取当前的单据数据包
var CostVouchDetail = this.View.Model.DataObject;
//第二步创建 当前的单据单据视图,用以接收数据包,赋值赋值数据
var tDetailView = CreateView("SJY_DepartCostVouchDetail");
//第三步 把第一部创建的数据包绑定第二步创建的单据视图
tDetailView.Model.DataObject=CostVouchDetail;
//第四步 在这以后你就可以对tDetailView进行耗费性能的大批量setVale操作,因为是操作插件内存中创建的单据
视图并不会涉及与前台的刷新渲染效率上会快非常多,但仍然可以触发值更新等数据变化
tDetailView.Model.SetValue(dc.ColumnName, val, i);
tDetailView.Model.SetValue(dc.ColumnName, val, i);
tDetailView.Model.SetValue(dc.ColumnName, val, i);
.....
.....
//第五步 把处理完的数据包赋值给当前打开单据的view
this.View.Model.DataObject = tDetailView.Model.DataObject;
//第六步 刷新当前页面,操作完成啦
this.View.UpdateView("FEntity");
/// <summary>
/// 创建单据视图
/// </summary>
/// <param name="ctx"></param>
/// <param name="metaData"></param>
/// <returns></returns>
public Kingdee.BOS.Core.DynamicForm.IDynamicFormView CreateView(string formId)
{
FormMetadata metadata = FormMetaDataCache.GetCachedFormMetaData(context, formId);
var OpenParameter = CreateOpenParameter(context, metadata);
var Provider = metadata.BusinessInfo.GetForm().GetFormServiceProvider(true);
string importViewClass = "Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web";
Type type = Type.GetType(importViewClass);
Kingdee.BOS.Core.DynamicForm.IDynamicFormView view = (Kingdee.BOS.Core.DynamicForm.IDynamicFormView)Activator.CreateInstance(type);
((Kingdee.BOS.Core.DynamicForm.IDynamicFormViewService)view).Initialize(OpenParameter, Provider);
return view;
}
/// <summary>
/// 创建输入参数
/// </summary>
/// <param name="ctx"></param>
/// <param name="metaData"></param>
/// <returns></returns>
public Kingdee.BOS.Core.Bill.BillOpenParameter CreateOpenParameter(Kingdee.BOS.Context ctx, Kingdee.BOS.Core.Metadata.FormMetadata metaData)
{
Kingdee.BOS.Core.Metadata.FormElement.Form form = metaData.BusinessInfo.GetForm();
Kingdee.BOS.Core.Bill.BillOpenParameter openPara = new Kingdee.BOS.Core.Bill.BillOpenParameter(form.Id, metaData.GetLayoutInfo().Id);
openPara = new Kingdee.BOS.Core.Bill.BillOpenParameter(form.Id, string.Empty);
openPara.Context = ctx;
openPara.ServiceName = form.FormServiceName;
openPara.PageId = Guid.NewGuid().ToString();
// 单据
openPara.FormMetaData = metaData;
openPara.LayoutId = metaData.GetLayoutInfo().Id;
// 操作相关参数
openPara.Status = Kingdee.BOS.Core.Metadata.OperationStatus.ADDNEW;
openPara.PkValue = null;
openPara.CreateFrom = Kingdee.BOS.Core.Metadata.CreateFrom.Default;
openPara.ParentId = 0;
openPara.GroupId = "";
openPara.DefaultBillTypeId = null;
openPara.DefaultBusinessFlowId = null;
// 修改主业务组织无须用户确认
openPara.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
// 插件
List<Kingdee.BOS.Core.DynamicForm.PlugIn.AbstractDynamicFormPlugIn> plugins = form.CreateFormPlugIns();
openPara.SetCustomParameter(Kingdee.BOS.Core.FormConst.PlugIns, plugins);
return openPara; //t3f3v3t3v4
}
分享 单据/动态表单 大批量Setvalue循环优化技巧
本文2024-09-16 18:26:31发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22162.html