Reporting Service
生活随笔
收集整理的這篇文章主要介紹了
Reporting Service
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
研究了一下reportServices,還沒有完全得其精髓,東拼西湊一個小例子如下:(實現搜索報表,保存報表,以及現實在form上),希望對初學者有些幫助。
***********************************************
using?System;
using?System.Drawing;
using?System.Collections;
using?System.ComponentModel;
using?System.Windows.Forms;
using?System.Data;
using?System.IO;
using?System.Web.Services.Protocols;
using?System.Diagnostics;
namespace?myApplication1
{
????/**////?<summary>
????///?Summary?description?for?Form1.
????///?</summary>
????public?class?Form1?:?System.Windows.Forms.Form
????{
????????private?myApplication1.ReportService.ReportingService?myReportService?=new?myApplication1.ReportService.ReportingService();
????????private?static?myApplication1.ReportService.CatalogItem[]?items?=?null;
????????private?System.Windows.Forms.ComboBox?comboBox1;
????????private?AxSHDocVw.AxWebBrowser?axWebBrowser1;
????????/**////?<summary>
????????///?Required?designer?variable.
????????///?</summary>
????????private?System.ComponentModel.Container?components?=?null;
????????public?Form1()
????????{
????????????//
????????????//?Required?for?Windows?Form?Designer?support
????????????//
????????????InitializeComponent();
????
????????????//
????????????//?TODO:?Add?any?constructor?code?after?InitializeComponent?call
????????????//
????????????//?ReportService?URL=http://localhost/ReportServer/ReportService.asmx?wsdl"%20filename="ReportService.wsdl
????????????//
????????????myApplication1.ReportService.ReportingService?rs?=?new?myApplication1.ReportService.ReportingService();
????????????rs.Credentials?=?System.Net.CredentialCache.DefaultCredentials;
????????????????????????
????????????myApplication1.ReportService.SearchCondition?condition?=?new?myApplication1.ReportService.SearchCondition();
????????????condition.Condition?=?myApplication1.ReportService.ConditionEnum.Contains;
????????????condition.ConditionSpecified?=?true;
????????????condition.Name?=?"Name";
????????????condition.Value?=?"Report_A1";
????????????myApplication1.ReportService.SearchCondition[]?conditions?=?new?myApplication1.ReportService.SearchCondition[1];
????????????conditions[0]?=?condition;
????????????try
????????????{
????????????????items?=?rs.FindItems(?"/",?myApplication1.ReportService.BooleanOperatorEnum.Or,?conditions?);
????????????????if?(?items?!=?null?)
????????????????{
????????????????????foreach?(?myApplication1.ReportService.CatalogItem?ci?in?items)
????????????????????{
????????????????????????Console.WriteLine(?"Item?{0}?found?at?{1}",?ci.Name,?ci.Path?);
????????????????????????comboBox1.Items.Add(ci.Name);
????????????????????}
????????????????}
????????????}
????????????catch?(?SoapException?e?)
????????????{
????????????????Console.WriteLine(?e.Detail.InnerXml.ToString()?);?
????????????}
????????}
????????/**////?<summary>
????????///?Clean?up?any?resources?being?used.
????????///?</summary>
????????protected?override?void?Dispose(?bool?disposing?)
????????{
????????????if(?disposing?)
????????????{
????????????????if?(components?!=?null)?
????????????????{
????????????????????components.Dispose();
????????????????}
????????????}
????????????base.Dispose(?disposing?);
????????}
????????Windows?Form?Designer?generated?code#region?Windows?Form?Designer?generated?code
????????/**////?<summary>
????????///?Required?method?for?Designer?support?-?do?not?modify
????????///?the?contents?of?this?method?with?the?code?editor.
????????///?</summary>
????????private?void?InitializeComponent()
????????{
????????????System.Resources.ResourceManager?resources?=?new?System.Resources.ResourceManager(typeof(Form1));
????????????this.comboBox1?=?new?System.Windows.Forms.ComboBox();
????????????this.axWebBrowser1?=?new?AxSHDocVw.AxWebBrowser();
????????????((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
????????????this.SuspendLayout();
????????????//?
????????????//?comboBox1
????????????//?
????????????this.comboBox1.Location?=?new?System.Drawing.Point(24,?32);
????????????this.comboBox1.Name?=?"comboBox1";
????????????this.comboBox1.Size?=?new?System.Drawing.Size(200,?21);
????????????this.comboBox1.TabIndex?=?1;
????????????this.comboBox1.SelectedIndexChanged?+=?new?System.EventHandler(this.comboBox1_SelectedIndexChanged);
????????????//?
????????????//?axWebBrowser1
????????????//?
????????????this.axWebBrowser1.Anchor?=?((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top?|?System.Windows.Forms.AnchorStyles.Bottom)?
????????????????|?System.Windows.Forms.AnchorStyles.Left)?
????????????????|?System.Windows.Forms.AnchorStyles.Right)));
????????????this.axWebBrowser1.Enabled?=?true;
????????????this.axWebBrowser1.Location?=?new?System.Drawing.Point(32,?96);
????????????this.axWebBrowser1.OcxState?=?((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState"));
????????????this.axWebBrowser1.Size?=?new?System.Drawing.Size(576,?232);
????????????this.axWebBrowser1.TabIndex?=?2;
????????????//?
????????????//?Form1
????????????//?
????????????this.AutoScaleBaseSize?=?new?System.Drawing.Size(5,?13);
????????????this.ClientSize?=?new?System.Drawing.Size(648,?397);
????????????this.Controls.Add(this.axWebBrowser1);
????????????this.Controls.Add(this.comboBox1);
????????????this.Name?=?"Form1";
????????????this.Text?=?"Form1";
????????????((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
????????????this.ResumeLayout(false);
????????}
????????#endregion
????????/**////?<summary>
????????///?The?main?entry?point?for?the?application.
????????///?</summary>
????????[STAThread]
????????static?void?Main()?
????????{
????????????Application.Run(new?Form1());
????????}
????????private?void?comboBox1_SelectedIndexChanged(object?sender,?System.EventArgs?e)
????????{????????????
????????????myApplication1.ReportService.ReportingService?rs?=?new?myApplication1.ReportService.ReportingService();
????????????rs.Credentials?=?System.Net.CredentialCache.DefaultCredentials;
????????????//?Render?arguments
????????????byte[]?result?=?null;
????????????string?reportPath?=?items[comboBox1.SelectedIndex].Path;?
????????????string?format?=?"HTML4.0";
????????????string?historyID?=?null;
????????????string?devInfo?=?@"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
????????????//?Prepare?report?parameter.
????????????myApplication1.ReportService.ParameterValue[]?parameters?=?null;
????????????myApplication1.ReportService.DataSourceCredentials[]?credentials?=?null;
????????????string?showHideToggle?=?null;
????????????string?encoding;
????????????string?mimeType;
????????????myApplication1.ReportService.Warning[]?warnings?=?null;
????????????myApplication1.ReportService.ParameterValue[]?reportHistoryParameters?=?null;
????????????string[]?streamIDs?=?null;
????????????myApplication1.ReportService.SessionHeader?sh?=
????????????????new?myApplication1.ReportService.SessionHeader();
????????????rs.SessionHeaderValue?=?sh;
????????????try{
????????????????result?=?rs.Render(reportPath,?format,?historyID,?devInfo,?parameters,?credentials,?
????????????????????showHideToggle,?out?encoding,?out?mimeType,?out?reportHistoryParameters,?out?warnings,
????????????????????out?streamIDs);
????????????????sh.SessionId?=?rs.SessionHeaderValue.SessionId;
????????????????Console.WriteLine("SessionID?after?call?to?Render:?{0}",?
????????????????????rs.SessionHeaderValue.SessionId);
????????????????Console.WriteLine("Execution?date?and?time:?{0}",
????????????????????rs.SessionHeaderValue.ExecutionDateTime);
????????????????Console.WriteLine("Is?new?execution:?{0}",
????????????????????rs.SessionHeaderValue.IsNewExecution);
????????????}
????????????catch(SoapException?err?)
????????????{
????????????????Console.WriteLine(err.Detail.OuterXml);
????????????}
????????????//?Write?the?contents?of?the?report?to?an?HTML?file.
????????????try
????????????{
????????????????FileStream?stream?=?File.Create(?"report.htm",?result.Length?);????????
????????????????Console.WriteLine(?"File?created."?);
????????????????stream.Write(?result,?0,?result.Length?);
????????????????Console.WriteLine(?"Result?written?to?the?file."?);
????????????????stream.Close();
????????????????//axPdf1.src?=?"report.pdf";
????????????????int?zero=0;
????????????????object?oZero=?zero;
????????????????string?str?=?"";
????????????????object?oStr?=?str;
????????????????axWebBrowser1.Navigate("http://localhost/ReportServer?%2freport+sample%2fReport_A1&rs:Command=Render",
ref?oZero,
ref?oStr,
????????????????????????ref?oStr,
????????????????????????ref?oStr);
????????????}
????????????catch?(?Exception?err?)
????????????{
????????????????Console.WriteLine(?err.Message?);
????????????}
????????}
????}
}
***********************************************
using?System;
using?System.Drawing;
using?System.Collections;
using?System.ComponentModel;
using?System.Windows.Forms;
using?System.Data;
using?System.IO;
using?System.Web.Services.Protocols;
using?System.Diagnostics;
namespace?myApplication1
{
????/**////?<summary>
????///?Summary?description?for?Form1.
????///?</summary>
????public?class?Form1?:?System.Windows.Forms.Form
????{
????????private?myApplication1.ReportService.ReportingService?myReportService?=new?myApplication1.ReportService.ReportingService();
????????private?static?myApplication1.ReportService.CatalogItem[]?items?=?null;
????????private?System.Windows.Forms.ComboBox?comboBox1;
????????private?AxSHDocVw.AxWebBrowser?axWebBrowser1;
????????/**////?<summary>
????????///?Required?designer?variable.
????????///?</summary>
????????private?System.ComponentModel.Container?components?=?null;
????????public?Form1()
????????{
????????????//
????????????//?Required?for?Windows?Form?Designer?support
????????????//
????????????InitializeComponent();
????
????????????//
????????????//?TODO:?Add?any?constructor?code?after?InitializeComponent?call
????????????//
????????????//?ReportService?URL=http://localhost/ReportServer/ReportService.asmx?wsdl"%20filename="ReportService.wsdl
????????????//
????????????myApplication1.ReportService.ReportingService?rs?=?new?myApplication1.ReportService.ReportingService();
????????????rs.Credentials?=?System.Net.CredentialCache.DefaultCredentials;
????????????????????????
????????????myApplication1.ReportService.SearchCondition?condition?=?new?myApplication1.ReportService.SearchCondition();
????????????condition.Condition?=?myApplication1.ReportService.ConditionEnum.Contains;
????????????condition.ConditionSpecified?=?true;
????????????condition.Name?=?"Name";
????????????condition.Value?=?"Report_A1";
????????????myApplication1.ReportService.SearchCondition[]?conditions?=?new?myApplication1.ReportService.SearchCondition[1];
????????????conditions[0]?=?condition;
????????????try
????????????{
????????????????items?=?rs.FindItems(?"/",?myApplication1.ReportService.BooleanOperatorEnum.Or,?conditions?);
????????????????if?(?items?!=?null?)
????????????????{
????????????????????foreach?(?myApplication1.ReportService.CatalogItem?ci?in?items)
????????????????????{
????????????????????????Console.WriteLine(?"Item?{0}?found?at?{1}",?ci.Name,?ci.Path?);
????????????????????????comboBox1.Items.Add(ci.Name);
????????????????????}
????????????????}
????????????}
????????????catch?(?SoapException?e?)
????????????{
????????????????Console.WriteLine(?e.Detail.InnerXml.ToString()?);?
????????????}
????????}
????????/**////?<summary>
????????///?Clean?up?any?resources?being?used.
????????///?</summary>
????????protected?override?void?Dispose(?bool?disposing?)
????????{
????????????if(?disposing?)
????????????{
????????????????if?(components?!=?null)?
????????????????{
????????????????????components.Dispose();
????????????????}
????????????}
????????????base.Dispose(?disposing?);
????????}
????????Windows?Form?Designer?generated?code#region?Windows?Form?Designer?generated?code
????????/**////?<summary>
????????///?Required?method?for?Designer?support?-?do?not?modify
????????///?the?contents?of?this?method?with?the?code?editor.
????????///?</summary>
????????private?void?InitializeComponent()
????????{
????????????System.Resources.ResourceManager?resources?=?new?System.Resources.ResourceManager(typeof(Form1));
????????????this.comboBox1?=?new?System.Windows.Forms.ComboBox();
????????????this.axWebBrowser1?=?new?AxSHDocVw.AxWebBrowser();
????????????((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
????????????this.SuspendLayout();
????????????//?
????????????//?comboBox1
????????????//?
????????????this.comboBox1.Location?=?new?System.Drawing.Point(24,?32);
????????????this.comboBox1.Name?=?"comboBox1";
????????????this.comboBox1.Size?=?new?System.Drawing.Size(200,?21);
????????????this.comboBox1.TabIndex?=?1;
????????????this.comboBox1.SelectedIndexChanged?+=?new?System.EventHandler(this.comboBox1_SelectedIndexChanged);
????????????//?
????????????//?axWebBrowser1
????????????//?
????????????this.axWebBrowser1.Anchor?=?((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top?|?System.Windows.Forms.AnchorStyles.Bottom)?
????????????????|?System.Windows.Forms.AnchorStyles.Left)?
????????????????|?System.Windows.Forms.AnchorStyles.Right)));
????????????this.axWebBrowser1.Enabled?=?true;
????????????this.axWebBrowser1.Location?=?new?System.Drawing.Point(32,?96);
????????????this.axWebBrowser1.OcxState?=?((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState"));
????????????this.axWebBrowser1.Size?=?new?System.Drawing.Size(576,?232);
????????????this.axWebBrowser1.TabIndex?=?2;
????????????//?
????????????//?Form1
????????????//?
????????????this.AutoScaleBaseSize?=?new?System.Drawing.Size(5,?13);
????????????this.ClientSize?=?new?System.Drawing.Size(648,?397);
????????????this.Controls.Add(this.axWebBrowser1);
????????????this.Controls.Add(this.comboBox1);
????????????this.Name?=?"Form1";
????????????this.Text?=?"Form1";
????????????((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
????????????this.ResumeLayout(false);
????????}
????????#endregion
????????/**////?<summary>
????????///?The?main?entry?point?for?the?application.
????????///?</summary>
????????[STAThread]
????????static?void?Main()?
????????{
????????????Application.Run(new?Form1());
????????}
????????private?void?comboBox1_SelectedIndexChanged(object?sender,?System.EventArgs?e)
????????{????????????
????????????myApplication1.ReportService.ReportingService?rs?=?new?myApplication1.ReportService.ReportingService();
????????????rs.Credentials?=?System.Net.CredentialCache.DefaultCredentials;
????????????//?Render?arguments
????????????byte[]?result?=?null;
????????????string?reportPath?=?items[comboBox1.SelectedIndex].Path;?
????????????string?format?=?"HTML4.0";
????????????string?historyID?=?null;
????????????string?devInfo?=?@"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
????????????//?Prepare?report?parameter.
????????????myApplication1.ReportService.ParameterValue[]?parameters?=?null;
????????????myApplication1.ReportService.DataSourceCredentials[]?credentials?=?null;
????????????string?showHideToggle?=?null;
????????????string?encoding;
????????????string?mimeType;
????????????myApplication1.ReportService.Warning[]?warnings?=?null;
????????????myApplication1.ReportService.ParameterValue[]?reportHistoryParameters?=?null;
????????????string[]?streamIDs?=?null;
????????????myApplication1.ReportService.SessionHeader?sh?=
????????????????new?myApplication1.ReportService.SessionHeader();
????????????rs.SessionHeaderValue?=?sh;
????????????try{
????????????????result?=?rs.Render(reportPath,?format,?historyID,?devInfo,?parameters,?credentials,?
????????????????????showHideToggle,?out?encoding,?out?mimeType,?out?reportHistoryParameters,?out?warnings,
????????????????????out?streamIDs);
????????????????sh.SessionId?=?rs.SessionHeaderValue.SessionId;
????????????????Console.WriteLine("SessionID?after?call?to?Render:?{0}",?
????????????????????rs.SessionHeaderValue.SessionId);
????????????????Console.WriteLine("Execution?date?and?time:?{0}",
????????????????????rs.SessionHeaderValue.ExecutionDateTime);
????????????????Console.WriteLine("Is?new?execution:?{0}",
????????????????????rs.SessionHeaderValue.IsNewExecution);
????????????}
????????????catch(SoapException?err?)
????????????{
????????????????Console.WriteLine(err.Detail.OuterXml);
????????????}
????????????//?Write?the?contents?of?the?report?to?an?HTML?file.
????????????try
????????????{
????????????????FileStream?stream?=?File.Create(?"report.htm",?result.Length?);????????
????????????????Console.WriteLine(?"File?created."?);
????????????????stream.Write(?result,?0,?result.Length?);
????????????????Console.WriteLine(?"Result?written?to?the?file."?);
????????????????stream.Close();
????????????????//axPdf1.src?=?"report.pdf";
????????????????int?zero=0;
????????????????object?oZero=?zero;
????????????????string?str?=?"";
????????????????object?oStr?=?str;
????????????????axWebBrowser1.Navigate("http://localhost/ReportServer?%2freport+sample%2fReport_A1&rs:Command=Render",
ref?oZero,
ref?oStr,
????????????????????????ref?oStr,
????????????????????????ref?oStr);
????????????}
????????????catch?(?Exception?err?)
????????????{
????????????????Console.WriteLine(?err.Message?);
????????????}
????????}
????}
}
轉載于:https://www.cnblogs.com/applegreen/archive/2005/04/26/145409.html
總結
以上是生活随笔為你收集整理的Reporting Service的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转贴]无刷新的2个DropDownLi
- 下一篇: EBook网址