【学习】创建简单账表原创
13人赞赏了该文章
302次浏览
编辑于2024年08月20日 11:29:02
创建简单账表模板
添加显示字段
创建报表过滤页
添加过滤字段
简单账表关联过滤页
页面展示
代码分享
using Kingdee.BOS; using Kingdee.BOS.Contracts.Report; using Kingdee.BOS.Core.Report; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; namespace XueXi { [Description("学习简单报表开发"), HotUpdate] public class Class5 : SysReportBaseService { public override void Initialize() { base.Initialize(); //新增自定义报表 不需要由插件生成临时表 this.IsCreateTempTableByPlugin = false; //继承的报表可以不添加 } public override ReportTitles GetReportTitles(IRptParams filter) { //将报表过滤页面中的值放入报表头部显示 ReportTitles reportTitles = new ReportTitles(); DynamicObject customFilter = filter.FilterParameter.CustomFilter; if (customFilter != null) { //获取报表过滤页面的值 标识为过滤页面中字段标识 //三目运算 如果取值为空在进行转换时会报错 string FBILLNO = customFilter["F_VVHD_Text"] == null ? string.Empty : customFilter["F_VVHD_Text"].ToString(); string FSupplierId= customFilter["F_VVHD_MulCombo"] == null ? string.Empty : customFilter["F_VVHD_MulCombo"].ToString(); //日期时间如果给一个默认值则不需要判断 string FDATE = customFilter["F_VVHD_Date"].ToString(); string FDATE1 = customFilter["F_VVHD_Date1"].ToString(); //这里是报表页面的标识 reportTitles.AddTitle("F_VVHD_Text", FBILLNO); reportTitles.AddTitle("F_VVHD_Text1", FSupplierId); reportTitles.AddTitle("F_VVHD_Date", FDATE); reportTitles.AddTitle("F_VVHD_Date1", FDATE1); } return reportTitles; } public override ReportHeader GetReportHeaders(IRptParams filter) { //报表的列 //AddChild("SQL字段名称", new LocaleValue("显示的名称", this.Context.UserLocale.LCID), SqlStorageType.字段的类型); ReportHeader header = new ReportHeader(); header.AddChild("FBILLNO", new LocaleValue("单据编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar); header.AddChild("FDate", new LocaleValue("单据日期", this.Context.UserLocale.LCID), SqlStorageType.SqlDatetime); header.AddChild("FSUPPLIERID", new LocaleValue("供应商", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar); return header; } //下面为SQL拼接 protected override string BuilderSelectFieldSQL(IRptParams filter) { //拼接查询 #region.当前SQL //*dialect*/select * into 临时表名 #endregion string sqlstr = "/*dialect*/select *"; return sqlstr; } protected override string BuilderTempTableOrderBySQL(IRptParams filter) { //拼接排序 #region.当前SQL //*dialect*/select * , ROW_NUMBER() OVER(ORDER BY FDate desc) 字段名[FIDENTITYID] into 临时表名 #endregion string OrderBy = ""; //排序 string datasort = Convert.ToString(filter.FilterParameter.SortString); if (datasort != "") { OrderBy = datasort; } else { OrderBy = "FDate desc"; } return OrderBy; } protected override string BuilderFromWhereSQL(IRptParams filter) { //拼接条件 #region.当前SQL //*dialect*/select * , ROW_NUMBER() OVER(ORDER BY FDate desc) 字段名[FIDENTITYID] into 临时表名 //from(select FBILLNO, FDATE from T_PUR_POORDER) A where 1 = 1 //如果在条件页签中增加过滤 拼接在此处 //AND FBILLNO like '%%' //AND FDATE >= '当前时间' //AND FDATE <= '当前时间' #endregion string Filter = filter.FilterParameter.FilterString; DynamicObject customFilter = filter.FilterParameter.CustomFilter; StringBuilder strwhere = new StringBuilder(); strwhere.AppendLine("from (select FBILLNO,FDATE,FSUPPLIERID from T_PUR_POORDER) A where 1 = 1"); if (Filter.Trim() != "")//条件页签过滤不为空 则拼接 { strwhere.AppendLine(string.Format("AND {0}", Filter)); } string FBILLNO = customFilter["F_VVHD_Text"] == null ? string.Empty : customFilter["F_VVHD_Text"].ToString(); string FSupplierId= customFilter["F_VVHD_MulCombo"] == null ? string.Empty : customFilter["F_VVHD_MulCombo"].ToString(); string FDATE = customFilter["F_VVHD_Date"].ToString(); string FDATE1 = customFilter["F_VVHD_Date1"].ToString(); strwhere.AppendLine(string.Format("AND FBILLNO like '%{0}%'", FBILLNO)); if (!(FSupplierId is null || FSupplierId == "")) { strwhere.AppendLine(string.Format("AND FSUPPLIERID in ({0})", FSupplierId)); } strwhere.AppendLine(string.Format("AND FDATE >= '{0}'", FDATE)); strwhere.AppendLine(string.Format("AND FDATE <= '{0}'", FDATE1)); return strwhere.ToString(); } public override List<SummaryField> GetSummaryColumnInfo(IRptParams filter) { //在查询结果表中的最底部显示汇总信息 var result = base.GetSummaryColumnInfo(filter); result.Add(new SummaryField("FBILLNO", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.COUNT)); return result; } } }
最后需要将生成的dll文件在报表的 服务器插件 中引用
赞 13
13人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!