二开案例.账表.单据中获取分页账表数据

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

二开案例.账表.单据中获取分页账表数据

**【应用场景】** 单据中获取分页账表每页的数据。 **【案例演示】** <1>编写单据插件,动态构建分页账表视图并获取数据,代码如下。 ``` csharp 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.Core.Report; using Kingdee.BOS.Model.ReportFilter; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Serialization; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Text; namespace Kingdee.BOS.PlugInTest { [Description("【单据插件】获取分页账表数据"), HotUpdate] public class GetMoveReportBillPlugIn : AbstractBillPlugIn { private FormMetadata _reportMetadata = null; private IRptParams _rptParam = null; /// <summary> /// 菜单点击事件 /// </summary> /// <param name="e"></param> public override void BarItemClick(BarItemClickEventArgs e) { base.BarItemClick(e); if (e.BarItemKey.EqualsIgnoreCase("tbGetMoveReportData")) { // rpt.DataSource 获取账表的DataTable Dictionary<int, IMoveReport> rtnDIc = new Dictionary<int, IMoveReport>(); // 库存账龄分析表【STK_InvAgeAnalyzeRpt】 // 库存账龄分析表过滤框 【STK_InvAgeAnalyzeFilter】 // 通过T_BAS_FILTERSCHEME查询过滤方案ID 【66a45b74a29579】 var rpt = GetReportData(this.Context, "STK_InvAgeAnalyzeRpt", "STK_InvAgeAnalyzeFilter", "66a45b74a29579", 0); rtnDIc[0] = rpt; // 获取其他分页 if (rpt.ListCount > 1) { for (int i = 1; i < rpt.ListCount; i++) { var tmpRpt = GetReportData(this.Context, i); rtnDIc[i] = tmpRpt; } } // 执行后续操作,这里是展示信息 StringBuilder str = new StringBuilder(1024); str.AppendLine(string.Format("账表共有{0}分页", rpt.ListCount)); for (int i = 0; i < rpt.ListCount; i++) { var tmpRpt = rtnDIc[i]; str.AppendLine(string.Format("分页{0}对应临时表{1},共有{2}条数据", i + 1, tmpRpt.DataSource.TableName, tmpRpt.DataSource.Rows.Count)); } this.View.ShowMessage(str.ToString()); } } /// <summary> /// 获取分页账表数据 /// </summary> /// <param name="ctx">执行上下文</param> /// <param name="rptFormId">账表FormId</param> /// <param name="rptFilterFormId">账表过滤方案FormId</param> /// <param name="schemeId">过滤方案内码</param> /// <param name="currentPosition">分页账表当前位置</param> /// <returns></returns> private IMoveReport GetReportData(Context ctx, string rptFormId, string rptFilterFormId, string schemeId, int currentPosition) { var filterMetadata = FormMetaDataCache.GetCachedFilterMetaData(ctx); // 加载分页报表元数据 var reportMetadata = FormMetaDataCache.GetCachedFormMetaData(ctx, rptFormId); // 加载分页报表过滤条件框元数据 var reportFilterMetadata = FormMetaDataCache.GetCachedFormMetaData(ctx, rptFilterFormId); var reportFilterServiceProvider = reportFilterMetadata.BusinessInfo.GetForm().GetFormServiceProvider(); var model = new SysReportFilterModel(); model.SetContext(ctx, reportFilterMetadata.BusinessInfo, reportFilterServiceProvider); model.FormId = reportFilterMetadata.BusinessInfo.GetForm().Id; model.FilterObject.FilterMetaData = filterMetadata; model.InitFieldList(reportMetadata, reportFilterMetadata); model.GetSchemeList(); var entity = model.Load(schemeId); var dyn = DeserializeCustomFilter(reportFilterMetadata.BusinessInfo, entity.CustomFilterSetting); model.DataObject = dyn; var filter = model.GetFilterParameter(); IRptParams rptParam = new RptParams(); rptParam.FormId = reportFilterMetadata.BusinessInfo.GetForm().Id; // 分页账表当前位置 rptParam.CurrentPosition = currentPosition; // StartRow和EndRow是报表数据分页的起始行数和截至行数,一般取所有数据,所以EndRow取int最大值。 rptParam.StartRow = 1; rptParam.EndRow = int.MaxValue; rptParam.FilterParameter = filter; rptParam.FilterFieldInfo = model.FilterFieldInfo; var dic = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); foreach (var itemProp in dyn.DynamicObjectType.Properties) { dic[itemProp.Name] = dyn[itemProp.Name]; } rptParam.CustomParams.Add("OpenParameter", dic); // 赋值给全局变量,给后续查询使用 this._reportMetadata = reportMetadata; this._rptParam = rptParam; // 查询数据 MoveReportServiceParameter param = new MoveReportServiceParameter(ctx, reportMetadata.BusinessInfo, Guid.NewGuid().ToString(), rptParam); return SysReportServiceHelper.GetListAndReportData(param); } /// <summary> /// 获取自定义参数 /// </summary> /// <param name="businessInfo">过滤方案元数据</param> /// <param name="xml"></param> /// <returns></returns> private DynamicObject DeserializeCustomFilter(BusinessInfo businessInfo, string xml) { DcxmlBinder binder = new DynamicObjectDcxmlBinder(businessInfo); binder.OnlyDbProperty = false; DcxmlSerializer target = new DcxmlSerializer(binder); // 切换到中性语言,获取主差量 binder.Culture = CultureInfo.InvariantCulture; // 集合忽略主键冲突 target.ColloctionIgnorePKValue = true; DynamicObject obj = (DynamicObject)target.DeserializeFromString(xml, null); return obj; } /// <summary> /// 获取分页账表数据 /// </summary> /// <param name="ctx">执行上下文</param> /// <param name="currentPosition">分页账表当前位置</param> /// <returns></returns> private IMoveReport GetReportData(Context ctx, int currentPosition) { // 更新分页下标 this._rptParam.CurrentPosition = currentPosition; // 查询数据 MoveReportServiceParameter param = new MoveReportServiceParameter(ctx, this._reportMetadata.BusinessInfo, Guid.NewGuid().ToString(), this._rptParam); return SysReportServiceHelper.GetListAndReportData(param); } } } ``` <2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。 <4>注册插件。 ![注册插件.webp](/download/01008de861b87c8742158fd02c833102d19c.webp) <4>现在可以登业务站点,验证一下结果。 ![单据中获取分页账表数据.webp](/download/0100f3f9086608814450bcdf848c52656ac1.webp)

二开案例.账表.单据中获取分页账表数据

**【应用场景】** 单据中获取分页账表每页的数据。**【案例演示】** <1>编写单据插件,动态构建分页账表视图并获取数据,代码如...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息