C# RDLC报表不出现预览窗体直接输出到打印机
#region 直接打印区域
/// <summary>
/// 直接打印到打印机
/// </summary>
/// <param name="reportFullFileName"></param>
/// <param name="reportTitle"></param>
/// <param name="reportDSTable1"></param>
/// <param name="reportDSTable2"></param>
/// <param name="reportDSTable3"></param>
/// <param name="reportDSTable4"></param>
/// <param name="reportDSTable5"></param>
/// <param name="hasSubReport"></param>
/// <param name="subReportDSTable1"></param>
/// <param name="subReportDSTable2"></param>
/// <param name="tPageSettings"></param>
/// <param name="tPrinterSettings"></param>
/// <param name="logoFileName1"></param>
/// <param name="logoFileName2"></param>
/// <param name="logoFileName3"></param>
public void PrintReportDrc(string reportFullFileName, string reportTitle, DataTable reportDSTable1,
DataTable reportDSTable2 = null, DataTable reportDSTable3 = null, DataTable reportDSTable4 = null,
DataTable reportDSTable5 = null, bool hasSubReport = false, DataTable subReportDSTable1 = null,
DataTable subReportDSTable2 = null, System.Drawing.Printing.PageSettings tPageSettings = null, System.Drawing.Printing.PrinterSettings tPrinterSettings = null, string logoFileName1 = null, string logoFileName2 = null, string logoFileName3 = null)
{
if (!File.Exists(reportFullFileName))
{
MyMsg.Error("T.1201/指定的报表文件不存在,请检查!");
this.Close();
return;
}
this.Text += "(" + reportTitle + ")"; this.RptvMain.Reset();
this.RptvMain.ProcessingMode = ProcessingMode.Local;
this.RptvMain.LocalReport.ReportPath = reportFullFileName;//必须在前面,否则出现The source of the report definition has not been specified错误
this.RptvMain.LocalReport.EnableExternalImages = true; // RDLC报表显示本地图片必须设置(默认是关闭) #region 处理参数
ReportParameterInfoCollection reportParameterInfos = RptvMain.LocalReport.GetParameters();
List<string> parasNames = new List<string>();
foreach (ReportParameterInfo rpi in reportParameterInfos)
{
parasNames.Add(rpi.Name);
} List<ReportParameter> reportParameters = new List<ReportParameter>();
if (parasNames.Contains("LogoFile1"))
{
if (string.IsNullOrEmpty(logoFileName1))
{
logoFileName1 = "RptLogoDft1.jpg";
}
logoFileName1 = AppInfo.GetPath(AppInfo.AppPath.Report) + @"\Images\" + logoFileName1;
logoFileName1 = @"file:///" + logoFileName1.Replace(@"\", @"/");
ReportParameter reportParameter = new ReportParameter("LogoFile1", logoFileName1);
reportParameters.Add(reportParameter);
}
if (parasNames.Contains("LogoFile2"))
{
if (string.IsNullOrEmpty(logoFileName2))
{
logoFileName2 = "RptLogoDft2.jpg";
}
logoFileName2 = AppInfo.GetPath(AppInfo.AppPath.Report) + @"\Images\" + logoFileName2;
logoFileName2 = @"file:///" + logoFileName2.Replace(@"\", @"/");
ReportParameter reportParameter = new ReportParameter("LogoFile2", logoFileName2);
reportParameters.Add(reportParameter);
}
if (parasNames.Contains("LogoFile3"))
{
if (string.IsNullOrEmpty(logoFileName3))
{
logoFileName3 = "RptLogoDft3.jpg";
}
logoFileName3 = AppInfo.GetPath(AppInfo.AppPath.Report) + @"\Images\" + logoFileName3;
logoFileName3 = @"file:///" + logoFileName3.Replace(@"\", @"/");
ReportParameter reportParameter = new ReportParameter("LogoFile3", logoFileName3);
reportParameters.Add(reportParameter);
}
if (reportParameters.Count > )
{
this.RptvMain.LocalReport.SetParameters(reportParameters);
}
#endregion #region 处理Dataset
this.RptvMain.LocalReport.DataSources.Clear();
if (reportDSTable1 != null)
{
ReportDataSource rds1 = new ReportDataSource("DataSet1", reportDSTable1);
this.RptvMain.LocalReport.DataSources.Add(rds1);
}
if (reportDSTable2 != null)
{
ReportDataSource rds2 = new ReportDataSource("DataSet2", reportDSTable2);
this.RptvMain.LocalReport.DataSources.Add(rds2);
}
if (reportDSTable3 != null)
{
ReportDataSource rds3 = new ReportDataSource("DataSet3", reportDSTable3);
this.RptvMain.LocalReport.DataSources.Add(rds3);
}
if (reportDSTable4 != null)
{
ReportDataSource rds4 = new ReportDataSource("DataSet4", reportDSTable4);
this.RptvMain.LocalReport.DataSources.Add(rds4);
}
if (reportDSTable5 != null)
{
ReportDataSource rds5 = new ReportDataSource("DataSet5", reportDSTable5);
this.RptvMain.LocalReport.DataSources.Add(rds5);
} #endregion //定义子报表处理方法
if (hasSubReport)
{
subDSTable1 = subReportDSTable1;
subDSTable2 = subReportDSTable2;
RptvMain.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
} RptvMain.SetDisplayMode(DisplayMode.PrintLayout);
RptvMain.ZoomMode = ZoomMode.Percent;
RptvMain.ZoomPercent = ;
try
{
if (tPageSettings != null) RptvMain.SetPageSettings(tPageSettings);
if (tPrinterSettings != null) RptvMain.PrinterSettings = tPrinterSettings;
}
catch (Exception)
{ }
RptvMain.LocalReport.Refresh();
RptvMain.RefreshReport(); #region 直接打印定义
m_streams = new List<Stream>();
ReportPageSettings pageSettings = RptvMain.LocalReport.GetDefaultPageSettings(); decimal pgWidth = decimal.Round(HpString.NZ2Decimal(pageSettings.PaperSize.Width * 2.54 / ), );
decimal pgHeight = decimal.Round(HpString.NZ2Decimal(pageSettings.PaperSize.Height * 2.54 / ), );
decimal mgTop = decimal.Round(HpString.NZ2Decimal(pageSettings.Margins.Top * 2.54 / ), );
decimal mgLeft = decimal.Round(HpString.NZ2Decimal(pageSettings.Margins.Left * 2.54 / ), );
decimal mgRight = decimal.Round(HpString.NZ2Decimal(pageSettings.Margins.Right * 2.54 / ), );
decimal mgBottom = decimal.Round(HpString.NZ2Decimal(pageSettings.Margins.Bottom * 2.54 / ), ); string deviceInfo = "<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>"+ pgWidth + "cm</PageWidth>" +
" <PageHeight>" + pgHeight + "cm</PageHeight>" +
" <MarginTop>" + mgTop + "cm</MarginTop>" +
" <MarginLeft>" + mgLeft + "cm</MarginLeft>" +
" <MarginRight>" + mgRight + "cm</MarginRight>" +
" <MarginBottom>" + mgBottom + "cm</MarginBottom>" +
"</DeviceInfo>";
RptvMain.LocalReport.Render("Image", deviceInfo, CreateStream, out Warning[] warnings);
//==================================================开始打印
m_currentPageIndex = ;
if (m_streams == null || m_streams.Count == )
return;
//声明PrintDocument对象用于数据的打印
PrintDocument printDoc = new PrintDocument
{
DefaultPageSettings = RptvMain.GetPageSettings()
};
//如果没有指定打印机设置,则使用空字符串""来指定默认打印机
if (RptvMain.PrinterSettings == null)
{
printDoc.PrinterSettings.PrinterName = "";
}
else
{
printDoc.PrinterSettings = RptvMain.PrinterSettings;
}
//判断指定的打印机是否可用
if (!printDoc.PrinterSettings.IsValid)
{
MyMsg.Warning("没有找到指定的打印机:" + printDoc.PrinterSettings.PrinterName);
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
//执行打印操作,Print方法将触发PrintPage事件。
printDoc.Print(); //释放资源
foreach (Stream stream in m_streams)
{
stream.Dispose();
stream.Close();
}
m_streams = null;
#endregion
} //声明一个Stream对象的列表用来保存报表的输出数据
//LocalReport对象的Render方法会将报表按页输出为多个Stream对象。
private List<Stream> m_streams;
//用来提供Stream对象的函数,用于LocalReport对象的Render方法的第三个参数。
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) {
//如果需要将报表输出的数据保存为文件,请使用FileStream对象。
Stream stream = new MemoryStream();
m_streams.Add(stream);
return stream;
} //用来记录当前打印到第几页了
private int m_currentPageIndex; #region 打印页面
private void PrintPage(object sender, PrintPageEventArgs ev)
{
m_streams[m_currentPageIndex].Position = ;
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]); System.Drawing.Rectangle adjustedRect = new System.Drawing.Rectangle(
ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX,
ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY, ev.PageBounds.Width, ev.PageBounds.Height); ev.Graphics.FillRectangle(System.Drawing.Brushes.White, adjustedRect); ev.Graphics.DrawImage(pageImage, adjustedRect); m_streams[m_currentPageIndex].Close();
m_currentPageIndex++; ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
#endregion
#endregion
C# RDLC报表不出现预览窗体直接输出到打印机的更多相关文章
- FastReport合并多份报表为一份预览打印
效果 比较简单,直接贴代码 //打印第一份报表 procedure TForm1.Button2Click(Sender: TObject); begin frxReport1.LoadFromFil ...
- C# WinForm RDLC报表不预览直接连续打印
用微软的RDLC报表直接打印不预览 直接上代码. //打印清单 System.Data.DataTable dt = print_QD(dr); ReportViewer rvDoc = new Re ...
- 根据 Power BI Desktop(预览版)中的报表页创建工具提示
根据 Power BI Desktop 中创建的报表页,可创建直观丰富的报表工具提示,这些提示在你将鼠标悬停在视觉对象上时显示. 通过创建用作工具提示的报表页,使自定义工具提示包含视觉对象.图像以及在 ...
- 通过程序预览Office文档
我承认,标题是夸大了,就是为了吸引注意力.这里只有Word文档和Excel文档的预览代码. Word://此部分来源:http://princed.mblogger.cn/posts/11885.as ...
- 关闭rdlc报表打印预览后,关闭客户端,抛出异常“发生了应用程序级的异常 将退出”
问题:关闭rdlc报表打印预览后,关闭客户端,抛出异常“发生了应用程序级的异常 将退出” 办法:在容纳ReportViewer的窗体后台代码中,添加如下代码即可 protected override ...
- RDLC 图形报表预览时 “本地报表处理期间错误”
在RDLC报表中有图形报表的导出和打印都正常,但预览时"本地报表处理期间错误",这是因为你设置的图形太宽已经超过默认的A4 纸的宽度,解决办法:报表页面的报表--->报表属性 ...
- rdlc报表的导出及预览时表头
感谢各路大神的博客,总结rdlc报表中目前用到的知识,积累. 一.rdlc报表PDF打印出现空白页 1.先至Report.rdlc報表設計的頁面,選擇功能表上的[報表]->[報表屬性],在[配置 ...
- Dynamics AX 2012 R2 SSRS报表在VS2010中预览没有数据
今天,Reinhard 在VS中制作SSRS报表,预览的时候发现显示不出数据. 仔细检查了数据处理环节和临时表里的数据,都发现没有问题. 用同事的账号登陆同样的开发环境,发现他的账号可以在VS中预览到 ...
- RM报表预览,只有固定的1个订单页面
明明选了多个记录,预览时,只显示最后一个. 原因: 主项数据的数据集选了报表自带的虚拟数据集了.
随机推荐
- 归纳整理Linux下C语言常用的库函数----内存及字符串控制及操作
在没有IDE的时候,记住一些常用的库函数的函数名.参数.基本用法及注意事项是很有必要的. 参照Linux_C_HS.chm的目录,我大致将常用的函数分为一下几类: 1. 内存及字符串控制及操作 2. ...
- svg make a face
1.创建项目 #使用simple模板 vue init webpack-simple vue-svg #安装依赖 cd vue-svg/ npm i #安装d3 npm i d3 --save 2.代 ...
- FP昨天的新单,今天交期回写到2020年
昨天新单6900000053,回写交期到2020年.在此视图查看此单回写的日期V_OUT_SHIPMENT_PLAN_TESTS,可看到日期是2020年. 1.检查OUT_SHIPMENT_PLAN表 ...
- ROS 消息发布器和订阅器Publisher, Subscriber
博客参考:https://www.2cto.com/kf/201705/639776.html 1.编写发布器节点节点(Node) 是指 ROS 网络中可执行文件.接下来,将会创建一个发布器节点(“t ...
- [Java] Java API文档下载方法
Java API文档下载方法:http://jingyan.baidu.com/article/a3aad71ac9e48fb1fb009692.html Oracle : http://www.or ...
- 回答了这四个问题,你就可以打造最佳App首页
如果把手机APP比作人的话,首页就是脸面了.首页是一款产品的大门,好的开头就是成功的一半. 调查表示,26%的手机APP的平均使用次数只有一次.对首次使用产品的用户而言,首页的好坏关乎到用户对该产品的 ...
- TabHost tab项单击事件
TabHost 选项发生变化时会触发OnTabChangedListener事件,但是如果当前已经选中第一项,再次单击该项时,OnTabChangedListener不会触发该事件,所以再次单击选中t ...
- docker-compose up启动又停止,需要加tty为true
如果docker-compose.yml如下,则用docker-compose up -d启动起来的容器可能会立即停止. version: '2' services: mir-http-repo: i ...
- mysql的.sql文件头部 /*!32312 IF NOT EXISTS*/;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RE ...
- mfc的一点总结-----Edit Control操作
获取Edit Control(编辑框)的内容: CString key; GetDlgItem(IDC_EDIT1)->GetWindowText(key); 其中IDC_EDIT1是所要获取编 ...