注塑喷涂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

187 lines
5.8 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using gregn6Lib;
namespace PurchingMistakeNew
{
public class ReportHelper
{
public GridppReport Report;
private DataTable _dtDataDetail;
public ReportHelper(string filename, DataTable dtDataHead, DataTable dtDataDetail, int paperOrigntation, short copies, string printerName)
{
Init(filename, dtDataHead, dtDataDetail, paperOrigntation, copies, printerName);
}
private void Init(string filename, DataTable dtDataHead, DataTable dtDataDetail, int paperOrigntation, short copies, string printerName)
{
try
{
_dtDataDetail = dtDataDetail;
Report = new GridppReport();
Report.LoadFromFile(filename);
Report.FetchRecord += Report_FetchRecord;
Report.Printer.PrinterName = printerName;
Report.Printer.PaperOrientation = (GRPaperOrientation)paperOrigntation;
Report.Printer.Copies = copies;
FillParameters(Report, dtDataHead);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public void Print(bool isPreview, bool isShowDialog = true)
{
if (isPreview)
Report.PrintPreview(true);
else
Report.Print(isShowDialog);
}
private void Report_FetchRecord()
{
if (_dtDataDetail != null)
{
FillRecordToReport(Report, _dtDataDetail);
}
}
private void FillRecordToReport(IGridppReport report, DataTable dtDetail)
{
foreach (DataRow dr in dtDetail.Rows)
{
report.DetailGrid.Recordset.Append();
foreach (DataColumn dc in dtDetail.Columns)
{
var field = report.FieldByName(dc.ColumnName);
if (field == null) continue;
field.Value = dr[dc.ColumnName];
}
report.DetailGrid.Recordset.Post();
}
}
private void FillParameters(GridppReport report, DataTable dtHead)
{
if (dtHead.Rows.Count == 0) return;
foreach (DataColumn dc in dtHead.Columns)
{
var param = report.ParameterByName(dc.ColumnName);
if (param == null) continue;
param.Value = dtHead.Rows[0][dc.ColumnName];
}
}
public static string GetTemplateFile(string sourfilename)
{
var ofd = new OpenFileDialog
{
Filter = @"Grid++ files (*.grf)|*.grf",
Multiselect = false,
RestoreDirectory = true,
FileName = sourfilename,
InitialDirectory = Path.GetDirectoryName(sourfilename),
};
if (ofd.ShowDialog() != DialogResult.OK) return string.Empty;
return ofd.FileName;
}
#region 新标签模板
/// <summary>
/// X247门板标签
/// </summary>
/// <returns></returns>
internal static string GetTemplateDoor()
{
return Application.StartupPath + $@"\Report\标签-247门板.grf";
}
/// <summary>
/// X243轮眉标签
/// </summary>
/// <returns></returns>
internal static string GetTemplateWheelBrow243()
{
return Application.StartupPath + $@"\Report\标签-243轮眉.grf";
}
/// <summary>
/// X247轮眉标签
/// </summary>
/// <returns></returns>
internal static string GetTemplateWheelBrow247()
{
return Application.StartupPath + $@"\Report\标签-247轮眉.grf";
}
/// <summary>
/// X247&H247扰流板标签
/// </summary>
/// <returns></returns>
internal static string GetTemplateSpoiler()
{
return Application.StartupPath + $@"\Report\标签-247扰流板.grf";
}
#endregion
#region 新装箱单模板
/// <summary>
/// 247门板装箱单
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
internal static string GetBoxTemplateNameDoor()
{
return Application.StartupPath + $@"\Report\装箱单-门板.grf";
}
/// <summary>
/// 247轮眉装箱单
/// </summary>
/// <returns></returns>
internal static string GetBoxTemplateNameWheelBrow247()
{
return Application.StartupPath + $@"\Report\装箱单-247轮眉.grf";
}
/// <summary>
/// 243轮眉装箱单
/// </summary>
/// <returns></returns>
internal static string GetBoxTemplateNameWheelBrow243()
{
return Application.StartupPath + $@"\Report\装箱单-243轮眉.grf";
}
/// <summary>
/// X247和H247扰流板装箱单
/// </summary>
/// <returns></returns>
internal static string GetBoxTemplateNameSpoiler()
{
return Application.StartupPath + $@"\Report\装箱单-247扰流板.grf";
}
#endregion
internal static string GetTemplateName(string fileName)
{
return Application.StartupPath + $@"\Report\{fileName}.grf";
}
internal static string GetTemplateNameDNew(string fileName)
{
return $@"D:\New\{fileName}.grf";
}
internal static string GetTemplateNameD(string fileName)
{
return $@"D:\{fileName}.grf";
}
}
}