二开插件如何获取分页报表数据?原创
金蝶云社区-dev_charles
dev_charles
17人赞赏了该文章 534次浏览 未经作者许可,禁止转载编辑于2024年06月27日 10:32:43

        /// <summary>

        /// 获取基础资料数据包

        /// </summary>

        /// <param name="ctx"></param>

        /// <param name="FormNumber">基础资料编码</param>

        /// <param name="PKId">基础资料内码</param>

        /// <returns></returns>

        private DynamicObject GetDynamicObject(Context ctx,string FormNumber,string PKId)

        {

            FormMetadata formMetaData = MetaDataServiceHelper.Load(ctx, FormNumber) as FormMetadata;

            DynamicObject dynamicObject = BusinessDataServiceHelper.LoadSingle(ctx, PKId, formMetaData.BusinessInfo.GetDynamicObjectType());

            return dynamicObject;

        }


        /// <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 DataTable GetReportData(Context ctx, string rptFormId, string rptFilterFormId, string schemeId, int currentPosition)

        {

            var dt = new DataTable();

            try

            {

                var sysReportService = ServiceFactory.GetSysReportService(ctx);

                var permissionService = ServiceFactory.GetPermissionService(ctx);


                //此处以存货收发存明细表分页账表为例

                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();//过滤方案的主键值,可通过该SQL语句查询得到:SELECT * FROM T_BAS_FILTERSCHEME

          

                var filter = model.GetFilterParameter();


                var filterObj = filter.CustomFilter;


                //过滤条件值,根据实际情况给值

                var ACCTGSYSTEMID = "1";

                var OrgId = Convert.ToString(this.Context.CurrentOrganizationInfo.ID);

                var AcctPolicyId = "1";

                var matId = "283955";


                var acctsystemDynamic = GetDynamicObject(ctx, "Org_AccountSystem", ACCTGSYSTEMID);

                var acctOrgIdDynamic = GetDynamicObject(ctx, "ORG_Organizations", OrgId);

                var acctPolicyIdDynamic = GetDynamicObject(ctx, "BD_ACCTPOLICY", AcctPolicyId);

                var matDynamic = GetDynamicObject(ctx, "BD_MATERIAL", matId);


                IRptParams rptParam = new RptParams();

                rptParam.FormId = reportFilterMetadata.BusinessInfo.GetForm().Id;

                rptParam.CurrentPosition = 0;//分页账表当前位置,官方提示除分页报表外,该值始终为0可不用理会,默认给0

                rptParam.StartRow = 1;

                rptParam.EndRow = int.MaxValue;//StartRow和EndRow是报表数据分页的起始行数和截至行数,一般取所有数据,所以EndRow取int最大值。

                rptParam.FilterParameter = filter;

                rptParam.FilterFieldInfo = model.FilterFieldInfo;


                //自定义条件赋值

                var dic = new Dictionary<string, object>();

                dic.Add("CustomFilter", filter.CustomFilter);

                rptParam.CustomParams.Add("OpenParameter", dic);


                //需要修改的过滤条件

                rptParam.FilterParameter.CustomFilter["ACCTGSYSTEMID"] = acctsystemDynamic;

                rptParam.FilterParameter.CustomFilter["ACCTGSYSTEMID_Id"] = ACCTGSYSTEMID;

                rptParam.FilterParameter.CustomFilter["ACCTGORGID"] = acctOrgIdDynamic;

                rptParam.FilterParameter.CustomFilter["ACCTGORGID_Id"] = OrgId;

                rptParam.FilterParameter.CustomFilter["ACCTPOLICYID"] = acctPolicyIdDynamic;

                rptParam.FilterParameter.CustomFilter["ACCTPOLICYID_Id"] = AcctPolicyId;

                rptParam.FilterParameter.CustomFilter["Year"] = "2024";

                rptParam.FilterParameter.CustomFilter["Period"] = "4";

                rptParam.FilterParameter.CustomFilter["ENDYEAR"] = "2024";

                rptParam.FilterParameter.CustomFilter["EndPeriod"] = "4";

                rptParam.FilterParameter.CustomFilter["MATERIALID_Id"] = matId;

                rptParam.FilterParameter.CustomFilter["MATERIALID"] = matDynamic;

                rptParam.FilterParameter.CustomFilter["ENDMATERIALID_Id"] = matId;

                rptParam.FilterParameter.CustomFilter["ENDMATERIALID"] = matDynamic;

                rptParam.FilterParameter.CustomFilter["FDimType"] = "0";

                rptParam.FilterParameter.CustomFilter["CHXEXPENSE"] = "true";


                //下面两种方法都可获取到明细表信息

                using (DataTable datatable = sysReportService.GetData(ctx, reportMetadata.BusinessInfo, rptParam))

                {

                    return datatable;

                }


                //MoveReportServiceParameter param = new MoveReportServiceParameter(ctx, reportMetadata.BusinessInfo, Guid.NewGuid().ToString(), rptParam);

                //var repData = sysReportService.GetListAndReportData(param);

            }

            catch(Exception ex)

            {


            }

            return dt;


        }


图标赞 17
17人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!