这次系统用的报表是vs2010自带的rdlc报表,感觉还蛮实用的,不错。
在这里就说下,使用的过程,因为之前都是vs2008与2010还是有区别的。
1、简历rdlc文件
2、
画图
3、建立数据源---此数据源只是个占位符的意思,与前端页面并不对应
4、代码贴上
页面代码:
<div class="column">
<div class="columntitle">
材料入库报表</div>
<div class="columncontent">
<table cellspacing="0" cellpadding="0" id="tb_report" rules="all" align="center"
border="0" style="border-width: 0px; width: 100%; border-collapse: collapse;">
<tr>
<td>
<rsweb:reportviewer id="ReportViewer2" runat="server" font-names="Verdana" width="100%"
font-size="8pt" interactivedeviceinfos="(集合)" waitmessagefont-names="Verdana"
waitmessagefont-size="14pt" pagecountmode="Actual">
<LocalReport ReportPath="materialReport\Report1.rdlc">
</LocalReport>
</rsweb:reportviewer>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</td>
</tr>
</table>
</div>
</div>
后台代码:
ReportParameter p1 = new ReportParameter("ReportParameter1", str);
ReportParameter p2 = new ReportParameter("ReportParameter2", "材料入库");
ReportParameter p3 = new ReportParameter("ReportParameter3", "入库数量");
ReportParameter p4 = new ReportParameter("ReportParameter4", "入 库 人");
DataTable tb_r = MakeTable();
int sumCount = 0;
if (tb.Rows.Count > 0)
{
for (int i = 0; i < tb.Rows.Count; i++)
{
DataRow row = tb_r.NewRow();
string dd = tb.Rows.Count.ToString();
row["MaterialIDName"] = tb.Rows[i]["MaterialIDName"].ToString();
row["Type"] = tb.Rows[i]["JionCount"].ToString();
row["Offer"] = tb.Rows[i]["JionName"].ToString();
tb_r.Rows.Add(row);
sumCount += Convert.ToInt32(tb.Rows[i]["JionCount"].ToString());
if(i==tb.Rows.Count-1){
DataRow row1 = tb_r.NewRow();
row1["MaterialIDName"] = "总计";
row1["Type"] = sumCount.ToString();
row1["Offer"] = "----";
tb_r.Rows.Add(row1);
}
}
}
ReportViewer2.Style.Add("display", "");
this.ReportViewer2.LocalReport.DataSources.Clear();
this.ReportViewer2.LocalReport.SetParameters(p1);
this.ReportViewer2.LocalReport.SetParameters(p2);
this.ReportViewer2.LocalReport.SetParameters(p3);
this.ReportViewer2.LocalReport.SetParameters(p4);
this.ReportViewer2.LocalReport.DataSources.Add(new ReportDataSource("
DataSet1", tb_r));
//虚拟一个报表表格
private DataTable MakeTable()
{
DataTable tbl = new DataTable("report");
DataColumn Column1 = new DataColumn();//材料名称
Column1.ColumnName = "MaterialIDName";
Column1.DataType = System.Type.GetType("System.String");
Column1.AllowDBNull = true;
tbl.Columns.Add(Column1);
DataColumn Column2 = new DataColumn();//采购数量
Column2.ColumnName = "Type";
Column2.DataType = System.Type.GetType("System.String");
Column2.AllowDBNull = true;
tbl.Columns.Add(Column2);
DataColumn Column3 = new DataColumn();//采购人
Column3.ColumnName = "Offer";
Column3.DataType = System.Type.GetType("System.String");
Column3.AllowDBNull = true;
tbl.Columns.Add(Column3);
return tbl;
}