2017-02-28 178 views
0

我有一個C#應用程序,在窗體中有一個Crystal Report Viewer。我調用該表單並傳遞一個值,我用它來更新與Crystal Report關聯的參數字段,以便只顯示特定的記錄。打印不顯示打印選項對話框Crystal Report Viewer在我的C#中

這一切都很好,我可以調用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 Viewer來做到這一點?

非常感謝您的幫助。

回答

0

通過從代碼傳遞變量後面CR報表參數:

這可能是是這樣的:

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

請參閱本link更多信息

1

Crystal報表瀏覽器本身不不提供此功能。

要控制沒有對話框彈出的頁面數量,您將不得不使用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是路徑到晶體報告:

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

+0

布蘭登感謝您回覆我的問題。我將Crystal Report與CrystalReportView相關聯的方式是在將CrystalReportView組件拖動到我的窗體後,單擊窗體右上角出現的箭頭,然後使用屬性對話框顯示允許我選擇要使用的外部Crystal Report。 –

+0

嗯,如果您在SetCrystalOrderNumParameter函數中設置斷點,並檢查報表查看器的ReportSource屬性,它是否包含ReportDocument對象?也許你可以從源文件檢索文檔,只需要調用PrintToPrinter? –

+0

我不熟悉使用visual studio designer來設置/顯示水晶報表。對不起,我不能在這方面得到更多的幫助。 –

相關問題