簡體   English   中英

在我的C#中不顯示打印選項對話框Crystal Report Viewer進行打印

[英]Printing w/o displaying Print Option Dialog Box Crystal Report Viewer in my C#

我有一個C#應用程序,在窗體中有一個Crystal Report Viewer。 我調用該表單並將其值傳遞給它,該值用於更新與Crystal Report關聯的參數字段,因此僅顯示特定記錄。

一切正常,我可以調用Viewers PrintReport方法來打印報告,而無需操作員干預。

CrystalForm fs = new CrystalForm(); 
fs.SetCrystalOrderNumParameter(ItemID);

 public partial class CrystalForm : Form
    {
        public CrystalForm()
        {
            InitializeComponent();
        }

        public void SetCrystalOrderNumParameter(string ItemID)
        {
            ParameterFields paramFields = new ParameterFields();

            ParameterField paramField = new ParameterField();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            paramField.Name = "ItemID";
            paramDiscreteValue.Value = ItemID;
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);


            crystalReportViewer1.ParameterFieldInfo = paramFields;

            crystalReportViewer1.PrintReport();

        }
    }

我遇到的問題是我希望能夠將值傳遞給Crystal Report,以便它使用此#來確定應打印多少份報告。

有沒有辦法使用Crystal Report Viewer來做到這一點?

預先感謝您的協助。

Crystal Report查看器本身不提供此功能。

若要控制頁面數而沒有彈出對話框,則必須使用CrystalDecisions.CrystalReports.Engine.ReportDocument類。 此類是CrystalReports API用來表示實際的Crystal Report的類,通常將其分配給查看器的ReportSource屬性,以告知查看器要顯示什么報告。 您可能已經在使用此對象,但是我無法從共享代碼中看到將報表源分配到的位置。

ReportDocument類具有PrintToPrinter方法,第二個重載如下所示: void PrintToPrinter(int nCopies, bool collated, int startPageN, int endPageN)

nCopies參數使您可以指定要打印報告的副本數。 該報告的打印設置將默認為該報告的打印機設置,盡管可以通過ReportDocument實例的PrintOptions屬性對其進行更改。

這是一個簡單的代碼示例,其中rptPath是您的Crystal報表的路徑:

var rpt = new ReportDocument();
rpt.Load(rptPath);
rpt.PrintOptions.PrinterName = "MyPrinterName";
//This will print 2 copies of the crystal report.
//You can use the nCopies (first) parameter to specify whatever #
//of copies you wish.
rpt.PrintToPrinter(2, false, 0, 0);

此外,當ReportDocument用於通過Load()方法加載Crystal報表時,它會自動使用報表期望的所有參數填充其ParameterFields集合。 然后,您可以設置參數的值,如顯示的紅色:

rpt.SetParameterValue("ParameterName", value);

最后,如果要與查看器一起顯示此報告,則要做的只是以下操作:

viewer.ReportSource = rpt;

其中rpt是表示報告的ReportDocument對象,查看器是您要用於顯示報告的CrystalDecisions.Windows.Forms.CrystalReportViewer

通過將變量從代碼傳遞到cr報告參數:

可能是這樣的:

CRPT.SetParameterValue("syear", Servercls.year);
CRPT.SetParameterValue("smonth", Servercls.month);
CRPT.SetParameterValue("sday", Servercls.day);

查看此鏈接以獲取更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM