public override void OnPrepareDevPrintData(PreparePrintDevDataEventArgs e)
{
base.OnPrepareDevPrintData(e);
DataTable dt = e.DataSource.Tables["t_PUR_POOrderEntry"];
DataTable dtResult = dt.Clone();
DataTable dtName = dt.DefaultView.ToTable(true, "FMATERIALID");
for (int i = 0; i < dtName.Rows.Count; i++)
{
DataRow[] rows = dt.Select("FMATERIALID='" + dtName.Rows[i][0] + "'");
//temp用来存储筛选出来的数据
DataTable temp = dtResult.Clone();
foreach (DataRow row in rows)
{
temp.Rows.Add(row.ItemArray);
}
DataRow dr = dtResult.NewRow();
for (int j=0; j< dtResult.Columns.Count; j++)
{
dr[j] = rows[0][j];
}
dr["fqty"] = temp.Compute("sum(fqty)", "");
dtResult.Rows.Add(dr);
}
dt.Rows.Clear();
DataRow[] drs = dtResult.Select();
foreach (DataRow dr in drs)
{
dt.Rows.Add(dr.ItemArray);
}
}
推荐阅读