发布一个水晶报表的通用类:CrystalHelper,适用环境如下:

.Net Framework 2.0 ,ASP.NET2.0中直接实例化就可以用了,封装了常用的操作,特别是权限验证部分,很方便,可以避免在ASP.NET 中使用CrystalReports时遇到的很多问题!部分代码如下:

usingSystem;
usingSystem.Text;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Globalization;
usingSystem.Threading;
usingSystem.Windows.Forms;
usingSystem.Web;
usingSystem.Diagnostics.CodeAnalysis;
usingSystem.Collections.Generic;

//Crystalreports required assembliesusingCrystalDecisions.CrystalReports.Engine;
usingCrystalDecisions.Shared;
usingCrystalDecisions.Windows.Forms;

namespaceCrystalLibrary
{
/**////<summary>///Supported export formats for Crystal reports.
///</summary>

publicenumCrystalExportFormat
{
/**////<summary>///Export to Microsoft Word (*.doc)
///</summary>

Word,

/**////<summary>///Export to Microsoft Excel (*.xls)
///</summary>

Excel,

/**////<summary>///Export to Rich Text format (*.rtf)
///</summary>

RichText,

/**////<summary>///Export to Adobe Portable Doc format (*.pdf)
///</summary>

PortableDocFormat
    }

/**////<summary>///<p>The CrystalHelper class handles a number of actions that are usually
///required to use Crystal Reports for Visual Studio .Net. 
///</p>///<p>This class can be used for all reports based on typed datasets and reports that
///have embedded queries.</p>///<p>Please note that you need to register Crystal Reports when you want to use 
///it in Visual Studio. Registration of Crystal Reports for VS.Net is free!</p>///</summary>///<example>///The following example shows how CrystalHelper can be used to print a report
///where the information is supplied by a DataSet:
///<code>///void PrintReport(SqlConnection conn)
///{
///using (DataSet ds = new TestData())
///{
///SqlHelper.FillDataset(conn, 
///CommandType.Text, "SELECT * FROM Customers", 
///ds, new string [] {"Customers"});
//////using (CrystalHelper helper = new CrystalHelper(new CrystalReport1()))
///{
///helper.DataSource = ds;
///helper.Open();
///helper.Print();
///helper.Close();
///}
///}
///}
///</code>//////</example>

publicclassCrystalHelper : IDisposable
{
Local Variables#regionLocal Variables
privatestring_datebaseName;
privatestring_serverName;
privatestring_userId;
privatestring_password;
privatebool_integratedSecurity;

privateReportDocument    _reportDocument;
privateDataSet            _reportData;
privatestring_reportFile;
privatebool_reportIsOpen;
privateSortedList<string,object>_parameters;

#endregion

Private methods#regionPrivate methods
/**////<summary>///Get the Crystal Export format using the CrystalExportFormat export format definitions
///</summary>///<param name="exportFormat"><see cref="CrystalExportFormat"/>export type</param>///<returns>Crystal Reports<see cref="ExportFormatType"/>type</returns>

privatestaticExportFormatType GetExportType(CrystalExportFormat exportFormat)
{
            ExportFormatType result
=ExportFormatType.RichText;

switch(exportFormat)
{
caseCrystalExportFormat.Word        : 
                    result
=ExportFormatType.WordForWindows;    
break;
caseCrystalExportFormat.Excel        : 
                    result
=ExportFormatType.Excel;            
break;
caseCrystalExportFormat.RichText    : 
                    result
=ExportFormatType.RichText;
break;
caseCrystalExportFormat.PortableDocFormat    : 
                    result
=ExportFormatType.PortableDocFormat;
break;
default:
thrownewCrystalHelperException(string.Format(CultureInfo.CurrentUICulture,"Unsupported export format '{0}'.", exportFormat.ToString()));
            }
returnresult;
        }

/**////<summary>///Get the CrystalExportFormat export format definitions using the file name extension
///</summary>///<param name="fileName">Name of the export file</param>///<returns><see cref="CrystalExportFormat"/>export type</returns>

[SuppressMessage("Microsoft.Performance","CA1807:AvoidUnnecessaryStringCreation", MessageId="stack0")]
privatestaticCrystalExportFormat GetExportFormat(stringfileName)
{
            CrystalExportFormat result
=CrystalExportFormat.RichText;

stringextension=Helpers.FileExtension(fileName).ToUpper(CultureInfo.CurrentCulture);

switch(extension)
{
case"DOC"
                    result
=CrystalExportFormat.Word;    
break;
case"XLS"
                    result
=CrystalExportFormat.Excel;            
break;
case"RTF"
                    result
=CrystalExportFormat.RichText;
break;
case"PDF"
                    result
=CrystalExportFormat.PortableDocFormat;
break;
default:
thrownewCrystalHelperException(string.Format(CultureInfo.CurrentUICulture,"Unsupported export format for file '{0}'.", fileName));
            }
returnresult;
        }

/**////<summary>///Assign a<see cref="ConnectionInfo"/>to a<see cref="CrystalDecisions.CrystalReports.Engine.Table"/>object
///</summary>///<param name="table">Table to which the connection is to be assigned</param>///<param name="connection">Connection to the database.</param>

privatestaticvoidAssignTableConnection(CrystalDecisions.CrystalReports.Engine.Table table, ConnectionInfo connection)
{
//Cache the logon info blockTableLogOnInfo logOnInfo=table.LogOnInfo;

//Set the connectionlogOnInfo.ConnectionInfo=connection;

//Apply the connection to the table!table.ApplyLogOnInfo(logOnInfo);
        }

/**////<summary>///Assign the database connection to the table in all the report sections.
///</summary>

privatevoidAssignConnection()
{
            ConnectionInfo connection
=newConnectionInfo();

            connection.DatabaseName
=_datebaseName;
            connection.ServerName
=_serverName;
if(_integratedSecurity)
{
                connection.IntegratedSecurity
=_integratedSecurity;
            }
else{
                connection.UserID
=_userId;
                connection.Password
=_password;
            }

//First we assign the connection to all tables in the main report
//
foreach(CrystalDecisions.CrystalReports.Engine.Table tablein_reportDocument.Database.Tables)
{
                AssignTableConnection(table, connection);
            }

//Now loop through all the sections and its objects to do the same for the subreports
//
foreach(CrystalDecisions.CrystalReports.Engine.Section sectionin_reportDocument.ReportDefinition.Sections)
{
//In each section we need to loop through all the reporting objectsforeach(CrystalDecisions.CrystalReports.Engine.ReportObject reportObjectinsection.ReportObjects)
{
if(reportObject.Kind==ReportObjectKind.SubreportObject)
{
                        SubreportObject subReport
=(SubreportObject)reportObject;
                        ReportDocument  subDocument
=subReport.OpenSubreport(subReport.SubreportName);

foreach(CrystalDecisions.CrystalReports.Engine.Table tableinsubDocument.Database.Tables)
{
                            AssignTableConnection(table, connection);
                        }
                    }
                }
            }
        }

/**////<summary>///Assign the DataSet to the report.
///</summary>

privatevoidAssignDataSet()
{
            DataSet reportData
=_reportData.Copy();

//Remove primary key info. CR9 does not appreciate this information!!!foreach(DataTable dataTableinreportData.Tables)
{
foreach(DataColumn dataColumnindataTable.PrimaryKey)
{
                    dataColumn.AutoIncrement
=false;
                }
                dataTable.PrimaryKey=null;
            }

//Now assign the dataset to all tables in the main report
//
_reportDocument.SetDataSource(reportData);

//Now loop through all the sections and its objects to do the same for the subreports
//
foreach(CrystalDecisions.CrystalReports.Engine.Section sectionin_reportDocument.ReportDefinition.Sections)
{
//In each section we need to loop through all the reporting objectsforeach(CrystalDecisions.CrystalReports.Engine.ReportObject reportObjectinsection.ReportObjects)
{
if(reportObject.Kind==ReportObjectKind.SubreportObject)
{
                        SubreportObject subReport
=(SubreportObject)reportObject;
                        ReportDocument  subDocument
=subReport.OpenSubreport(subReport.SubreportName);

                        subDocument.SetDataSource(reportData);
                    }
                }
            }
        }

/**////<summary>///Create a ReportDocument object using a report file and store
///the name of the file.
///</summary>///<param name="reportFile">Name of the CrystalReports file (*.rpt).</param>///<returns>A valid ReportDocument object.</returns>

privateReportDocument CreateReportDocument(stringreportFile)
{
            ReportDocument newDocument
=newReportDocument();

            _reportFile
=reportFile;
            newDocument.Load(reportFile);

returnnewDocument;
        }

/**////<summary>///Sets the parameters that have been added using the SetParameter method
///</summary>

privatevoidSetParameters()
{
foreach(ParameterFieldDefinition parameterin_reportDocument.DataDefinition.ParameterFields)
{
try{
//Now get the current value for the parameterCrystalDecisions.Shared.ParameterValues currentValues=parameter.CurrentValues;
                    currentValues.Clear();

//Create a value object for Crystal reports and assign the specified value.CrystalDecisions.Shared.ParameterDiscreteValue newValue=newCrystalDecisions.Shared.ParameterDiscreteValue();

if(_parameters.ContainsKey(parameter.Name))
{
                        newValue.Value
=_parameters[parameter.Name];
                    }

//Now add the new value to the values collection and apply the 
//collection to the report.currentValues.Add(newValue);
                    parameter.ApplyCurrentValues(currentValues);
                }
catch{
//Ignore any errors}
            }
        }

#endregion

Constructors#regionConstructors
/**////<summary>///Initializes a new instance of the<see cref="T:CrystalHelper"/>class.
///</summary>

publicCrystalHelper()
{
            _parameters
=newSortedList<string,object>();
        }

/**////<summary>///Initializes a new instance of the<see cref="T:CrystalHelper"/>class.
///</summary>///<param name="report">The<see cref="T:ReportDocument"/>object for an embedded report.</param>

publicCrystalHelper(ReportDocument report) :this()
{
            _reportDocument
=report;
        }

/**////<summary>///Initializes a new instance of the<see cref="T:CrystalHelper"/>class.
///</summary>///<param name="reportFile">Name and path for a CrystalReports (*.rpt) file.</param>

publicCrystalHelper(stringreportFile)
            :
this()
{
            _reportDocument
=CreateReportDocument(reportFile);
        }

/**////<summary>///Initializes a new instance of the<see cref="T:CrystalHelper"/>class.
///</summary>///<param name="report">The<see cref="T:ReportDocument"/>object for an embedded report.</param>///<param name="serverName">Name of the database server.</param>///<param name="databaseName">Name of the database.</param>///<param name="userId">The user id required for logon.</param>///<param name="userPassword">The password for the specified user.</param>

publicCrystalHelper(ReportDocument report,stringserverName,stringdatabaseName,stringuserId,stringuserPassword)
            :
this()
{
            _reportDocument
=report;

//Setup the connection information_serverName=serverName;        
            _datebaseName
=databaseName;
            _userId
=userId;
            _password
=userPassword;
        }

/**////<summary>///Initializes a new instance of the<see cref="T:CrystalHelper"/>class.
///</summary>///<param name="report">The<see cref="T:ReportDocument"/>object for an embedded report.</param>///<param name="serverName">Name of the database server.</param>///<param name="databaseName">Name of the database.</param>///<param name="integratedSecurity">if set to<c>true</c>integrated security is used to connect to the database; false if otherwise.</param>

publicCrystalHelper(ReportDocument report,stringserverName,stringdatabaseName,boolintegratedSecurity)
            :
this()
{
            _reportDocument
=report;

//Setup the connection information_serverName=serverName;
            _datebaseName
=databaseName;
            _integratedSecurity
=integratedSecurity;
        }

/**////<summary>///Initializes a new instance of the<see cref="T:CrystalHelper"/>class.
///</summary>///<param name="reportFile">Name and path for a CrystalReports (*.rpt) file.</param>///<param name="serverName">Name of the database server.</param>///<param name="databaseName">Name of the database.</param>///<param name="userId">The user id required for logon.</param>///<param name="userPassword">The password for the specified user.</param>

publicCrystalHelper(stringreportFile,stringserverName,stringdatabaseName,stringuserId,stringuserPassword)
            :
this()
{
            _reportDocument
=CreateReportDocument(reportFile);

//Setup the connection information_serverName=serverName;        
            _datebaseName
=databaseName;
            _userId
=userId;
            _password
=userPassword;
        }

/**////<summary>///Initializes a new instance of the<see cref="T:CrystalHelper"/>class.
///</summary>///<param name="reportFile">Name and path for a CrystalReports (*.rpt) file.</param>///<param name="serverName">Name of the database server.</param>///<param name="databaseName">Name of the database.</param>///<param name="integratedSecurity">if set to<c>true</c>integrated security is used to connect to the database; false if otherwise.</param>

publicCrystalHelper(stringreportFile,stringserverName,stringdatabaseName,boolintegratedSecurity)
            :
this()
{
            _reportDocument
=CreateReportDocument(reportFile);

//Setup the connection information_serverName=serverName;
            _datebaseName
=databaseName;
            _integratedSecurity
=integratedSecurity;
        }
        
#endregion

Public properties#regionPublic properties
/**////<summary>///Gets or sets the report source.
///</summary>///<value>The report source.</value>///<remarks>///Use this property when you want to show the report in the 
///CrystalReportsViewer control.</remarks>

publicReportDocument ReportSource
{
get
return_reportDocument; 
            }
set{
if(_reportDocument!=null)
{
                    _reportDocument.Dispose();
                }
                _reportDocument=value;
if(value==null)
{
                    _reportFile
=null;
                }
            }
        }

/**////<summary>///Gets or sets the report file.
///</summary>///<value>The report file.</value>

publicstringReportFile
{
get
return_reportFile; 
            }
set{
if(_reportDocument!=null)
{
                    _reportDocument.Dispose();
                }
if(value!=null&&value.Trim().Length>0)
{
                    _reportDocument
=CreateReportDocument(value);
                }
else{
                    _reportFile
=value;
                    _reportDocument
=null;
                }
            }
        }

/**////<summary>///Gets or sets the data source.
///</summary>///<value>The data source.</value>

publicDataSet DataSource
{
get
return_reportData; 
            }
set
if(_reportData!=null)
{
                    _reportData.Dispose();
                }
                _reportData=value; 
            }
        }

/**////<summary>///Gets or sets the name of the server.
///</summary>///<value>The name of the server.</value>

publicstringServerName
{
get
return_serverName; 
            }
set
                _serverName
=value; 
            }
        }

/**////<summary>///Gets or sets the name of the database.
///</summary>///<value>The name of the database.</value>

publicstringDatabaseName
{
get{
return_datebaseName; 
            }
set
                _datebaseName
=value; 
            }
        }

/**////<summary>///Gets or sets the user id.
///</summary>///<value>The user id.</value>

publicstringUserId
{
get
return_userId; 
            }
set
                _userId
=value; 
            }
        }

/**////<summary>///Gets or sets the password.
///</summary>///<value>The password.</value>

publicstringPassword
{
get
return_password; 
            }
set
                _password
=value; 
            }
        }

/**////<summary>///Gets or sets a value indicating whether [integrated security].
///</summary>///<value><c>true</c>if integrated security is used to connect to the database; false if otherwise.</value>

publicboolIntegratedSecurity
{
get{
return_integratedSecurity;
            }
set{
                _integratedSecurity
=value;
            }
        }

#endregion

Public static properties#regionPublic static properties
/**////<summary>///Gets the export filter for a<see cref="T:SaveFileDialog"/>///</summary>///<value>The export filter.</value>
publicstaticstringExportFilter
{
get{
                StringBuilder filter
=newStringBuilder();

//TODO: Translations???filter.Append("Rich text (*.rtf)|*.rtf|");
                filter.Append(
"Excel (*.xls)|*.xls|");
                filter.Append(
"Word (*.doc)|*.doc|");
                filter.Append(
"Portable Document Format (*.pdf)|*.pdf");

returnfilter.ToString();
            }
        }

