透视表简单示例教程
本文将示例一个透视表从新建到编写插件,演示一个简单的过滤过程。本示例适用于SQL Server账套。
首先打开BOS IDE,点击新建,新建一个透视表,如下图所示:
点击确定后,需要修改一下默认透视表样式。在左侧工具栏的拖一个分割容器,再放一个日期作为查询条件。修改后的透视表如下:
新建一个过滤页面,新建过程选择“继承”,依次选择节点BOS-应用框架-动态表单,选择到公共过滤,示例如下:
确定后,生成一个过滤页面,在快捷页签下拖放一个日期控件作为查询条件,设置完成后如下:
将透视表的“过滤窗口业务对象(报表)”设置为你的过滤页面的标识,本示例中填写PAEZ_PivotFilterDemo;
接下来我们需要编写透视表数据源插件并注册,打开visual studio,编写透视表插件。同简单账表类似,新建类,继承自SysReportBaseService类,与简单账表不同的是,透视表需要对行、列以及数据进行设置。
this.SettingInfo.RowTitleFields.Add(settingBillNo);
this.SettingInfo.SelectedFields.Add(settingBillNo);
this.SettingInfo.ColTitleFields.Add(settingMaterial);
this.SettingInfo.SelectedFields.Add(settingMaterial);
this.SettingInfo.AggregateFields.Add(settingAmount);
this.SettingInfo.SelectedFields.Add(settingAmount);
具体插件代码如下:
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts.Report;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Metadata.GroupElement;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Core.Report.PivotReport;
using Kingdee.BOS.Orm.DataEntity;
using System;
using System.ComponentModel;
using System.Data;
namespace GalaxyPlugin.Pivot
{
[Description("透视表插件")]
public class CrossReportPlugin : SysReportBaseService
{
public override void Initialize()
{
this.ReportProperty.IsGroupSummary = true;
this.ReportProperty.BillKeyFieldName = "FIDENTITYID";
this.ReportProperty.ReportName = new Kingdee.BOS.LocaleValue("透视表插件演示");
base.Initialize();
}
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();
}
//设置报表title
result.AddTitle("F_PAEZ_Date", Convert.ToString(dyFilter["F_PAEZ_Date"]));
}
return result;
}
public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
{
string strCreateTable = string.Format(@"
/*dialect*/SELECT TM.FID,TM.FBILLNO,TM.FCREATORID,TM.FCREATEDATE,TF.FALLAMOUNT,ml.FNAME as FMaterialName,TE.FENTRYID as FIDENTITYID INTO {0}
FROM T_PUR_POORDER TM
INNER JOIN T_PUR_POORDERENTRY_F TF ON TM.FID = TF.FID
INNER JOIN T_PUR_POORDERENTRY TE ON TM.FID = TE.FID
inner join T_BD_MATERIAL m on te.FMATERIALID = m.FMATERIALID
inner join T_BD_MATERIAL_L ml on m.FMATERIALID = ml.FMATERIALID
WHERE 1=1 ", tableName);
var custFilter = filter.FilterParameter.CustomFilter;
if (custFilter != null && custFilter.DynamicObjectType.Properties.Contains("F_PAEZ_Date"))
{
var date = custFilter["F_PAEZ_Date"].ToString();
if (!string.IsNullOrEmpty(date))
{
string strDate = DateTime.Parse(date).ToString("yyyy-MM-dd");
strCreateTable += string.Format(" AND TM.FCREATEDATE >= '{0}'", strDate);
}
}
//base.AfterCreateTempTable(tablename);
DBUtils.ExecuteDynamicObject(this.Context, strCreateTable);
DataTable reportSouce = DBUtils.ExecuteDataSet(this.Context, string.Format("SELECT * FROM {0}", tableName)).Tables[0];
this.SettingInfo = new PivotReportSettingInfo();
TextField field;
DecimalField fieldData;
//构造透视表列
//FID
field = new TextField();
field.Key = "FBILLNO";
field.FieldName = "FBILLNO";
field.Name = new LocaleValue("单据编号");
SettingField settingBillNo = PivotReportSettingInfo.CreateColumnSettingField(field, 0);
this.SettingInfo.RowTitleFields.Add(settingBillNo);
this.SettingInfo.SelectedFields.Add(settingBillNo);
//field = new TextField();
//field.Key = "FCREATORID";
//field.FieldName = "FCREATORID";
//field.Name = new LocaleValue("创建者");
//SettingField settingCreateId = PivotReportSettingInfo.CreateColumnSettingField(field, 0);
//this.SettingInfo.RowTitleFields.Add(settingCreateId);
//this.SettingInfo.SelectedFields.Add(settingCreateId);
//构造行
field = new TextField();
field.Key = "FMaterialName";
field.FieldName = "FMaterialName";
field.Name = new LocaleValue("物料名称");
SettingField settingMaterial = PivotReportSettingInfo.CreateColumnSettingField(field, 0);
this.SettingInfo.ColTitleFields.Add(settingMaterial);
this.SettingInfo.SelectedFields.Add(settingMaterial);
//构造数据
fieldData = new DecimalField();
fieldData.Key = "FALLAMOUNT";
fieldData.FieldName = "FALLAMOUNT";
fieldData.Name = new LocaleValue("金额");
SettingField settingAmount = PivotReportSettingInfo.CreateDataSettingField(fieldData, 0, GroupSumType.Sum, "N3"); //N3表示3位小数
this.SettingInfo.AggregateFields.Add(settingAmount);
this.SettingInfo.SelectedFields.Add(settingAmount);
}
}
}
编写好插件后,编译成dll,放到website\bin目录下,通过报表数据源插件注册到此插件,然后保存。重启站点(通过重启IIS)。在BOS IDE中发布此报表,然后打开预览,效果如下:
透视表简单示例教程
本文2024-09-23 04:16:15发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164229.html