Cloud开发动态列的简单账表
阅读原文时间:2023年07月15日阅读:1

业务场景:客户需要根据过滤条件的不同显示不同的列。如下方式可以实现动态的列名。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.Report.PlugIn;
using Kingdee.BOS.Core.Report;
using System.Data;
using Kingdee.BOS.Contracts.Report;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.CommonFilter;
using Kingdee.BOS.Util;
using Kingdee.BOS;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.List;
using System.ComponentModel;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using Kingdee.BOS.Core.DynamicForm;

namespace Report
{
    [Description("部门每月领用数量统计表")]
    public class Report : SysReportBaseService
    {
        public DataSet ds = new DataSet();
        public override void Initialize()
        {
            base.Initialize();
            this.ReportProperty.ReportType = ReportType.REPORTTYPE_NORMAL;
            this.ReportProperty.ReportName = new LocaleValue("部门每月领用数量统计表", base.Context.UserLocale.LCID);
            this.ReportProperty.BillKeyFieldName = "dept";
        }

public override string GetTableName()
        {
            var result = base.GetTableName();
            return result;
        }

public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
        {
            base.BuilderReportSqlAndTempTable(filter, tableName);
            // 获取过滤条件
            DynamicObject customFil = filter.FilterParameter.CustomFilter;
            String StartTime = customFil["F_Dev_StartTime"].ToString();
            String StopTime = customFil["F_Dev_StopTime"].ToString();

string seqFld = string.Format(base.KSQL_SEQ, " dept ");

KSQL_SEQ = string.Format(KSQL_SEQ, "dept asc");
            string sSQL = @"exec P_ExportToChart '" + StartTime + "','" + StopTime + "','{0}','{1}'";
            string sSQLWithNoTempTable = @"exec P_ExportToChartWithNoTempTable '" + StartTime + "','" + StopTime + "'";
            ds = DBServiceHelper.ExecuteDataSet(this.Context, sSQLWithNoTempTable);
            sSQL = string.Format(sSQL, this.KSQL_SEQ, tableName);
            DBUtils.Execute(this.Context, sSQL);
        }

public override ReportTitles GetReportTitles(IRptParams filter)
        {
            ReportTitles titles = new ReportTitles();
            // 获取过滤条件
            DynamicObject customFil = filter.FilterParameter.CustomFilter;
            String StartTime = customFil["F_Dev_StartTime"].ToString();
            String StopTime = customFil["F_Dev_StopTime"].ToString();

titles.AddTitle("FSTARTTIME", StartTime);
            titles.AddTitle("FSTOPTIME", StopTime);
            return titles;
        }
        ///

        /// 构建动态列         ///
        ///
        ///
        public override ReportHeader GetReportHeaders(IRptParams filter)
        {
            // TODO:fentryid,fid,fbaseunitqty,fmaterialid,fbomid,fqty
            ReportHeader header = new ReportHeader();
            //header.AddChild("fwname", new LocaleValue(Kingdee.BOS.Resource.ResManager.LoadKDString("物料", "002460030014689", Kingdee.BOS.Resource.SubSystemType.BOS), this.Context.UserLocale.LCID));
            //header.AddChild("fcustid", new LocaleValue(Kingdee.BOS.Resource.ResManager.LoadKDString("客户", "002460030014692", Kingdee.BOS.Resource.SubSystemType.BOS), this.Context.UserLocale.LCID));
            //header.AddChild("FQty", new LocaleValue(Kingdee.BOS.Resource.ResManager.LoadKDString("数量", "002460030014695", Kingdee.BOS.Resource.SubSystemType.BOS), this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            //header.AddChild("fprice", new LocaleValue(Kingdee.BOS.Resource.ResManager.LoadKDString("单价", "002460030014698", Kingdee.BOS.Resource.SubSystemType.BOS), this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            //header.AddChild("famount", new LocaleValue(Kingdee.BOS.Resource.ResManager.LoadKDString("金额", "002460030014701", Kingdee.BOS.Resource.SubSystemType.BOS), this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header = this.GetHeaders(ds);
            return header;
        }

public ReportHeader GetHeaders(DataSet ds)
        {
            ReportHeader header = new ReportHeader();
            int count = ds.Tables[0].Columns.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    header.AddChild(ds.Tables[0].Columns[i].ToString(), new LocaleValue(Kingdee.BOS.Resource.ResManager.LoadKDString(ds.Tables[0].Columns[i].ToString(), "002460030014689", Kingdee.BOS.Resource.SubSystemType.BOS), this.Context.UserLocale.LCID));
                }
            }
            return header;
        }
    }

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章