Rdlc優點:

  1:Rdlc報表設計簡單

  2: " /> 乱色欧美videos黑人,黑丝一区,久久激情五月

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ASP.NET中動態控制RDLC報表

  在ASP.NET程序中,可以選擇使用水晶報表,功能確實強大。但是web版的水晶報表好像存在版權的問題。如果所作報表不是復雜的一塌糊涂的話,可以使用微軟自帶的Rdlc報表。

  Rdlc優點:

  1:Rdlc報表設計簡單

  2:結果存成xml,易于控制

  3:導出格式作的很不錯

  這里所說的動態控制報表所指的是:在一些時候,制作了報表之后希望在運行中可以動態的做一些小修改,比如說列的位置,用戶控制顯示那些列等等。

  控制方法,嘗試了這么幾種:

  1:控制微軟提供的報表對象的屬性;

  2:報表全部自動生成

  3:修改報表源文件,然后加載。

  控制微軟提供的報表對象的屬性:基于這個功能需求,一開始我想到的方法是通過控制微軟提供的這些報表對象的屬性來實現。因為這種方法最人道了。但是事與愿違,微軟的ReportViewer對象是用來顯示Report的,自然不行;我使用的report是自己設計的,localReport,找到Report對象,里面方法有這個幾個:report.GetDefaultPageSettings();report.GetDocumentMap()等,第一個是獲取打印紙張德設置,第二個是獲取doc文檔(但是始終出錯),都是只讀屬性;所以,第一種嘗試失敗。

  第二種方法就是報表全部自動生成??梢哉业揭粋€完整的例子,在這里:http://www.gotreportviewer.com/DynamicTable.zip
這個例子里面,他把xml結構的rdlc報表寫成一個類ReportDefinition,然后通過自定義這個類的內容來得到一個報表。其實際還是為了自己構造一個報表對象的xml。這是加載自定義報表的過程:win下的代碼 this.reportViewer1.Reset();

this.reportViewer1.LocalReport.LoadReportDefinition(m_rdl);
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("MyData", m_dataSet.Tables[0]));
this.reportViewer1.RefreshReport();這是自動生成xml的代碼:
private MemoryStream GenerateRdl(List<string> allFields, List<string> selectedFields)
{
 MemoryStream ms = new MemoryStream();
 RdlGenerator gen = new RdlGenerator();
 gen.AllFields = allFields;
 gen.SelectedFields = selectedFields;
 gen.WriteXml(ms);
 ms.Position = 0;
 return ms;
}

  這是完全ReportDefinition的一部分定義:

namespace Rdl {
 using System.Xml.Serialization;

