/// <summary>
/// 动态加载报表数据源
/// </summary>
private void ConfigureCrystalReports()
{
try
{
ConnectionInfo connectionInfo = new ConnectionInfo();
//登录等信息可以写入web.config文件
connectionInfo.ServerName = "sqlsvr";
connectionInfo.DatabaseName = "MembershipDB";
connectionInfo.UserID = "adupdate";
connectionInfo.Password = "gsegc";
string reportPath = Request.PhysicalApplicationPath + "LawReports\\CompanyReport.rpt";//报表路径,绝对路径
string strSQL = "SELECT Law_Category.CategoryName,Law_Company.CID,Law_Company.CName,Law_Company.EName,Law_Company.CShort,Law_Company.EShort FROM (MembershipDB.dbo.Law_ShopCard Law_ShopCard INNER JOIN MembershipDB.dbo.Law_Company Law_Company ON Law_ShopCard.CID=Law_Company.CID) INNER JOIN MembershipDB.dbo.Law_Category Law_Category ON Law_ShopCard.CategoryID=Law_Category.CategoryID ORDER BY Law_Category.CategoryName";
DataSet dataSet = SqlHelper.ExecuteDataSet(SqlHelper.ConnectionStringProfile, CommandType.Text, strSQL, null);
//dataSet.WriteXmlSchema(Request.PhysicalApplicationPath + "LawReports\\Law_Company.xsd");
//dataSet.Tables[0].TableName = "Law_Company";
customerReport = new ReportDocument();//实例化报表对象,采用pull的方式
if (File.Exists(reportPath))
{
customerReport.Load(reportPath);//加载报表
}
else
{
//customerReport.Load(reportPath);//加载一个空的指示错误的报表报表
}
customerReport.SetDataSource(dataSet);//可以接受DataSet或者DataTable,ArrayList,List<Type>等基本数据对象
crystalReportViewer.ReportSource = customerReport;//指定报表数据源,可以在此动态加载类似数据源
SetDBLogonForReport(connectionInfo);//处理报表权限,具体使用需要和本项目权限相连!!!!
#region 报表字段的多语言
InitMultiLanguage(customerReport);
#endregion
#region 代码自定义报表样式
//crystalReportViewer.HasToggleGroupTreeButton = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Group_Tree_Button)].Selected;
//crystalReportViewer.HasExportButton = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Export_Button)].Selected;
//crystalReportViewer.HasPrintButton = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Print_Button)].Selected;
//crystalReportViewer.HasViewList = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.View_List_Button)].Selected;
//crystalReportViewer.HasDrillUpButton = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Drill_Up_Button)].Selected;
//crystalReportViewer.HasPageNavigationButtons = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Page_Navigation_Button)].Selected;
//crystalReportViewer.HasGotoPageButton = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Go_to_Page_Button)].Selected;
//crystalReportViewer.HasSearchButton = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Search_Button)].Selected;
//crystalReportViewer.HasZoomFactorList = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Zoom_Button)].Selected;
//crystalReportViewer.HasCrystalLogo = listCRVToolbar.Items[Convert.ToInt32(CeWebCRVToolbarOptions.Crystal_Logo)].Selected;
//crystalReportViewer.DisplayToolbar = listCRVReport.Items[Convert.ToInt32(CeWebCRVReportOptions.Toolbar)].Selected;
//crystalReportViewer.DisplayGroupTree = listCRVReport.Items[Convert.ToInt32(CeWebCRVReportOptions.Group_Tree)].Selected;
//crystalReportViewer.DisplayPage = listCRVReport.Items[Convert.ToInt32(CeWebCRVReportOptions.Main_Page)].Selected;
//crystalReportViewer.SeparatePages = listCRVReport.Items[Convert.ToInt32(CeWebCRVReportOptions.Enable_Separate_Pages)].Selected;
#endregion
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 多语言的实现
/// </summary>
/// <param name="customerReport">用户自定义报表对象</param>
private void InitMultiLanguage(ReportDocument customerReport)
{
TextObject txtObjCID = (TextObject)customerReport.ReportDefinition.ReportObjects["TextCID"];//TextCID是报表中字段的控件ID
txtObjCID.Text = (string)base.GetGlobalResourceObject("Companys", "AID");//AID是资源中的字段ID
TextObject txtObjEShort = (TextObject)customerReport.ReportDefinition.ReportObjects["TextEShort"];
txtObjEShort.Text = (string)base.GetGlobalResourceObject("Companys", "TxtComEShort");
}