Rdlc優點:

  1:Rdlc報表設計簡單

  2: " /> 四虎国产精品免费观看视频,久久国内精品视频,97免费视频观看

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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報表,轉載需保留來源!

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

主站蜘蛛池模板: 67194成在线观看免费 | 欧美18精品久久久无码午夜福利 | 中文字幕无码亚洲字幕成A人蜜桃 | 少女亚洲free| 伊人不卡久久大香线蕉综合影院 | 免费看欧美一级特黄a大片 免费看欧美xxx片 | 亚洲一卡二卡三卡四卡无卡麻豆 | 久久久久久久久女黄 | 国产亚洲人成在线视频 | 恋夜影视列表免费安卓手机版 | 饥渴的40岁熟妇完整版在线 | 日韩精品 电影一区 亚洲高清 | 国产精品igao视频网网址 | 9966在线观看免费高清电影 | 第一次玩老妇真实经历 | 日本2021免费一二三四区 | 丰满少妇69激懒啪啪无码 | 国产精品点击进入在线影院高清 | 无码人妻少妇色欲AV一区二区 | 大香伊人久久 | 天堂so导航| 最新2017年韩国伦理片在线 | 亚洲成人免费在线观看 | 一本久道久久综合婷婷五月 | 花蝴蝶hd免费 | 日韩做A爰片久久毛片A片毛茸茸 | 皮皮在线精品亚洲 | 中文字幕在线不卡日本v二区 | 国产精品久久久久久亚洲毛片 | 亚洲福利区 | 99免费在线观看 | 国产免费人视频在线观看免费 | 性xxxx18公交车| 99久久精品费精品国产一区二 | 国产在线观看黄 | 收集最新中文国产中文字幕 | 秋霞网韩国理伦片免费看 | 精品日韩欧美一区二区三区 | 胖老太与人牲交BBWBBW高潮 | 欧美特级午夜一区二区三区 | 男人J桶女人P视频无遮挡网站 |