177 lines
7.4 KiB
C#
177 lines
7.4 KiB
C#
using gregn6Lib;
|
||
using System;
|
||
using System.Data;
|
||
|
||
namespace HL_FristAidPlatform_Public
|
||
{
|
||
public class PrintByGridpp
|
||
{
|
||
/// <summary>
|
||
/// 报表
|
||
/// </summary>
|
||
private GridppReport Report = new GridppReport();
|
||
|
||
/// <summary>
|
||
/// 报表数据源
|
||
/// </summary>
|
||
private DataTable ReportDT = new DataTable();
|
||
|
||
private string PDFFileName;
|
||
|
||
#region Grid++ Report报表打印
|
||
|
||
/// <summary>
|
||
/// 打印条形码
|
||
/// </summary>
|
||
/// <param name="_barCodeDT">条形码数据源</param>
|
||
/// <param name="_printerName">打印机名称</param>
|
||
/// <param name="_rptName">报表文件名称</param>
|
||
/// <param name="_isPreview">是否直接打印</param>
|
||
public string PrintReport(DataTable _barCodeDT, string _printerName, string _rptName, bool _isPreview)
|
||
{
|
||
string returnmsg = "";
|
||
if (_barCodeDT.Rows.Count > 0)
|
||
{
|
||
ReportDT = _barCodeDT;
|
||
//载入报表模板文件,必须保证 Grid++Report 的安装目录在‘C:\Program Files\Grid++Report 3’下,
|
||
//关于动态设置报表路径与数据绑定参数请参考其它例子程序
|
||
Report.LoadFromFile(AppDomain.CurrentDomain.BaseDirectory + "report\\" + _rptName);
|
||
//加载数据源
|
||
Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);
|
||
Report.Printer.PrinterName = _printerName;
|
||
if (_isPreview)
|
||
{
|
||
Report.Print(true);
|
||
}
|
||
else
|
||
{
|
||
Report.PrintPreview(false);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
returnmsg = "报表数据源传输错误!";
|
||
}
|
||
return returnmsg;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打印PDF
|
||
/// </summary>
|
||
/// <param name="_barCodeDT"></param>
|
||
/// <param name="fileName"></param>
|
||
/// <param name="_rptName"></param>
|
||
/// <param name="GUID"></param>
|
||
/// <returns></returns>
|
||
public bool PrintReportToPDF(DataTable _barCodeDT, string fileName, string _rptName, string path, string PGUID)
|
||
{
|
||
if (_barCodeDT.Rows.Count > 0)
|
||
{
|
||
PDFFileName = path + fileName;
|
||
//if (System.IO.File.Exists(PDFFileName + ".pdf"))
|
||
//{
|
||
// // Use a try block to catch IOExceptions, to
|
||
// // handle the case of the file already being
|
||
// // opened by another process.
|
||
// try
|
||
// {
|
||
// System.IO.File.Delete(PDFFileName + ".pdf");
|
||
// }
|
||
// catch (System.IO.IOException e)
|
||
// {
|
||
// }
|
||
//}
|
||
ReportDT = _barCodeDT;
|
||
//载入报表模板文件,必须保证 Grid++Report 的安装目录在‘C:\Program Files\Grid++Report 3’下,
|
||
//关于动态设置报表路径与数据绑定参数请参考其它例子程序
|
||
Report.LoadFromFile(AppDomain.CurrentDomain.BaseDirectory + "report\\" + _rptName);
|
||
//Report.ExportBegin += new _IGridppReportEvents_ExportBeginEventHandler(ReportExportBegin);
|
||
//加载数据源
|
||
Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);
|
||
GRExportType ExportType = GRExportType.gretPDF;
|
||
//直接调用ExportDirect方法执行导出任务
|
||
//Report.ExportDirect(ExportType, fileName, false, true);
|
||
//GridReportHelper.FillRecordToReport(Report, ReportDT);
|
||
string FileName = ExportInfo.GetExportFileName(PDFFileName);
|
||
//直接调用ExportDirect方法执行导出任务
|
||
Report.ExportDirect(ExportType, FileName, false, true);
|
||
//PublicClass.UploadFile(FileName, PGUID);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 填充数据源
|
||
/// </summary>
|
||
private void ReportFetchRecord()
|
||
{
|
||
GridppReportUtility.FillRecordToReport(Report, ReportDT);
|
||
}
|
||
|
||
private void ReportExportBegin(IGRExportOption Sender)
|
||
{
|
||
//ExportBegin 事件在将报表导出之前会触发到,无论是调用 ExportDirect 与 Export 方法,
|
||
//还是从打印预览窗口等地方执行导出,都会触发到 ExportBegin 事件。
|
||
//通常在 ExportBegin 事件中设置导出选项参数,改变默认导出行为
|
||
|
||
Sender.AbortOpenFile = true; //导出后不用关联程序打开导出文件,如导出Excel文件之后不用Excel打开
|
||
Sender.AbortShowOptionDlg = true; //导出之前不显示导出选项设置对话框
|
||
|
||
//指定导出文件的完整路径与文件名称
|
||
string FileName = ExportInfo.GetExportFileName(PDFFileName);
|
||
Sender.FileName = FileName; //"d:\\export\\my.dat";
|
||
|
||
//根据导出类型设置其特有的选项参数,有关选项参数的具体信息清参考帮助文档。
|
||
//IGRExportOption是导出选项的基类,其它具体导出选项的接口名称都以IGRE2为前缀
|
||
bool OnlyExportDetailGrid = false;//
|
||
bool SupressEmptyLines = false;//压缩空白行
|
||
switch (Sender.ExportType)
|
||
{
|
||
case GRExportType.gretXLS:
|
||
Sender.AsE2XLSOption.OnlyExportDetailGrid = OnlyExportDetailGrid;
|
||
Sender.AsE2XLSOption.SupressEmptyLines = SupressEmptyLines;
|
||
|
||
Sender.AsE2XLSOption.ExportPageHeaderFooter = false;
|
||
Sender.AsE2XLSOption.SameAsPrint = false;
|
||
Sender.AsE2XLSOption.ExportPageBreak = false;
|
||
break;
|
||
|
||
case GRExportType.gretRTF:
|
||
Sender.AsE2RTFOption.OnlyExportDetailGrid = OnlyExportDetailGrid;
|
||
Sender.AsE2RTFOption.SupressEmptyLines = SupressEmptyLines;
|
||
break;
|
||
|
||
case GRExportType.gretPDF:
|
||
Sender.AsE2PDFOption.Author = "My Author";
|
||
Sender.AsE2PDFOption.Subject = "My Subject";
|
||
break;
|
||
|
||
case GRExportType.gretHTM:
|
||
Sender.AsE2HTMOption.OnlyExportDetailGrid = OnlyExportDetailGrid;
|
||
Sender.AsE2HTMOption.SupressEmptyLines = SupressEmptyLines;
|
||
break;
|
||
|
||
case GRExportType.gretIMG:
|
||
Sender.AsE2IMGOption.DPI = 300;
|
||
Sender.AsE2IMGOption.ImageType = GRExportImageType.greitPNG;
|
||
break;
|
||
|
||
case GRExportType.gretTXT:
|
||
Sender.AsE2TXTOption.OnlyExportDetailGrid = OnlyExportDetailGrid;
|
||
Sender.AsE2TXTOption.SupressEmptyLines = SupressEmptyLines;
|
||
break;
|
||
|
||
default:
|
||
Sender.AsE2CSVOption.OnlyExportDetailGrid = OnlyExportDetailGrid;
|
||
Sender.AsE2CSVOption.SupressEmptyLines = SupressEmptyLines;
|
||
break;
|
||
}
|
||
}
|
||
|
||
#endregion Grid++ Report报表打印
|
||
}
|
||
} |