金蝶云星空——创建简单账表
参考:https://vip.kingdee.com/article/226013527986004992?productLineId=1&lang=zh-CN
参考:https://vip.kingdee.com/article/37120?productLineId=1&lang=zh-CN
参考:https://vip.kingdee.com/article/377783954302429184?productLineId=1&lang=zh-CN
参考:https://vip.kingdee.com/article/235813563204221952?lang=zh-CN&productLineId=1
参考:https://vip.kingdee.com/article/42279?productLineId=1&lang=zh-CN
这是一个最简单的示例
功能是:查询供应商的信息,筛选条件是FNumber(这个是供应商的代码)
-
首先需要创建一个简单账表:新建-->空白对象-->简单账表
-
创建一个筛选窗口:新建-->模板继承-->动态表单-->公共过滤
-
将过滤窗口的标识,复制粘贴到简单账表的"过滤窗口业务对象(报表)"属性上
-
之后开发一个服务插件,给简单账表绑定数据
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts.Report;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Orm.DataEntity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
namespace WeiWaiFaLiaoQingDan3
{
[Description("简单账表-服务插件")]
public class MyFirstJianDanZhangBiao : SysReportBaseService
{
//初始化
public override void Initialize()
{
base.Initialize();
base.ReportProperty.ReportType = 0;
base.ReportProperty.ReportName = new LocaleValue("helloMyFirst", base.Context.UserLocale.LCID);
this.IsCreateTempTableByPlugin = true;
base.ReportProperty.IsUIDesignerColumns = false;
base.ReportProperty.IsGroupSummary = false;
base.ReportProperty.SimpleAllCols = false;
base.ReportProperty.PrimaryKeyFieldName = "FIDENTITYID";
base.ReportProperty.IsDefaultOnlyDspSumAndDetailData = true;
}
//动态构造列
public override ReportHeader GetReportHeaders(IRptParams filter)
{
List<SummaryField> summaryField = this.SummarySpecialFields;
ReportHeader header = new ReportHeader();
header.AddChild("FCUSTID", new LocaleValue("客户ID", this.Context.UserLocale.LCID));
header.AddChild("FNUMBER", new LocaleValue("客户", this.Context.UserLocale.LCID));
header.AddChild("FNAME", new LocaleValue("名称", this.Context.UserLocale.LCID), SqlStorageType.SqlText);
header.AddChild("FINVOICETITLE", new LocaleValue("名称", this.Context.UserLocale.LCID), SqlStorageType.SqlText);
return header;
}
/// 构造取数Sql,取数据填充到临时表:tableName
public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
{
base.BuilderReportSqlAndTempTable(filter, tableName);
DynamicObject customFilter = filter.FilterParameter.CustomFilter;
string fnumber = customFilter["FNUMBER"].ToString();
//注意1:金蝶的模式就是必须将查询结果保存在一个实体的临时表中 ,所以这里一定需要一个Into操作
//注意2:简单账表的每一条记录必须要有唯一ID,在初始化中设置ID名称,这里是FIDENTITYID
string text = $"SELECT ROW_NUMBER() OVER (ORDER BY FCUSTID) AS FIDENTITYID, FCUSTID, FNUMBER, FNAME, FINVOICETITLE into {tableName} FROM dbo.V_AC_BD_Customer where Fnumber like '%{fnumber}%'";
DBUtils.ExecuteDynamicObject(base.Context, text, null, null, CommandType.Text, new SqlParam[0]);
}
//设置单据头:将过滤字段填写在单据头中
public override ReportTitles GetReportTitles(IRptParams filter)
{
var result = base.GetReportTitles(filter);
DynamicObject dyFilter = filter.FilterParameter.CustomFilter;
if (dyFilter != null)
{
if (result == null)
{
result = new ReportTitles();
}
result.AddTitle("FNumber", Convert.ToString(dyFilter["FNumber"]));
}
return result;
}
}
}
- 说明:比较麻烦的就是金蝶云星空的需要将绑定的数据源存放在实体表临时表中,这个所谓的临时表就是一张实体表,由金蝶自动创建
若是绑定的数据源是通过存储过程查询,则需要将金蝶自动创建的实体临时表作为参数传递给存储过程,下面是在存储过程中的最终操作:
--将需要绑定的数据源查询存储在#tempResult,之后再保存在金蝶创建的的实体临时表中
DECLARE @sql NVARCHAR(1000) =N'select * into {@TempTableName} from #tempResult';
SET @sql=REPLACE(@sql, '{@TempTableName}', @TempTableName);
EXEC sp_executesql @sql;