RDLC一些问题收集

xp下vs2010版的

1.发布时需要独立安装或Copy对应的程序集到客户端电脑
需要Copy的程序集,文件可以从c:\windows\assembly 通过dos命令复制过来。
Microsoft.ReportViewer.Common.dll                
Microsoft.ReportViewer.ProcessingObjectModel.dll
Microsoft.ReportViewer.WebForms.dll              
Microsoft.ReportViewer.WinForms.dll         
或者下载额外安装包:http://www.microsoft.com/en-us/download/details.aspx?id=6442

2.可以使用dataset, 或自定义的数据源如POCO,需要添加下数据源,在RDLC里面都是以Dataset节点显示
一个RDLC 可以定义多个数据源,添加额外数据原时,打开对应报表设计窗口,在菜单[视图]->报表数据(或者按Ctrl+alt+D)

3.固定表头问题

RDLC报表固定每页都显示表头
以XML方式打开rdlc文件
查找到
<TablixRowHierarchy>
          <TablixMembers>
            <TablixMember>
              <KeepWithGroup>After</KeepWithGroup>
              </TablixMember>
            <TablixMember>
              <Group Name="详细信息" />
            </TablixMember>
            <TablixMember>
              <KeepWithGroup>Before</KeepWithGroup>
            </TablixMember>
          </TablixMembers>
        </TablixRowHierarchy>

修改成
<TablixRowHierarchy>
          <TablixMembers>
            <TablixMember>
              <KeepWithGroup>After</KeepWithGroup>
              <RepeatOnNewPage>true</RepeatOnNewPage> 加上这句就可以了
              </TablixMember>
            <TablixMember>
              <Group Name="详细信息" />
            </TablixMember>
            <TablixMember>
              <KeepWithGroup>Before</KeepWithGroup>
            </TablixMember>
          </TablixMembers>
        </TablixRowHierarchy>

4.可以通过设置KeepTogether指定将列表不分页显示(打印视图还是要分页的)

5.相关代码

View Code
            var befMoney = 0.0m;

            if (string.IsNullOrWhiteSpace(txtCustomer.Text.Trim()))

            {

                throw new Exception("必需输入客户名称!");

            }



            //生成报表数据并绑定

            var list = new RepManager().Payable(dtpBTime.Value, dtpETime.Value.Date, txtCustomer.Text, out befMoney);

            bindingSource1.DataSource = list;

            var repDataSource = new Microsoft.Reporting.WinForms.ReportDataSource("dsRP", bindingSource1);

            reportViewer1.LocalReport.DataSources.Add(repDataSource);



            //设置报表模板

            this.reportViewer1.LocalReport.ReportEmbeddedResource = "FIStudio.WinUI.Report.RPDetail.rdlc";



            //参数设置

            var repParams = new ReportParameter[]{

                new ReportParameter("Title",string.Format("产品采购明细账--{0}",txtCustomer.Text)),

                new ReportParameter("BefMoneyTitle",string.Format("{0}前结余",dtpBTime.Text)),

                new ReportParameter("BefMoney",befMoney.ToString()),

                new ReportParameter("EndMoneyTitle",string.Format("{0}止结余",dtpETime.Text)),



                new ReportParameter("FieldA","付款"),

                new ReportParameter("FieldB","应付结余")

            };

            reportViewer1.LocalReport.SetParameters(repParams);

            //呈现

            this.reportViewer1.RefreshReport();

  6.数据源内容变更时可能有缓存 

reportViewer1.LocalReport.DataSources.Clear();调用下清空缓存

                var equipmentNo = TryParser(txtEquipmentNo.Text, "");

                var useCount = TryParser<int?>(txtUseCount.Text, 0) ;

                var service = new EquipmentServiceImpl();

                var response = service.queryBladeUseStatus(equipmentNo, useCount * 10000);



                DataTable dt = new dsBladeUseStatus.DataTable1DataTable();

                foreach (var it in response.Model)

                {

                    var row = (dsBladeUseStatus.DataTable1Row)dt.NewRow();

                    row.序号 = it.RecId;

                    row.刀片 = it.BladeNo;

                    row.设备号 = it.EquipmentNo;

                    row.维护人 = it.EditUser;

                    row["最后维护"] = GetV(it.EditTime);

                    row.使用次数 = it.UseCount.HasValue ? it.UseCount.Value.ToString() : "";

                    row.备注 = "";

                    dt.Rows.Add(row);

                }



                ReportViewer1.LocalReport.DataSources.Clear();

                var repDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("ds", dt);

                ReportViewer1.LocalReport.DataSources.Add(repDataSource);



                var path = System.Web.Hosting.HostingEnvironment.MapPath("/EM/UI/BladeUseStatusQuery.rdlc");

                //设置报表模板

                this.ReportViewer1.LocalReport.ReportPath = path;



                //参数设置

                var repParams = new ReportParameter[]{ 

                new ReportParameter("QueryTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),

                new ReportParameter("UseCount",">=" + useCount + "万次"),

                new ReportParameter("EquipmentNo",equipmentNo)

                 };

                ReportViewer1.LocalReport.SetParameters(repParams);

                this.ReportViewer1.LocalReport.DisplayName = "自动机刀片使用状态";



                //呈现

               // this.ReportViewer1.DataBind();



                ReportViewer1.LocalReport.Refresh();

            }

            catch (Exception ex)

            {

                Alert(ex.Message);

            }
View Code

WebForm中,如果不调用清空,则上面代码回导致每查询一次内参中则多一个数据集合(ds)
7.WebForm中使用强类型DataSet时,需要把DataSet放根目录下
------

8.WebForm中无法使用(vs2010--.net4.0 + xp) 自定义类为数据源,只能使用强类型的DataSet
不过绑定数据时,只要字段名称跟DataSet的Table列名对上即可,可以使用List<XXX>类型的数据绑定
另外可以建立一个类库项目,在类库项目里使用自定义类作为报表数据源,在设计完报表后需要把rdlc文件就copy到WebForm项目下

你可能感兴趣的:(问题)