WinForm+VS2005下ReportViewer的自动打印原码

2020-02-20 23:23

WinForm+VS2005下ReportViewer的自动打印原码

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;

using System.Windows.Forms; using ControlLib;

using System.Drawing.Printing;

using Microsoft.Reporting.WinForms; using System.IO;

using System.Drawing.Imaging;

namespace ReportLib {

public partial class CrystalForm : Form {

private string _reportname = \; private DataSet _datasource = null; private string _autoprint = \; private IList m_streams; private int m_currentPageIndex;

public CrystalForm(string reportname,DataSet datasource,string p1) {

_reportname = reportname; _datasource = datasource; _autoprint = p1;

InitializeComponent(); }

private void CrystalForm_Load(object sender, EventArgs e) {

this.reportViewer1.LocalReport.ReportEmbeddedResource = _reportname; this.reportViewer1.LocalReport.DataSources.Clear(); if (_datasource != null) {

foreach (DataTable table in _datasource.Tables) {

this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource(table.TableName, table));

} }

this.reportViewer1.RefreshReport(); if(_autoprint==\) {

PPrint(); } }

#region 报表自打印 public void PPrint() {

try {

LocalReport report = this.reportViewer1.LocalReport; Export(report);

m_currentPageIndex = 0; NBPrint();

if (m_streams != null) {

foreach (Stream stream in m_streams) stream.Close(); m_streams = null; } }

catch (Exception ex) {

MessageBox.Show(\在打印过程中出现异常! \ + ex.Message.ToString()); } }

private void Export(LocalReport report) {

//7.5in 3.66in 0 0 0 0 当前设置为A4纵向 string deviceInfo = \ +

\ EMF\ + \ 20.7cm\ + \ 28cm\ + \ 0in\ + \ 0in\ + \ 0in\ + \ 0in\ + \; Warning[] warnings;

m_streams = new List();

report.Render(\, deviceInfo, CreateStream, out warnings);

foreach (Stream stream in m_streams) {

stream.Position = 0; } }

private void NBPrint() {

if (m_streams == null || m_streams.Count == 0) return;

PrintDocument printDoc = new PrintDocument();

if (!printDoc.PrinterSettings.IsValid) {

string msg = String.Format(\, \默认打印机!\); MessageBox.Show(msg, \找不到默认打印机\); return; }

printDoc.PrintPage += new PrintPageEventHandler(PrintPage); printDoc.Print(); this.Close(); }

private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) {

string filenameext = DateTime.Now.Year.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); Stream stream = new FileStream(name + \ + fileNameExtension, FileMode.Create); m_streams.Add(stream); return stream; }

private void PrintPage(object sender, PrintPageEventArgs ev) {

Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]); ev.Graphics.DrawImage(pageImage, ev.PageBounds); m_currentPageIndex++;

ev.HasMorePages = (m_currentPageIndex < m_streams.Count); }

#endregion } }

ReportViewer显示 rdlc报表,对应一个dataset.Xsd接受数据集的对应表。 打印部分参考http://blog.csdn.net/jbdren/archive/2010/05/05/5558288.aspx


WinForm+VS2005下ReportViewer的自动打印原码.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:用于干混砂浆的VAE可再分散乳胶粉的研制

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: