報表欄位的多語言本地化

來源:互聯網
上載者:User
報表欄位的多語言本地化

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.