水晶报表打印

水晶报表打印问题:

ReportDocument aReportDocument = new ReportDocument();

//加载报表

 aReportDocument.Load(@Application.StartupPath + Properties.Settings.Default.MainReportPath);

//子报表数据源

aReportDocument.Subreports["SonRpt.rpt"].SetDataSource(sonDs);

//传递参数

 aReportDocument.SetParameterValue("Name", Class.Name);

//登录

foreach (Table aTable in aReportDocument.Database.Tables)
{
 aTable.LogOnInfo.ConnectionInfo.ServerName = Properties.Settings.Default.ServerName;
 aTable.LogOnInfo.ConnectionInfo.UserID = Properties.Settings.Default.UserID;
 aTable.LogOnInfo.ConnectionInfo.Password = Properties.Settings.Default.Password

 aTable.ApplyLogOnInfo(aTable.LogOnInfo);

}

//指定系统默认打印机位报表打印机

 PrintDocument printDc = new PrintDocument();
 aReportDocument.PrintOptions.PrinterName = printDc.PrinterSettings.PrinterName;

//如果没有上面两句,默认打印机是在水晶报表中指定的
 aReportDocument.PrintToPrinter(1, true, 0, 0);
 aReportDocument.Dispose();

posted @ 2014-11-20 18:56  stoneFang  阅读(126)  评论(0编辑  收藏  举报