根据数据库动态加载列
执行存储过程的数据信息,并将数据读取过来
将读取的状态值 存入缓存中 CacheUtil.SetCache(this.Context.GetAreaCacheKey(), "111", KEY, headData, TimeSpan.FromMilliseconds(60000));
构件列时读取缓存值 object v = CacheUtil.GetCache(this.Context.GetAreaCacheKey(), "111", KEY);
根据缓存的内容自动构建表格
public class JCDAbstractReportPlugIn :SysReportBaseService
{
string KEY = DateTime.Now.ToString("yyyyMMddHHmmss");
//public override void Initialize()
// { //初始化
// base.Initialize();
// // 简单账表类型:普通、树形、分页
// this.ReportProperty.ReportType = ReportType.REPORTTYPE_NORMAL;
// this.IsCreateTempTableByPlugin = false;
// }
//设置单据列
public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
{
DynamicObject dyFilter = filter.FilterParameter.CustomFilter;//快捷页签过滤条件
//lstParam.Add(new SqlParam("@EndTime", DbType.AnsiString, "2024-09-01"));
//DBUtils.ExecuteStoreProcedure(this.Context, "PROC_getGYData", lstParam); //调用存储过程
string execSql = string.Format("exec PROC_getGYData '{0}','{1}','{2}','{3}','{4}','{5}'", tableName, "51101064", "", "22", "2024-06-01", "2024-09-01");
DynamicObjectCollection objList = DBUtils.ExecuteDynamicObject(this.Context, execSql);
string headType = "";
string headType2 = "";
string headType3 = "";
string headType4 = "";
foreach (DynamicObject obj in objList)
{
if (headType == "" && obj["FBillTypeName"] != null)
{
headType = obj["FBillTypeName"].ToString();
}
if (headType2 == "" && obj["FBillTypeName2"] != null)
{
headType2 = obj["FBillTypeName2"].ToString();
}
if (headType3 == "" && obj["FBillTypeName3"] != null)
{
headType3 = obj["FBillTypeName3"].ToString();
}
if (headType4 == "" && obj["FBillTypeName4"] != null)
{
headType4 = obj["FBillTypeName4"].ToString();
}
}
string headData = headType+"," + headType2+"," + headType3 +"," + headType4;
CacheUtil.SetCache(this.Context.GetAreaCacheKey(), "111", KEY, headData, TimeSpan.FromMilliseconds(60000));
}
/// <summary>
/// 得到页面列表显示列头,动态增加列
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
public override ReportHeader GetReportHeaders(IRptParams filter)
{
base.GetReportHeaders(filter);
ReportHeader header = new ReportHeader();
object v = CacheUtil.GetCache(this.Context.GetAreaCacheKey(), "111", KEY);
char[] separators = new char[] { ',' };
string[] headType = v.ToString().Split(separators);
if (headType[0] != "")
{
header.AddChild("FNumber", new LocaleValue("产品&产品编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FName", new LocaleValue("产品&产品名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FPH", new LocaleValue("产品&产品牌号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
dealHeader(header, headType[0],"1");
}
if (headType[1] != "")
{
header.AddChild("FNumber2", new LocaleValue("一级BOM&物料编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FName2", new LocaleValue("一级BOM&物料名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FLot2", new LocaleValue("一级BOM&批号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
dealHeader(header, headType[1], "2");
}
if (headType[2] != "")
{
header.AddChild("FNumber3", new LocaleValue("二级BOM&物料编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FName3", new LocaleValue("二级BOM&物料名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FLot3", new LocaleValue("二级BOM&批号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
dealHeader(header, headType[2], "3");
}
if (headType[3] != "")
{
header.AddChild("FNumber4", new LocaleValue("三级BOM&物料编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FName4", new LocaleValue("三级BOM&物料名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FLot4", new LocaleValue("三级BOM&批号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
dealHeader(header, headType[3], "4");
}
return header;
}
public ReportHeader dealHeader(ReportHeader header,string type,string level)
{
if (type == "类型1")
{
header.AddChild("FCT"+ level, new LocaleValue("Ct,%", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FCO" + level, new LocaleValue("Ct,%", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
}
else if (type == "类型2")
{
header.AddChild("FCO" + level, new LocaleValue("Ct,%", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FO" + level, new LocaleValue("O,%", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FNi" + level, new LocaleValue("Ni,%", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
header.AddChild("FTi" + level, new LocaleValue("Ti,%", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
}
return header;
}
}
推荐阅读