#endregion

Public methods#regionPublic methods
/**////<summary>///Set value for report parameters
///</summary>///<param name="name">Parameter name.</param>///<param name="value">Value to be set for the specified parameter.</param>

publicvoidSetParameter(stringname,objectvalue)
{
if(_parameters.ContainsKey(name))
{
                _parameters[name]
=value;
            }
else{
                _parameters.Add(name, value);
            }
        }

/**////<summary>///Close the report.
///</summary>///<remarks>///This method will throw an exception when the Open() method is not yet called on this object.
///</remarks>

publicvoidClose()
{
if(!_reportIsOpen)thrownewInvalidOperationException("The report is already closed.");

            _reportDocument.Close();
            _reportIsOpen
=false;
        }

/**////<summary>///Open the report.
///</summary>///<remarks>///<p>This method will first attempt to assign the DataSource if that was specified. When no DataSource has been
///assigned, a check will be made to see if database connection information has been specified. When this is the case
///this information will be assigned to the report.
///</p>///<P>This method will throw an exception when:
///<list type="bullet">///<item><description>The report (rpt) has not been assigned yet.</description></item>///<item><description>The Open() method has already been called on this object.</description></item>///<item><description>A table being used in the report does not exist in the dataset which has been assigned to this report. (only when a dataset has been assigned to the DataSource property)</description></item>///<item><description>The ServerName, DatabaseName or UserId property has not been set. (only when the DataSource property has not been set)</description></item>///<item><description>When no database connection or datset could be assignd.</description></item>///</list>///</P></remarks>

