账表二开(如何将现有列作为过滤条件)原创
金蝶云社区-popcat
popcat
4人赞赏了该文章 384次浏览 未经作者许可,禁止转载编辑于2023年08月01日 10:42:35

账表二开(如何将现有列作为过滤条件) 

我们在对账表进行二开添加字段的时候,可能会有将现有列作为过滤条件的需求

(不知道怎么二开的小伙伴可以看一下这位老师的帖子:报表二次开发添加自定义字段的指导方案 (kingdee.com)

补充一点小知识:星空系统里面有些账表比较特殊,我们在进行二开的时候如果遇到列不显示的问题记得要重载

public override ReportHeader GetReportHeaders(IRptParams filter)  方法)

例如:我要将 销售订单执行明细表 的 应收数量 作为筛选条件

image.png

首先,我们找到bos里面对应的字段名称

image.png

然后在过滤框里面添加字段

image.png

我们要知道,条件过滤是存在于下面这个属性里面的,并且系统会帮我们拼接好,我写的时候以为到这一步就大功告成了,但事实并没有我想象的那么简单

filter.FilterParameter.FilterString;//条件过滤

我在注册测插件后就遇到了一个报错

先选择应收数量等于一的条件

image.png

当我点击执行的时候出现报错

image.png

在我感到疑惑的时候我决定去数据库里面看看到底有没有这一列

image.png

显而易见它是存在的,至于为什么会报错,我猜测可能是条件是在生成临时表之前执行的,导致报错,具体原因,如果有大佬知道还请赐教!!

那么我们即想要系统生成的条件过滤的字符串,又不想要报错该怎么办呢

我的解决方案如下:

            string b =  filter.FilterParameter.FilterString;//条件过滤(将条件过滤字符串赋值给变量)
            filter.FilterParameter.FilterString = "";//将原有的条件清除防止报错
            base.BuilderReportSqlAndTempTable(filter, strTable);//生成原有报表(旧表的生成)
            
            string c = $" where 1=1 ";
            if (b != null&&!string.IsNullOrWhiteSpace(b))
                c += $"and {b}";//拼接过滤条件
            List<SqlParam> lstParam = new List<SqlParam>();


            lstParam.Add(new SqlParam("@oldtablename", KDDbType.String, strTable));

            lstParam.Add(new SqlParam("@newtablename", KDDbType.String, tableName));
            lstParam.Add(new SqlParam("@File", KDDbType.String, c));

            DBUtils.ExecuteStoreProcedure(this.Context, "SAL_detailReportdemo", lstParam); //调用存储过程 生成新表

这样就可以完美解决问题。

示例如下:

using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.K3.SCM.App.Sal.Report;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace XLx_HTS_Report
{
    [Description("销售订单执行明细表扩展")]
    [HotUpdate]
    public class Class2 : SalDetailRpt
    {
        public string[] oldTableList;
        public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
        {
            IDBService dBService = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>();
            oldTableList = dBService.CreateTemporaryTableName(this.Context, 1);
            string strTable = oldTableList[0];
            DynamicObject customFilter = filter.FilterParameter.CustomFilter;//快捷过滤
           
            
            string b =  filter.FilterParameter.FilterString;//条件过滤
            //filter.FilterParameter.FilterString = "";
            base.BuilderReportSqlAndTempTable(filter, strTable);
            
            string c = $" where 1=1 ";
            if (b != null&&!string.IsNullOrWhiteSpace(b))
                c += $"and {b}";
            List<SqlParam> lstParam = new List<SqlParam>();


            lstParam.Add(new SqlParam("@oldtablename", KDDbType.String, strTable));

            lstParam.Add(new SqlParam("@newtablename", KDDbType.String, tableName));
            lstParam.Add(new SqlParam("@File", KDDbType.String, c));

            DBUtils.ExecuteStoreProcedure(this.Context, "SAL_detailReportdemo", lstParam); //调用存储过程 


        }
        public override void CloseReport()
        {
            if (oldTableList.IsNullOrEmptyOrWhiteSpace())
            {
                return;
            }
            IDBService dBService = Kingdee.BOS.App.ServiceHelper.GetService<Kingdee.BOS.Contracts.IDBService>();
            dBService.DeleteTemporaryTableName(this.Context, oldTableList);
            base.CloseReport();
        }
        public override ReportHeader GetReportHeaders(IRptParams filter)
        {
            //return base.GetReportHeaders(filter);
            ReportHeader header = base.GetReportHeaders(filter);
             header.AddChild("F_PETW_COMBO1", new LocaleValue("列名"));
            
             header.AddChild("F_PETW_ASSISTANT", new LocaleValue("列名"));
            
            
            return header;
        }
    }
}


赞 4