注塑喷涂
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.
 
 
 
 
 

98 lines
3.1 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using gregn6Lib;
namespace PunchAndWeld
{
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;
}
}
}