现在有个报表是要显示物资目录明细
要按物资品种(即分类的意思)来显示对应的物资。
01001010
010010100001
01002010
010020100001
010020100002
010020100003
010020100004
……
RPTWZMLMXBBMaster:物资目录明细报表分组主表窗口
界面上Detail中放置主表显示内容的表格,再插入一个Subreport,在属性面板将其ReportSource属性设为子表的类名称,将产生一个实例名:rptwzmlmxb1
/// <summary>
/// 打印前加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RPTWZMLMXBBMaster_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
string strSQL = "select * from wzpz where length(cwzpzbh)=8 order by cwzpzbh";
DB2Command db2Cmd = new DB2Command(strSQL, new DB2Connection(pModel.ConnectionString));
DB2DataAdapter db2Da = new DB2DataAdapter();
db2Da.SelectCommand = db2Cmd;
DataSet ds = new DataSet();
db2Da.Fill(ds);
this.DataMember = TABLE_WZPZ.NAME;
this.DataSource = ds;
this.xrTableCell8.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZPZ.COLUMN_CWZPZBH) });
this.xrTableCell4.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZPZ.COLUMN_CWZPZMC) });
xrLabel3.Text = DateTime.Now.ToString();
}
/// <summary>
/// Detail加载事件,加载一行,向子表传递一次参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
RPTWZMLMXB subRPT = subreport1.ReportSource as RPTWZMLMXB;
subRPT.GetParameters(Convert.ToInt32(GetCurrentColumnValue(TABLE_WZPZ.COLUMN_IID)));//字段名区分大小写
}
RPTWZMLMXB:物资目录明细表(子表)窗口
子表界面只保留Detail,放置显示内容的表格
/// <summary>
/// 接收主分组表参数,绑定数据
/// </summary>
/// <param name="IWZPZID"></param>
public void GetParameters(int IWZPZID)
{
string strSQL = "select * from wz where ispbz=2 and iwzpzid=" + IWZPZID;
DB2Command db2Cmd = new DB2Command(strSQL, new DB2Connection(pModel.ConnectionString));
DB2DataAdapter db2Da = new DB2DataAdapter();
db2Da.SelectCommand = db2Cmd;
DataSet ds = new DataSet();
db2Da.Fill(ds);
this.DataMember = TABLE_WZ.NAME;
this.DataSource = ds;
this.xrTableCell2.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZ.COLUMN_CWZBH) });
this.xrTableCell7.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZ.COLUMN_CWZMC) });
this.xrTableCell8.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZ.COLUMN_CXHGG) });
this.xrTableCell9.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZ.COLUMN_CTH) });
this.xrTableCell10.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZ.COLUMN_CCZ) });
this.xrTableCell12.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", ds, TABLE_WZ.COLUMN_CJLDW) });
}