publicvoidOpen()
{
if(_reportDocument==null)thrownewCrystalHelperException("First assign a report document.");
if(_reportIsOpen)thrownewInvalidOperationException("The report is already open.");

            SetParameters();
            
//Check if the connection object exists. If so assign that
//to the report.if(_reportData!=null)
{
//Assign the dataset to the report.AssignDataSet();
            }
else{
if(_serverName.Length==0||(!_integratedSecurity&&_userId.Length==0)||_datebaseName.Length==0)
{
thrownewCrystalHelperException("Connection information is incomplete. Report could not be opened.");
                }
                AssignConnection();
            }
            _reportIsOpen=true;
        }

/**////<summary>///Force a refresh of the data in the report. 
///</summary>///<remarks>///When the report is based on a DataSource, the report will be refreshed using 
///data in that DataSource. In case the report has it's own database connection 
///and uses SQL queries, the report will be refreshed using that information. 
///<br/>///<p>///This method will throw an exception when the Open() method is not yet called on this object.
///</p>///</remarks>

publicvoidRefresh()
{
if(!_reportIsOpen)thrownewInvalidOperationException("The report is not open.");

            _reportDocument.Refresh();
        }

/**////<summary>///Print the report to the specified printer. 
///</summary>///<param name="printerName">Name of the printer to print the information to.</param>///<param name="nrCopies">The number of copies required.</param>///<param name="collatePages">Indicates whether to collate the pages.</param>///<param name="firstPage">First page to be printed. When less than 1, printing starts at the first page.</param>///<param name="lastPage">Last page to be printed. When less than 1, or more than 9999, the last page will be printed as last page.</param>///<remarks>///This method will throw an exception when the Open() method is not yet called on this object.
///</remarks>

