报表字段的多语言本地化

报表字段的多语言本地化

using CrystalDecisions.Shared;//负责解释TableLogOnInfo类

using CrystalDecisions.CrystalReports.Engine;//负责解释ReportDocument类

TableLogOnInfo类: 提供属性,以便检索和设置表连接选项。
ReportDocument类 : 表示一个报表,并且包含定义、格式化、加载、导出和打印该报表的属性和方法。用于定义和格式化报表、设置导出选项、设置打印选项和设置报表选项的属性和方法可通过由 ReportDocument 属性返回的对象进行访问。

    /// <summary>
    /// 初始化报表
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }

    /// <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");
    }

你可能感兴趣的:(本地化)