0
我正在开发一个WPF(VB)项目,我需要将现有的水晶报告链接到WPF应用程序。用户将从我的WPF应用程序中输入工作号码;之后,我需要运行查询(从JobHeader选择*,其中Jobnumber = @ userjobnumber);然后我需要调用水晶报告,该报告将包含该JobNumber的所有详细信息。如何在WPF中集成Crystal Reports?
此外,我有一个示例WPF应用程序准备从哪里用户将输入jobnumber。我也准备好了水晶报告。用WPF集成水晶报告。有人可以帮助我吗?长期困扰这个问题并接近最后期限。请帮忙。
感谢
这里是我的VBCode:
Imports System.Globalization
Imports System.Drawing.Printing
Imports System.Drawing
Imports System.Data
Imports System.Data.SqlClient
Class MainWindow
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
AddHandler printDocument1.PrintPage, AddressOf printDocument1_PrintPage
End Sub
'Declaration the global variables
Private paperSize As New PaperSize("papersize", 300, 500)
'set the paper size
Private totalnumber As Integer = 0
'this is for total number of items of the list or array
Private itemperpage As Integer = 0
'this is for no of item per page
Private printDocument1 As New PrintDocument()
Private printDialog1 As New System.Windows.Forms.PrintDialog()
Private DefaultFont As New Font("Calibri", 20)
Public StrConn As String = "Data Source=it- 12\localAv01;Database=AvTest01;Uid=sa;Pwd=test123"
Dim QueryStr = "Select * from JobHeader where JobNumber="
Dim ConnStr = StrConnAvanti
Dim dTable As DataTable = New DataTable()
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
If txtStart.Text.Trim.Length > 0 Then
itemperpage = 1
totalnumber = txtStart.Text.Replace("J", "")
printDialog1.Document = printDocument1
printDocument1.DefaultPageSettings.PaperSize = paperSize
printDialog1.ShowDialog()
'printDocument1.PrinterSettings.PrinterName = "";
printDocument1.Print()
Else
MessageBox.Show("Invalid number")
End If
End Sub
Private Function CheckNumber(str As String)
Dim Num As Double
Return Double.TryParse(str, Num)
End Function
Private Sub printDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)
Dim currentY As Single = 10
While totalnumber <= txtStart.Text.Replace("J", "")
' check the number of items
e.Graphics.DrawString("J" + totalnumber.ToString("000000", CultureInfo.InvariantCulture), DefaultFont, System.Drawing.Brushes.Black, 50, currentY)
'print each item
currentY += 20
' set a gap between every item
totalnumber += 1
'increment count by 1
If itemperpage < 1 Then
' check whether the number of item(per page) is more than 1 or not
itemperpage += 1
' increment itemperpage by 1
' set the HasMorePages property to false , so that no other page will not be added
e.HasMorePages = False
Else
' if the number of item(per page) is more than 1 then add one page
itemperpage = 1
'initiate itemperpage to 0 .
If totalnumber <= Convert.ToInt32(txtStart.Text.Replace("J", "")) Then
e.HasMorePages = True
End If
'e.HasMorePages raised the PrintPage event once per page .
'It will call PrintPage event again
Return
End If
End While
End Sub
End Class
如果报告的名称中包含BillingSummary,则不必执行检查的部分,但我将其作为如何将参数传递给报告的示例(因此可以摆脱标准ameter窗口水晶用途等) – 2014-09-30 20:32:19
对不起也忘了我的构造函数中的Report(报告)只是一个包含文件路径的对象,这就是你真正需要的。我的报告对象还包含一个视图名称以及FileInfo。 – 2014-09-30 20:43:30
此ReportViewer窗口将允许报告呈现,导出(即Excel等)并自行打印。 – 2014-09-30 21:14:08