publicvoidPrint(stringprinterName,intnrCopies,boolcollatePages,intfirstPage,intlastPage)
{
boolopenedHere=false;

if(!_reportIsOpen)
{
this.Open();
                openedHere
=true;
            }

            _reportDocument.PrintOptions.PrinterName
=printerName;

if(firstPage<1) firstPage=0;
if((lastPage<1)||(lastPage>9999)) lastPage=0;

            _reportDocument.PrintToPrinter(nrCopies, collatePages, firstPage, lastPage);
if(openedHere)
{
this.Close();
            }
        }

/**////<summary>///Prints one copy of the entire report to the default printer.
///</summary>///<remarks>///This method will throw an exception when the Open() method is not yet called on this object.
///</remarks>

publicvoidPrint()
{
this.Print(string.Empty,1,false,0,0);
        }

/**////<summary>///Export the report to a file. 
///</summary>///<param name="fileName">Name of the export file.</param>///<remarks>///The type of document is specified by the extension for the file 
///name When no extension is specified, the export format will default to Rich text.
///The following document types are supported:
///<list type="bullet">///<item><description>Word (*.doc).</description></item>///<item><description>Excel (*.xls).</description></item>///<item><description>Rich text (*.rtf).</description></item>///<item><description>Portable Doc Format (*.pdf)</description></item>///</list><br/>///<p>///This method will throw an exception when the Open() method is not yet called on this object.
///</p>///</remarks>

