2013-10-31 1 views
1

내 rdlc 보고서에 문제가 있습니다. 인쇄를 시작하면 예외가 발생했습니다. 나는 그것의 유형이 무엇인지 모르지만 나는 스택 추적을 가지고있다. 보고서에rdlc 파일 인쇄 중에 예외가 발생했습니다

enter image description here

경로가 정확한지 확인하십시오.

다음
ThreadPool.QueueUserWorkItem(o => 
     { 
      var patientReportPresenter = PatientReportPresenter.Convert(patient); 
      using (var demo = new PrintComponent(patientReportPresenter, applicationSettings.PrinterName, "DataSet1", false)) 
      { 
       try 
       { 
        string exeFolder = Path.GetDirectoryName(Application.ExecutablePath); 
        string reportPath = Path.Combine(exeFolder, @"Template\Report1.rdlc"); 

        var report = new LocalReport 
        { 
         ReportPath = reportPath 
        }; 
        demo.Run(report); 
       } 
       catch (Exception ex) 
       { 
        string exeFolder = Path.GetDirectoryName(Application.ExecutablePath); 
        string reportPath = Path.Combine(exeFolder, @"Template\Report1.rdlc"); 

        MessageBox.Show(
         ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + reportPath, 
         @"Print error", MessageBoxButtons.OK, 
         MessageBoxIcon.Error); 
        return; 
       } 
      } 
     }, null); 

내 인쇄 클래스는 다음과 같습니다 :

public class PrintComponent : IDisposable 
{ 
    private readonly string _printerName; 
    private int m_currentPageIndex; 
    private IList<Stream> m_streams; 
    private readonly string _dataSetName; 
    private bool _landscape; 
    private PatientReportPresenter _patientReportPresenter; 

    public PrintComponent(PatientReportPresenter patientReportPresenter, string printerName, string dataSetName, bool landscape) 
    { 
     _patientReportPresenter = patientReportPresenter; 
     _printerName = printerName; 
     _dataSetName = dataSetName; 
     _landscape = landscape; 
    } 

    private DataTable LoadSalesData() 
    { 
     var table = new DataTable(); 


     table.Columns.Add("Address", typeof(string)); 
     //... 

     table.Rows.Add(_patientReportPresenter.Address, ...); 

     return table; 
    } 

    private Stream CreateStream(string name, 
           string fileNameExtension, Encoding encoding, 
           string mimeType, bool willSeek) 
    { 
     Stream stream = new MemoryStream(); 
     m_streams.Add(stream); 
     return stream; 
    } 

    private void Export(LocalReport report) 
    { 
     string deviceInfo; 

     if (_landscape) 
     { 
      deviceInfo = 
       @"<DeviceInfo> 
      <OutputFormat>EMF</OutputFormat> 
      <PageWidth>11.7in</PageWidth> 
      <PageHeight>8.3in</PageHeight> 
      <MarginTop>0in</MarginTop> 
      <MarginLeft>0in</MarginLeft> 
      <MarginRight>0in</MarginRight> 
      <MarginBottom>0in</MarginBottom> 
     </DeviceInfo>"; 
     } 
     else 
     { 
      deviceInfo = 
      @"<DeviceInfo> 
          <OutputFormat>EMF</OutputFormat> 
          <PageWidth>8.3in</PageWidth> 
          <PageHeight>11.7in</PageHeight> 
          <MarginTop>0.3in</MarginTop> 
          <MarginLeft>0in</MarginLeft> 
          <MarginRight>0in</MarginRight> 
          <MarginBottom>0in</MarginBottom> 
         </DeviceInfo>"; 
     } 
     m_streams = new List<Stream>(); 

     Warning[] warnings; 
     report.Render("Image", deviceInfo, CreateStream, out warnings); 

     foreach (Stream stream in m_streams) 
      stream.Position = 0; 
    } 

    private void PrintPage(object sender, PrintPageEventArgs ev) 
    { 
     var pageImage = new 
      Metafile(m_streams[m_currentPageIndex]); 

     var adjustedRect = new Rectangle(
      ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX, 
      ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY, 
      ev.PageBounds.Width, 
      ev.PageBounds.Height); 

     ev.Graphics.FillRectangle(Brushes.White, adjustedRect); 
     ev.Graphics.DrawImage(pageImage, adjustedRect); 
    } 

    private void Print() 
    { 
     if (m_streams == null || m_streams.Count == 0) 
      throw new Exception("Error: no stream to print."); 
     var printDoc = new PrintDocument {PrinterSettings = {PrinterName = _printerName}}; 
     if (_landscape) 
     { 
      printDoc.DefaultPageSettings.Landscape = true; 
     } 
     printDoc.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); 
     if (!printDoc.PrinterSettings.IsValid) 
     { 
      throw new Exception("Error: cannot find the default printer."); 
     } 

     printDoc.PrintPage += PrintPage; 
     m_currentPageIndex = 0; 
     printDoc.Print(); 
    } 

    public void Run(LocalReport report) 
    { 
     report.DataSources.Add(new ReportDataSource(_dataSetName, LoadSalesData())); 
     Export(report); 
     Print(); 
    } 

    public void Dispose() 
    { 
     if (m_streams != null) 
     { 
      foreach (Stream stream in m_streams) 
       stream.Close(); 
      m_streams = null; 
     } 
    } 
} 

내가 잘못 어떻게해야합니까 여기

내 코드?

답변