在VS2010中打印报告 [英] Print Report in VS2010

查看:109
本文介绍了在VS2010中打印报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我在使用VB 2010和报告查看器时遇到了问题。



我有一个表格我在哪里放置了一个链接到报告的报告查看器(Report1.rdlc)

还有一个参数。



我想做的是自动打印报告,以便用户无需按打印机图标。



但是只有在我不使用参数的情况下它才有效(尽管我编译时看起来是正确的)。我得到的错误是在 report.Render(Image,deviceInfo,AddressOf CreateStream,警告)



一个或多个参数需要指定....(或多或少,因为它是西班牙语)



这是代码。希望有人可以提供帮助



我如何通过RENDER方法传递参数?





oscarsaez1975@hotmail.com



Hello!
I'm having an issue with VB 2010 and the report-viewer.

I have a form where I have placed a report viewer linked to a report (Report1.rdlc)
There is also a parameter.

What I want to do is to print automatically the report so the user don't have to press the printer icon.

But it only works if I don't use the parameter (although it appears right when I compile). The error I get is in the "report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)"

ONE OR MORE PARAMETERS NEED TO BE SPECIFIED.... (more or less as it's in spanish)

Here's the code. Hope someone can help

HOW CAN I PASS THERE PARAMETERS TO THE RENDER METHOD??


oscarsaez1975@hotmail.com
"

Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Imports System.IO
Imports System.IO.Stream
Imports System.Data
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports System.Collections.Generic
Imports System.Windows.Forms
Public Class Form1
    Implements IDisposable
    Public m_currentPageIndex As Integer
    Public m_streams As IList(Of Stream)
    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'ContadoresDataSet.Contadores' Puede moverla o quitarla según sea necesario.

        'Dim valor As String
        'valor = "Hola"

        Dim params(1) As Microsoft.Reporting.WinForms.ReportParameter
        params(0) = New Microsoft.Reporting.WinForms.ReportParameter("reportTitle", "Hola")
        params(1) = New Microsoft.Reporting.WinForms.ReportParameter("reportFile", "MAS")
        ReportViewer1.LocalReport.SetParameters(params)
        Me.ReportViewer1.RefreshReport()
    End Sub

    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Run()
    End Sub
    Public Function LoadSalesData() As DataTable
        Dim dataSet As New DataSet()
        dataSet.ReadXml("data.xml")
        Return dataSet.Tables(0)
    End Function

    Public Function CreateStream(ByVal name As String, _
         ByVal fileNameExtension As String, _
              ByVal encoding As Encoding, ByVal mimeType As String, _
                  ByVal willSeek As Boolean) As Stream
        Dim stream As Stream = New FileStream(name + "." + fileNameExtension, FileMode.Create)
        m_streams.Add(stream)
        Return stream
    End Function

    Public Sub Export(ByVal report As LocalReport)
        Dim deviceInfo As String = 
          "<deviceinfo>" + _
          "  <outputformat>EMF</outputformat>" + _
          "  <pagewidth>8.5in</pagewidth>" + _
          "  <pageheight>11in</pageheight>" + _
          "  <margintop>0.25in</margintop>" + _
          "  <marginleft>0.25in</marginleft>" + _
          "  <marginright>0.25in</marginright>" + _
          "  <marginbottom>0.25in</marginbottom>" + _
          "</deviceinfo>"
        Dim warnings() As Warning = Nothing
        m_streams = New List(Of Stream)()
        report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)

        Dim stream As Stream
        For Each stream In m_streams
            stream.Position = 0
        Next
    End Sub

    Public Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
        ev.Graphics.DrawImage(pageImage, ev.PageBounds)

        m_currentPageIndex += 1
        ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
    End Sub

    Public Sub Print()
        Const printerName As String = "\\Printserver\RICOH Aficio MPC2500_MAT"

        If m_streams Is Nothing Or m_streams.Count = 0 Then
            Return
        End If

        Dim printDoc As New PrintDocument()
        printDoc.PrinterSettings.PrinterName = printerName
        If Not printDoc.PrinterSettings.IsValid Then
            Dim msg As String = String.Format("Can't find printer ""{0}"".", printerName)
            Debug.WriteLine(msg)
            Return
        End If
        AddHandler printDoc.PrintPage, AddressOf PrintPage
        printDoc.Print()
    End Sub

    Public Sub Run()
        Dim report As LocalReport = New LocalReport()
        report.ReportPath = "Report1.rdlc"
        report.DataSources.Add(New ReportDataSource("Sales", LoadSalesData()))
        report.GetParameters()

        Export(report)
        m_currentPageIndex = 0
        Print()
    End Sub

    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        If Not (m_streams Is Nothing) Then
            Dim stream As Stream
            For Each stream In m_streams
                stream.Close()
            Next
            m_streams = Nothing
        End If
    End Sub

End Class




"

推荐答案

这篇关于在VS2010中打印报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