publicvoidExport(stringfileName)
{
this.Export(fileName, GetExportFormat(fileName));
        }

/**////<summary>///Export the report to a file using the specified format. 
///</summary>///<param name="fileName">Name of the export file.</param>///<param name="exportFormat">CrystalExportFormat.</param>///<remarks>///The following document types are supported:
///<list type="bullet">///<item><description>Word (*.doc).</description></item>///<item><description>Excel (*.xls).</description></item>///<item><description>Rich text (*.rtf).</description></item>///<item><description>Portable Doc Format (*.pdf)</description></item>///</list><br/>///<p>///This method will throw an exception when the Open() method is not yet called on this object.
///</p>///</remarks>

publicvoidExport(stringfileName, CrystalExportFormat exportFormat)
{
boolopenedHere=false;

if(!_reportIsOpen) 
{
this.Open();
                openedHere
=true;
            }

            _reportDocument.ExportToDisk(GetExportType(exportFormat), fileName);

if(openedHere)
{
this.Close();
            }
        }

/**////<summary>///Exports the report to the specified HttpResponse.
///</summary>///<param name="response">The response object to export the report to.</param>///<param name="exportFormat">The export format.</param>

publicvoidExport(HttpResponse response, CrystalExportFormat exportFormat)
{
this.Export(response, exportFormat,false,"");
        }

/**////<summary>///Exports the report to the specified HttpResponse and prompts the user for a file name. The default 
///name is the specified file name, 
///</summary>///<param name="response">The response object to export the report to.</param>///<param name="exportFormat">The export format.</param>///<param name="asAttachment">If the asAttachment Boolean variable is set to True, a File Download dialog box appears. If the asAttachment Boolean variable is set to False, the exported report opens in the browser window.</param>///<param name="attachmentName">When you choose to save the file, the file name is set to the attachmentName string variable. If you do not specify the attachmentName variable, then the default file name is "Untitled," with the specified file extension. The file name can be changed in the Save As dialog box.</param>

publicvoidExport(HttpResponse response, CrystalExportFormat exportFormat,boolasAttachment,stringattachmentName)
{
if(response==null)thrownewArgumentNullException("response");
if(attachmentName==null)thrownewArgumentNullException("asAttachment");

boolopenedHere=false;

try{
if(!_reportIsOpen)
{
this.Open();
                    openedHere
=true;
                }

                _reportDocument.ExportToHttpResponse(GetExportType(exportFormat), response, asAttachment, attachmentName);
            }
finally{
if(openedHere)
{
this.Close();
                }
            }
        }

#endregion

Public static methods#regionPublic static methods
/**////<summary>///Show or hide the status bar on the crystalreports viewer.
///</summary>///<param name="viewer">Current viewer.</param>///<param name="visible">Set if the status bar is visible or not.</param>///<remarks>///This method will throw an exception when the viewer object is not specified.
///</remarks>///<example>///This example shows how the status bar can be removed:
///<code>///CrystalHelper.ViewerStatusBar(myViewer, false);
///</code>///</example>

[SuppressMessage("Microsoft.Design","CA1011:ConsiderPassingBaseTypesAsParameters")]
publicstaticvoidViewerStatusBar(CrystalReportViewer viewer,boolvisible)
{
if(viewer==null)thrownewArgumentNullException("viewer");

foreach(Control controlinviewer.Controls)
{
if(string.Compare(control.GetType().Name,"StatusBar",true, CultureInfo.InvariantCulture)==0)
{
                    control.Visible
=visible;
                }
            }
        }

/**////<summary>///Show or hide the tabs on the crystalreports viewer.
///</summary>///<param name="viewer">Current viewer</param>///<param name="visible">Set if the status bar is visible or not.</param>///<remarks>///This method will throw an exception when the viewer object is not specified.
///</remarks>///<example>///This example shows how the tabs can be removed:
///<code>///CrystalHelper.ViewerTabs(myViewer, false);
///</code>///</example>

