visual studio 2010 自带reporting报表本地加载的使用

时间:2023-03-09 02:27:27
visual studio 2010 自带reporting报表本地加载的使用

原文:visual studio 2010 自带reporting报表本地加载的使用

在这家公司时间不长,接触都是之前没玩过的东东,先是工作流引擎和各种邮件短信的审核信息,后又是部署reporting服务器。

reporting服务部署就不在这多说,在vs2010里面是自带了reporting报表的直接添加就可以使用。如图

visual studio 2010 自带reporting报表本地加载的使用

这是一个空白的模板。这时模板已有了就差数据了在新加一个数据集DataSet

visual studio 2010 自带reporting报表本地加载的使用

数据集有了模板有了就回到reporting模板页在这上面设计格式了,在空白处 右键-插入-表(也可以是其他图表之类)选择数据源

visual studio 2010 自带reporting报表本地加载的使用

此时的报表模板就和绑定web控件一样设定对于字段

visual studio 2010 自带reporting报表本地加载的使用

到这模板设定就完成了。接着去写对应的加载页面了aspx的html如下

<rsweb:ReportViewer ID="rvReport" runat="server" Font-Names="Verdana"
Font-Size="8pt" WaitMessageFont-Size="14pt" InteractiveDeviceInfos="(集合)" WaitMessageFont-Names="Verdana"
Width="100%" Height="90%">
<LocalReport ReportPath="ReportFiles\RepairCountReport.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1"/>
</DataSources>
</LocalReport> </rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server">
</asp:ObjectDataSource>

在cs文件加载数据代码如下

 private void InitDataGrid()
{
string betweenBegin = BetweenBegin.Value;
string betweenEnd = BetweenEnd.Value;
if (string.IsNullOrWhiteSpace(betweenBegin) || string.IsNullOrWhiteSpace(betweenEnd))
{
PromptHelper.ShowMessageJbox("温馨提示", "请输入查询区间", this);
return;
}
//默认是选中即油站名称进行分组
string groupbyValue = "";
if (ckOuName.Checked)
{
groupbyValue = "1";
}
else
{
groupbyValue = RadioButtonList1.SelectedValue;
}
sqlWhere = " and (T1.ActualFinishDate BETWEEN '" + betweenBegin + "' AND '" + betweenEnd + "') ";
string ouName=OUName.Value;
if (!string.IsNullOrWhiteSpace(ouName) && ouName != "油站名称")
{
sqlWhere += " and T3.OUName like '%" + ouName + "%'";
}
//先获取数据
SqlHelper helper = new SqlHelper();
SqlParameter[] par = new SqlParameter[]{
new SqlParameter("@sqlWhere",SqlDbType.VarChar,1000),
new SqlParameter("@groupby",SqlDbType.VarChar,2)
};
par[0].Value = sqlWhere;
par[1].Value = groupbyValue;
DataSet DataSet1 = helper.ExecuteDataSet(CommandType.StoredProcedure, "proc_RepairCountReport", par);
this.rvReport.Visible = true; this.rvReport.LocalReport.DataSources.Clear(); ObjectDataSource1.SelectParameters.Clear();
ObjectDataSource1.SelectParameters.Add("sqlWhere", sqlWhere);
this.rvReport.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", DataSet1.Tables[0]));
this.rvReport.LocalReport.Refresh(); }

  到这就算整个报表都已经做完了看看效果吧

visual studio 2010 自带reporting报表本地加载的使用