 /**//// <remarks/>
 [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
 [System.SerializableAttribute()]
 [System.Diagnostics.DebuggerStepThroughAttribute()]
 [System.ComponentModel.DesignerCategoryAttribute("code")]
 [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
 [System.Xml.Serialization.XmlRootAttribute(Namespace=_
  "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition", IsNullable=false)]
 public partial class Report {
  private object[] itemsField;

  但是幾經考慮之后,這個方案也不讓人滿意,原因是:所有的報表對象都得自己生成,一下子回到了解放前,沒有可視化工具的設計既繁瑣又復雜。特別是如果設計幾個line,然后再來上幾個分組的話,工作量巨大。

  于是乎嘗試第三種方法:ReportVivwer加載報表前在內存中修改報表源文件。這個方法比較狠,其實可以解決很多問題,包括設計自定義的打印紙張等(這里有另外一種設置打印紙張的方法http://waxdoll.cnblogs.com/archive/2006/03/03/342435.html)。

  設計思路是:首先加載rdlc文件到一個XmlDocument對象;然后修改xml內容;把xml序列化成字節流,交給ReportViewer顯示。

  這是這一段代碼:

public MemoryStream GenerateRdlc()
{
 XmlDocument sourceDoc = new XmlDocument();
 string path = AppDomain.CurrentDomain.BaseDirectory + "Test/OrderList.rdlc";
 sourceDoc.Load(path);
 Hashtable reportColumns = GetReportColumns(sourceDoc.LastChild);
 //just remove
 for (int i = 0; i < reportColumns.Count; i++)
 {
  if (!FindReportCoulmns(reportColumns[i].ToString()))
  {
   RemoveColumnFromRdlc(sourceDoc.LastChild, i);
  }
 }

 MemoryStream ms = new MemoryStream();
 XmlSerializer serializer = new XmlSerializer(typeof(XmlDocument));
 serializer.Serialize(ms, sourceDoc);
 ms.Position = 0;
 return ms;
}
  至于如何GetReportColumns和RemoveColumnFromRdlc,那就很簡單了,就是一個操作xml對象的過程。比方說:

private Hashtable GetReportColumns(XmlNode root)
{
 Hashtable cols = new Hashtable();
 //XmlNamespaceManager s=new XmlNamespaceManager(
  XmlNode cells = FindChildNode(root,"Body/ReportItems/Table/Header/TableRows/TableRow/TableCells");
 for (int i = 0; i < cells.ChildNodes.Count; i++)
 {
  XmlNode cell =FindChildNode( cells.ChildNodes[i],"ReportItems/Textbox/DataElementName");
  cols[i] = cell.InnerText;
 }
 return cols;
}
  這是使用這一段的代碼:

this.ReportViewer1.LocalReport.LoadReportDefinition(this.Report.GenerateRdlc());
this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", result.Tables[0]));
this.ReportViewer1.LocalReport.Refresh();
  這個方法終于成功了。

  附:rdlc文件的xml一段結構

  xml結構

1<?xml version="1.0" encoding="utf-8"?>
2<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
3 <DataSources>
4 <DataSource Name="ConnectionString">
5 <ConnectionProperties>
6 <ConnectString />
7 <DataProvider>SQL</DataProvider>
8 </ConnectionProperties>
9 <rd:DataSourceID>073016a7-6cb0-4e06-a6fd-f5882a039188</rd:DataSourceID>
10 </DataSource>
11 </DataSources>
12 <BottomMargin>2.5cm</BottomMargin>
13 <RightMargin>2.5cm</RightMargin>
14 <PageWidth>21cm</PageWidth>
15 <rd:DrawGrid>true</rd:DrawGrid>
16 <InteractiveWidth>21cm</InteractiveWidth>
17 <rd:GridSpacing>0.25cm</rd:GridSpacing>
18 <rd:SnapToGrid>true</rd:SnapToGrid>
19 <Body>
20 <ColumnSpacing>1cm</ColumnSpacing>
21 <ReportItems>
22 <Chart Name="chart1">

AspNet技術ASP.NET中動態控制RDLC報表,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 日本在线加勒比 | 成人免费黄色网址 | 一本色道久久综合亚洲精品高清 | 欧美xxxwww| 国产精品video | 色四月婷婷 | 久久93精品国产91久久综合 | 午夜视频网址 | 午夜视频在线免费观看 | 五月天天 | 午夜毛片网站 | 综合亚洲一区二区三区 | 久久久久久久国产精品 | 中文字幕日本精品一区二区三区 | 经典欧美gifxxoo动态图午夜 | 91大神在线精品网址 | 国产高清一区二区三区四区 | 成人精品国产亚洲 | www激情| 婷婷色九月 | 草草草视频在线观看 | 看全大色黄大色黄大片一级爽 | 亚洲香蕉网久久综合影院3p | 91福利在线看 | 都市激情综合网 | 激情视频图片小说qvdo | 午夜影院在线免费观看 | 一二三四视频社区在线播放中国 | 一级做a爰片性色毛片黄书 一级做a爰片性色毛片男 | 久久久久久久久女黄9999 | 中国一级特黄真人毛片免费看 | 国内精品伊人久久久久7777人 | 91精品国产高清久久久久久 | 久久精品视频99精品视频150 | 国产区视频在线观看 | 日本美女视频韩国视频网站免费 | 玖玖爱视频在线 | 一区高清 | 奇米一区二区 | 久久夜色精品国产飘飘 | 韩国精品一区视频在线播放 |