[SuppressMessage("Microsoft.Design","CA1011:ConsiderPassingBaseTypesAsParameters")]
publicstaticvoidViewerTabs(CrystalReportViewer viewer,boolvisible)
{
if(viewer==null)thrownewArgumentNullException("viewer");

foreach(Control controlinviewer.Controls)
{
if(string.Compare(control.GetType().Name,"PageView",true, CultureInfo.InvariantCulture)==0)
{
                    TabControl tab
=(TabControl)((PageView)control).Controls[0];

if(!visible)
{
                        tab.ItemSize
=newSize(0,1);
                        tab.SizeMode
=TabSizeMode.Fixed;
                        tab.Appearance
=TabAppearance.Buttons;
                    }
else{
                        tab.ItemSize
=newSize(67,18);
                        tab.SizeMode
=TabSizeMode.Normal;
                        tab.Appearance
=TabAppearance.Normal;
                    }
                }
            }
        }

/**////<summary>///Replace the current name of a tab with a new name.
///</summary>///<param name="viewer">Current viewer.</param>///<param name="oldName">The name to be replaced.</param>///<param name="newName">The new name.</param>///<remarks>///This method will throw an exception when:
///<list type="bullet">///<item><description>The viewer object is not specified.</description></item>///<item><description>The Open() method is not yet called on this object.</description></item>///</list>///</remarks>///<example>///This example shows how the default tab description MainReport can be replaced.
///<code>///CrystalHelper.ViewerStatusBar(myViewer, "MainReport", "And now for something completely different");
///</code>///</example>

[SuppressMessage("Microsoft.Design","CA1011:ConsiderPassingBaseTypesAsParameters")]
publicstaticvoidReplaceReportName(CrystalReportViewer viewer,stringoldName,stringnewName)
{
if(viewer==null)thrownewArgumentNullException("viewer");
if(oldName==null||oldName.Length==0)thrownewArgumentException("May not be empty.","oldName");

foreach(Control controlinviewer.Controls)
{
if(string.Compare(control.GetType().Name,"PageView",true, CultureInfo.InvariantCulture)==0)
{
foreach(Control controlInPageincontrol.Controls)
{
if(string.Compare(controlInPage.GetType().Name,"TabControl",true, CultureInfo.InvariantCulture)==0)
{
                            TabControl tabs
=(TabControl)controlInPage;

foreach(TabPage tabPageintabs.TabPages)
{
if(string.Compare(tabPage.Text, oldName,false, CultureInfo.InvariantCulture)==0)
{
                                    tabPage.Text
=newName;
return;
                                }
                            }
                        }
                    }
                }
            }
        }

#endregion

IDisposable Members#regionIDisposable Members
/**////<summary>///Dispose of this object's resources.
///</summary>

publicvoidDispose()
{
            Dispose(
true);
            GC.SuppressFinalize(
true);//as a service to those who might inherit from us}

/**////<summary>///Free the instance variables of this object.
///</summary>///<param name="disposing">if set to<c>true</c>[disposing].</param>

protectedvirtualvoidDispose(booldisposing)
{
if(disposing)
{
if(_reportIsOpen)
{
                    _reportDocument.Close();
                }
if(_reportDocument!=null)
{
                    _reportDocument.Dispose();
                    _reportDocument
=null;
                }

if(_reportData!=null)
{
                    _reportData.Dispose();
                    _reportData
=null;
                }
            }
        }

#endregion
    }
}

转载于:https://www.cnblogs.com/pccai/articles/895169.html

