public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
{
IDBService service = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>();
string tmpDataTbl = service.CreateTemporaryTableName(this.Context);
//获取数据
base.BuilderReportSqlAndTempTable(filter, tmpDataTbl);
//获取快捷过滤参数
var cusfilter = filter.FilterParameter.CustomFilter["F_YDL_ZDY"] as DynamicObjectCollection;
// 因为是单据体,所以我们需要遍历单据体里面的数据
if (cusfilter.Count() >= 0)
{
// 声明一个List类似,用来封装过滤条件
List<string> tzhValues = new List<string>(cusfilter.Count);
for (int i = 0; i < cusfilter.Count; i++)
{
tzhValues.Add(Convert.ToString(cusfilter[i]["F_TZH"]));
}
// 把List 拼成string类型的过滤的条件
string inClauseValues = string.Join(", ", tzhValues.Select(v => $"'{v}'"));
//string sql = string.Format(@"
// CREATE TABLE {0} AS
// SELECT A2.*
// FROM {1} A2
// LEFT JOIN T_BD_MATERIAL TT ON A2.FMATERIALID = TT.FMATERIALID
// WHERE TT.F_TZH IN ({2})",
// tableName,
// tmpDataTbl,
// inClauseValues);
// 把数据拼回临时表
string sql = string.Format(@"
SELECT A2.* INTO {0}
FROM {1} AS A2
LEFT JOIN T_BD_MATERIAL AS TT ON A2.FMATERIALID = TT.FMATERIALID
WHERE TT.F_TZH IN ({2})",
tableName,
tmpDataTbl,
inClauseValues);
DBUtils.Execute(this.Context, sql);
return;
}
//过滤数据
//tableName是最终返回的报表数据
string sqlText = string.Format(@"SELECT * INTO {0} FROM {1} ", tableName, tmpDataTbl);
DBUtils.Execute(this.Context, sqlText);
}
推荐阅读