using HotelPms.Share.Util;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Diagnostics;
|
using System.Drawing;
|
using System.Drawing.Printing;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
using System.Windows.Forms;
|
|
namespace HotelPms.Share.Windows.Report
|
{
|
public class ReportFactory
|
{
|
public static void OutputGrid(DataTable data, GridStyle style)
|
{
|
ReportType type = ReportType.Print;
|
using(FormTypeSelect form = new FormTypeSelect())
|
{
|
if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; }
|
type = form.ReportType;
|
}
|
OutputGrid(data, style, type);
|
}
|
|
public static string GetTempFileName()
|
{
|
string root = Application.StartupPath.TrimEnd(Path.DirectorySeparatorChar) + @"\Output\";
|
if(!Directory.Exists(root)) { Directory.CreateDirectory(root); }
|
|
return $"{root}{DateTime.Now.ToString("yyyyMMddHHmmssfff")}";
|
}
|
|
public static void OutputGrid(DataTable data, GridStyle style, ReportType type)
|
{
|
string path = string.Empty;
|
IReport report = null;
|
if (type == ReportType.Print) { report = new GridReport(data, style, string.Empty); }
|
else if (type == ReportType.Pdf)
|
{
|
path = GetTempFileName() + ".pdf";
|
report = new GridReport(data, style, path);
|
}
|
else if (type == ReportType.Xlsx) { report = new GridExcel(data, style, true, GetTempFileName()); }
|
else if (type == ReportType.Xls) { report = new GridExcel(data, style, false, GetTempFileName()); }
|
else if (type == ReportType.Csv) { report = new GridCsv(data, style); }
|
else if (type == ReportType.Xml) { report = new GridXml(data, style); }
|
|
if (report == null) { return; }
|
report.Output();
|
report.Dispose();
|
|
if (type == ReportType.Pdf) { CConvert.StartFile(path); }
|
}
|
|
public static void OutputForm(List<List<Cell>> rptList, Rectangle ownerArea, PaperKind paper, string titlem)
|
{
|
OutputForm(rptList, ownerArea, paper, titlem, -1);
|
}
|
|
public static void OutputForm(List<List<Cell>> rptList, Rectangle ownerArea, PaperKind paper, string title, int rptType)
|
{
|
ReportType type = ReportType.Print;
|
if (rptType == -1)
|
{
|
using (FormTypeSelect form = new FormTypeSelect())
|
{
|
form.btnItem2.Enabled = false;
|
form.btnItem3.Enabled = false;
|
form.btnItem6.Enabled = false;
|
form.btnItem7.Enabled = false;
|
if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; }
|
type = form.ReportType;
|
}
|
}
|
else
|
{
|
type = (ReportType)rptType;
|
}
|
|
IReport report = null;
|
if (type == ReportType.Print) { report = new FormReport(rptList, ownerArea, paper, title); }
|
|
if (report == null) { return; }
|
report.Output();
|
report.Dispose();
|
}
|
|
public static int SelectType()
|
{
|
ReportType type = ReportType.Print;
|
using (FormTypeSelect form = new FormTypeSelect())
|
{
|
form.btnItem2.Enabled = false;
|
form.btnItem3.Enabled = false;
|
form.btnItem6.Enabled = false;
|
form.btnItem7.Enabled = false;
|
if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return -1; }
|
type = form.ReportType;
|
}
|
return (int)type;
|
}
|
|
}
|
}
|