2016-03-03 29 views
0

我在做計費應用程序,因此我需要在沒有預覽報告的情況下打印帳單。而且,我不喜歡在打印機對話框中選擇打印機。它應該選擇默認打印機。如何在Windows應用程序中使用C#顯示預覽和打印機選擇而無需顯示預覽和打印機選擇

'PrintToPrinter'不適合我的要求。我需要發送最新創建的BillID作爲參數以獲取最新的細節。

如果我不使用'PrintToPrinter'語法,打印機對話框彈出屏幕將隨「選擇打印機」對話框提供。

請指導我解決這個問題。

供您參考,我附上一個片段我的代碼:

Report_Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\Reports\\StandardBill.rpt";       
ReportDocument rd = new ReportDocument(); 
rd.Load(Report_Path); 
rd.SetDatabaseLogon(AccessingData.DBUserName, AccessingData.DBPassword); 
ParameterFields paramFields = new ParameterFields(); 
ParameterField BillID = new ParameterField(); 
ParameterDiscreteValue discreteVal_BillID = new ParameterDiscreteValue(); 
BillID.ParameterFieldName = "BillNo"; 

discreteVal_BillID.Value = Convert.ToInt32(Bill_id); 
BillID.CurrentValues.Add(discreteVal_BillID); 

ParameterField CType = new ParameterField(); 
ParameterDiscreteValue discreteVal_CType = new ParameterDiscreteValue(); 
CType.ParameterFieldName = "ClientType"; 

discreteVal_CType.Value = ClientType; 
CType.CurrentValues.Add(discreteVal_CType); 

// Add parameter to the parameter fields collection. 
paramFields.Add(BillID); 
paramFields.Add(CType); 
CRViewer1.ParameterFieldInfo = paramFields; 

CRViewer1.ReportSource = rd;       

CRViewer1.PrintReport(); 
rd.Close(); 
rd.Dispose(); 

回答

0

你可以用這個

   Dim crtableLogoninfos As New TableLogOnInfos 
       Dim crtableLogoninfo As New TableLogOnInfo 
       Dim crConnectionInfo As New ConnectionInfo 
       Dim CrTables As Tables 
       Dim CrTable As Table 
       Dim cryRpt As New ReportDocument 
       cryRpt.Load("report path") 
       With crConnectionInfo 
        .ServerName = "servername" 
        .DatabaseName = "databasename" 
        .UserID = "userid" 
        .Password = "password" 
        .IntegratedSecurity = False 

       End With 
       CrTables = cryRpt.Database.Tables 
       For Each CrTable In CrTables 
        crtableLogoninfo = CrTable.LogOnInfo 
        crtableLogoninfo.ConnectionInfo = crConnectionInfo 
        CrTable.ApplyLogOnInfo(crtableLogoninfo) 
       Next 
       cryRpt.SetDatabaseLogon("userid", crConnectionInfo.Password, crConnectionInfo.ServerName, crConnectionInfo.DatabaseName, crConnectionInfo.IntegratedSecurity) 

       Dim crParameterFieldDefinitions As ParameterFieldDefinitions 
       Dim crParameterFieldDefinition As ParameterFieldDefinition 
       Dim crParameterValues As New ParameterValues 
       Dim crParameterDiscreteValue As New ParameterDiscreteValue 

       crParameterDiscreteValue.Value = BillID 
       crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields 
       crParameterFieldDefinition = crParameterFieldDefinitions.Item("BillID") 
       crParameterValues = crParameterFieldDefinition.CurrentValues 
       crParameterValues.Add(crParameterDiscreteValue) 
       crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) 
       crParameterValues.Clear() 

       cryRpt.PrintOptions.PrinterName = "printername" 
       cryRpt.PrintToPrinter(1, False, 0, 0) 


      End If 

嘗試我想這應該做的伎倆。雖然在VB中。