核算维度余额表,显示自定义字段原创
14人赞赏了该文章
211次浏览
编辑于2023年12月29日 10:54:44
参考教程:
https://vip.kingdee.com/article/285118202751868703
在查询 “应收账款1122”时,由于之前这个科目仅设置了“客户”维度,没有设置“员工”维度,导致无法根据员工维度显示数据,所以需要增加自定义字段,并重写临时表并查询到该客户对应的销售员并赋值到对应的字段中。
按照上面的教程,在报表与过滤框中添加对应的自定义字段。
容易忽视的小细节:
1、重写哪个插件
2、关于添加好的自定义字段不显示的问题
public override ReportHeader GetReportHeaders(IRptParams filter) { ReportHeader header = base.GetReportHeaders(filter); //返回base的字段再加, header.AddChild("实际的字段名", new Kingdee.BOS.LocaleValue("销售员", this.Context.LogLocale.LCID)); return header; }
有时候,需要判断过滤条件,又不清楚过滤条件的值,则可以把值显示在动态列的标题中,用于调试使用
DynamicObject customFilter = filter.FilterParameter.CustomFilter;
var weidu = customFilter["DETAILGROUP"];
header.AddChild("F_SSMM_Text", new Kingdee.BOS.LocaleValue(weidu, this.Context.LogLocale.LCID));
调试完恢复原来标题
3、继承哪一个插件
public class 你的类名: AccountingItemsBalanceService,并在工程中引入这个插件的dll文件
重写的查询方式如下,详细请查看上面的参考链接,F_SSMM_Text修改为自己的字段名,
string strSql = @"/*dialect*/select t1.*,t4.FName as F_SSMM_Text into {0} from {1} t1 left join T_BD_CUSTOMER t2 on t2.FNUMBER = t1.FDETAILNUMBER left join T_BD_OPERATORENTRY t3 on t3.FENTRYID=t2.FSELLER left join T_BD_STAFF_L t4 on t4.FSTAFFID=t3.FSTAFFID and t4.FLOCALEID=2052";
完整代码,增加了判断,只有维度中有客户时,才显示销售员数据,如果是其他维度,则不显示
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Kingdee.BOS.Contracts; using Kingdee.BOS.Contracts.Report; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Report; using System.ComponentModel; using Kingdee.BOS.App.Data; using Kingdee.K3.FIN.GL.App.Report; using Kingdee.BOS.Orm.DataEntity; namespace ABC.ZongZhang.ServicePlugIn.report { [Kingdee.BOS.Util.HotUpdate] [Description("重写核销维度余额表插件-显示销售员")] public class ShowSalesman : AccountingItemsBalanceService { private string[] TempTableName; public override ReportHeader GetReportHeaders(IRptParams filter) { ReportHeader header = base.GetReportHeaders(filter); //返回base的字段再加 DynamicObject customFilter = filter.FilterParameter.CustomFilter; var weidu = customFilter["DETAILGROUP"]; if (weidu != null && weidu.ToString().Equals("BD_Customer")) { header.AddChild("F_SSMM_Text", new Kingdee.BOS.LocaleValue("销售员", this.Context.LogLocale.LCID)); } return header; } //重写创建临时表方法 public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName) { //创建临时表用于保存自己的数据 IDBService dbservice = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>(); TempTableName = dbservice.CreateTemporaryTableName(this.Context, 1); string strTable = TempTableName[0]; //调用基类方法,获取初步的查询结果 base.BuilderReportSqlAndTempTable(filter, strTable); //对初步的查询结果处理,然后回填到默认的存放查询结果到临时表 StringBuilder sb = new StringBuilder(); string strSql; DynamicObject customFilter = filter.FilterParameter.CustomFilter; var weidu = customFilter["DETAILGROUP"]; //从快速过滤中,查询维度 if (weidu != null && weidu.ToString().Equals("BD_Customer")) { //关联查询客户表,业务员表,员工多语言表,然后把员工名称显示在自定义字段中 strSql = @"/*dialect*/select t1.*,t4.FName as F_SSMM_Text into {0} from {1} t1 left join T_BD_CUSTOMER t2 on t2.FNUMBER = t1.FDETAILNUMBER left join T_BD_OPERATORENTRY t3 on t3.FENTRYID=t2.FSELLER left join T_BD_STAFF_L t4 on t4.FSTAFFID=t3.FSTAFFID and t4.FLOCALEID=2052"; } else { strSql = @"/*dialect*/select t1.* into {0} from {1} t1 "; } sb.AppendFormat(strSql, tableName, strTable); DBUtils.Execute(this.Context, sb.ToString()); } public override void CloseReport() { //删除临时表 if (TempTableName == null || TempTableName.Length == 0) { return; } IDBService dbservice = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>(); dbservice.DeleteTemporaryTableName(this.Context, TempTableName); base.CloseReport(); } } }
推荐阅读