8a4dc54520
SVN-Revision: r1236
182 lines
6.9 KiB
C#
182 lines
6.9 KiB
C#
/******************************
|
|
* 说明:表格常规打印
|
|
* 创建人:龚宇超
|
|
* 创建日期:2017-11-10
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using DevExpress.XtraPrinting;
|
|
using DevExpress.XtraGrid;
|
|
using DevExpress.XtraReports.UI;
|
|
using System.Data;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Util;
|
|
using DevExpress.LookAndFeel;
|
|
using DevExpress.XtraReports.UserDesigner;
|
|
using Lskj.Model;
|
|
using Lskj.Data;
|
|
using System.IO;
|
|
using FastReport;
|
|
using FastReport.Preview;
|
|
using System.Windows.Forms;
|
|
using System.Threading.Tasks;
|
|
using Lskj.Business;
|
|
|
|
namespace Lskj.Control.Model
|
|
{
|
|
/// <summary>
|
|
/// 表格常规打印
|
|
/// </summary>
|
|
public class PrintUtil
|
|
{
|
|
/// <summary>
|
|
/// 打印模版后缀
|
|
/// </summary>
|
|
public static string TemplateFlag = ".frx";
|
|
/// <summary>
|
|
/// 打印完成后事件
|
|
/// </summary>
|
|
public static EventHandler OnAfterPrint;
|
|
|
|
public static void Print(GridControl gridControl)
|
|
{
|
|
try
|
|
{
|
|
PrintingSystem ps = null;
|
|
DevExpress.XtraPrinting.PrintableComponentLink link = null;
|
|
ps = new DevExpress.XtraPrinting.PrintingSystem();
|
|
link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
|
|
ps.Links.Add(link);
|
|
link.Component = gridControl;//这里可以是可打印的部件
|
|
string _PrintHeader = "打印数据信息";
|
|
PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;
|
|
phf.Header.Content.Clear();
|
|
phf.Header.Content.AddRange(new string[] { "", _PrintHeader, "" });
|
|
phf.Header.Font = new System.Drawing.Font("宋体", 14, System.Drawing.FontStyle.Bold);
|
|
phf.Header.LineAlignment = BrickAlignment.Center;
|
|
link.CreateDocument(); //建立文档
|
|
ps.PreviewFormEx.Show();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//MessageUtil.Show(ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:模版打印</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-06-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sqls">The SQLS.</param>
|
|
/// <param name="printFile">The print file.</param>
|
|
/// <param name="isPrint">The print file.</param>
|
|
/// <param name="printName">The print file.</param>
|
|
public static void FastReportPrint(List<string> sqls, string printFile, bool isPrint, string printerName = "", List<Task<DataTable>> dataTableTasks = null)
|
|
{
|
|
Report report = new Report();
|
|
FrmFastReportDesign design = new FrmFastReportDesign();
|
|
|
|
try
|
|
{
|
|
WaitForm.ShowForm(ResourceKeys.Handing);
|
|
FastReport.Utils.Res.LoadLocale(PubUtil.PrintModeResourcePath);
|
|
string path = PubUtil.PrintModePath + printFile;
|
|
|
|
if (File.Exists(path) && !string.IsNullOrEmpty(printFile))
|
|
report.Load(path);
|
|
|
|
design.Text = Path.GetFileName(printFile);
|
|
design.ReportObj = report;
|
|
if (dataTableTasks != null && dataTableTasks.Count > 0)
|
|
{
|
|
design.SetDataSource(dataTableTasks);
|
|
}
|
|
else
|
|
{
|
|
design.SetDataSource(sqls.ToArray());
|
|
}
|
|
if (isPrint && printerName != null)
|
|
{
|
|
design.ReportObj.PrintSettings.Printer = printerName;
|
|
design.ReportObj.PrintSettings.ShowDialog = false;
|
|
design.ReportObj.Print();
|
|
if (OnAfterPrint != null)
|
|
OnAfterPrint(null, null);
|
|
}
|
|
else if (ERPInfo.Instance.IsUserManager|| SystemInfo.Instance.PrintTemplate.Split(',').Contains(ERPInfo.Instance.UserName))
|
|
{
|
|
using (BaseForm form = new BaseForm())
|
|
{
|
|
form.Text = "打印程序";
|
|
form.IsMdiContainer = true;
|
|
form.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
|
|
|
design.ReportObj.Prepare();
|
|
design.ReportObj.Design(form);
|
|
design.ReportObj.Designer.BorderStyle = BorderStyle.None;
|
|
design.ReportObj.Designer.cmdPreview.CustomAction += OnCustomAction;
|
|
|
|
form.ShowDialog();
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
using (BaseForm form = new BaseForm())
|
|
{
|
|
form.Text = "打印程序";
|
|
form.IsMdiContainer = true;
|
|
form.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
|
design.ReportObj.Prepare();
|
|
design.ReportObj.ShowPrepared(form);
|
|
design.ReportObj.Preview.OnPrint += Preview_OnPrint;
|
|
design.ReportObj.Preview.ParentForm.WindowState = FormWindowState.Maximized;
|
|
form.ShowDialog();
|
|
|
|
}
|
|
}
|
|
WaitForm.HideForm();
|
|
//design.ShowDialog();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//MessageUtil.Show(ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
design.ReportObj.Design();
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static void OnCustomAction(object sender, EventArgs e)
|
|
{
|
|
FastReport.Design.StandardDesigner.DesignerControl design = sender as FastReport.Design.StandardDesigner.DesignerControl;
|
|
FastReport.Report report = design.Report;
|
|
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
|
|
form.IsMdiContainer = true;
|
|
form.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
|
report.Prepare();
|
|
report.ShowPrepared(form);
|
|
report.Preview.OnPrint += Preview_OnPrint;
|
|
report.Preview.ParentForm.WindowState = FormWindowState.Maximized;
|
|
form.ShowDialog();
|
|
report.Preview = null;
|
|
form.Dispose();
|
|
}
|
|
|
|
private static void Preview_OnPrint(object sender, PreviewControl.PrintEventArgs e) |