发布一个水晶报表的通用类:CrystalHelper相关推荐

  1. 发布一个收藏的XML处理类

    public class XmlHelper { public XmlHelper() { } /// <summary> /// 读取数据 /// </summary> // ...

  2. 水晶报表技术(12)——一个投票系统水晶报表应用

        前一段时间,公司需要做一个在线的调查投票系统,目的是统计公司能力等级指数,统计的能力级别分三大类,分别为一级能力要素,二级能力要素,三级能力要素,不同的一级能力要素下面分若干的二级能力要素,每 ...

  3. 水晶报表使用经验总结

    资料: Asp.Net中使用水晶报表(上) www.dotnet8.com  2002-9-6  DotNet吧 这篇文章教你如何在.Net Web应用中使用水晶报表,也可以让你在学习过程中少走一些弯 ...

  4. CSDN社区关于水晶报表的讨论

    CSDN - 专家门诊 关闭窗口       主        题:  有关水晶报表的使用经验和资料总结,欢迎各位使用过水晶报表的同仁把自己在使用过程中的总结.经验.体会同大家共享!! 作       ...

  5. C#之二十三 打印和水晶报表

    视频课堂https://edu.csdn.net/course/play/7621 C#程序设计及宿舍管理系统实战  https://edu.csdn.net/course/detail/27107 ...

  6. VisualStudio2008+水晶报表的使用

    1:打开VisualStudio2008,新建一个Windows窗体应用程序项目,名称可以自定义,选择项目的保存路径,然后确定 刚新建好的窗体应用程序: 2. 把准备好的水晶报表插件复制到项目中的bi ...

  7. 从ASP.NET传递参数给水晶报表

    原文 http://www.cnblogs.com/insus/p/3281114.html 上次Insus.NET有简单写了一篇文章<Visual Studio 2012使用水晶报表Cryst ...

  8. [转]VS2010中水晶报表安装应用及实例

    基本分类如下: 第一部分:VS2010简介 VS2010是微软的提供的一套完整的开发环境,功能也是相当的大 微软宣布了下一代开发工具和平台的正式名称,分别称为"Visual Studio T ...

  9. .NET环境下水晶报表使用总

    水晶报表是一个优秀的报表开发工具,本人在开发通用管理系统的时候,所有报表都使用水晶报表,其简单.易用和强大的功能令笔者倍加喜爱,现将水晶报表使用手记呈现给大家. 一.在使用自带的水晶报表时,请注册,否 ...

  10. .NET环境下水晶报表使用总结

    水晶报表是一个优秀的报表开发工具,本人在开发通用管理系统的时候,所有报表都使用水晶报表,其简单.易用和强大的功能令笔者倍加喜爱,现将水晶报表使用手记呈现给大家. 一.在使用自带的水晶报表时,请注册,否 ...

最新文章

  1. BZOJ 2140 稳定婚姻(强联通分量判环)【BZOJ修复工程】
  2. JVM的标配参数和X参数
  3. 读取TFrecord
  4. C 语言高效编程与代码优化
  5. mysql mvcc 隔离级别_关于 Mysql 四种隔离级别中 Lock 和 MVCC 的关系
  6. java games_Java Me Games
  7. Java 数组排序及元素查找
  8. Configure a VLAN on top of a team with NetworkManager (nmcli) in RHEL7
  9. My97DatePicker日期控件的使用
  10. poj1258 Agri-Net 最小生成树Kruskal、Prim
  11. java: 无法将类 com.duo_tai.Cow中的构造器 Cow应用到给定类型;
  12. 返回相同宽度数字型字符串
  13. Fcitx──小企鹅输入法---Ubuntu input method
  14. python os模块打开文件_Python 文件操作之OS模块
  15. 操作系统 第二部分 进程管理(三)
  16. zk-snark 时延
  17. 一个网站图标引发的血案!绕过同源策略,判断你是否登录了某网站
  18. GoLang基础知识(1)
  19. 潮汕“七样羹”,吃了变后生
  20. Python微信公众号

热门文章

  1. H3C防火墙安全域知识、远程登陆及web页面
  2. dah计算机原理,卢伟计算机原理themicrocomputerprinciplech3.pptx
  3. 在计算机上格式u盘启动,请问U盘制作成启动盘后插电脑上显示0字节,打不开也无法格式化,提示磁盘写有保护怎么回事?...
  4. ECCV2020:论文解读《Synthesize then Compare: Detecting Failures and Anomalies for Semantic Segmentation》
  5. Pytorch中的 AdaptivePooling
  6. 求职简历中一些常见的问题
  7. SAP Exchange Rate 外币汇率的设置
  8. .html怎么查看源代码,html的网页源代码怎么查看
  9. java设置铃声_Android来电铃声默认设置的实现方法与如何设置语音来电的默认铃声...
  10. linux下安装微软雅黑字体库