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.
116 lines
3.5 KiB
116 lines
3.5 KiB
3 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using grproLib;
|
||
|
using System.Data;
|
||
|
using Stone.Common;
|
||
|
|
||
|
namespace Stone.Common
|
||
|
{
|
||
|
public class MyReport
|
||
|
{
|
||
|
public GridppReport Report = null;
|
||
|
public DataTable dtDataHead = null;
|
||
|
public DataTable dtDataDetail = null;
|
||
|
|
||
|
public MyReport(string filename, DataTable _dtDataHead, DataTable _dtDataDetail)
|
||
|
{
|
||
|
dtDataHead = _dtDataHead;
|
||
|
dtDataDetail = _dtDataDetail;
|
||
|
|
||
|
Report = new GridppReport();
|
||
|
Report.LoadFromFile(filename);
|
||
|
Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(Report_FetchRecord);
|
||
|
Report.Printer.PrinterName = MyAppconfig.ReadValue("Ĭ�ϴ�ӡ��");
|
||
|
|
||
|
FillParameters(); //���Ӳ���
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ӡ����
|
||
|
/// </summary>
|
||
|
public void Print()
|
||
|
{
|
||
|
Report.Print(true);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ӡԤ��
|
||
|
/// </summary>
|
||
|
public void PrintPreview()
|
||
|
{
|
||
|
Report.PrintPreview(true);
|
||
|
}
|
||
|
|
||
|
public void Report_FetchRecord()
|
||
|
{
|
||
|
if (dtDataDetail != null)
|
||
|
{
|
||
|
FillRecordToReport(Report, dtDataDetail);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private struct MatchFieldPairType
|
||
|
{
|
||
|
public IGRField grField;
|
||
|
public int MatchColumnIndex;
|
||
|
}
|
||
|
|
||
|
|
||
|
// �� DataTable ������ת���� Grid++Report �����ݼ���
|
||
|
public void FillRecordToReport(IGridppReport _Report, DataTable dt)
|
||
|
{
|
||
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(_Report.DetailGrid.Recordset.Fields.Count, dt.Columns.Count)];
|
||
|
|
||
|
//�����ֶ������������ƽ���ƥ�䣬����DataReader�ֶ���Grid++Report��¼�����ֶ�֮���Ķ�Ӧ��ϵ
|
||
|
int MatchFieldCount = 0;
|
||
|
for (int i = 0; i < dt.Columns.Count; ++i)
|
||
|
{
|
||
|
foreach (IGRField fld in _Report.DetailGrid.Recordset.Fields)
|
||
|
{
|
||
|
if (String.Compare(fld.Name, dt.Columns[i].ColumnName, true) == 0)
|
||
|
{
|
||
|
MatchFieldPairs[MatchFieldCount].grField = fld;
|
||
|
MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
||
|
++MatchFieldCount;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
// �� DataTable �е�ÿһ����¼ת���� Grid++Report �����ݼ���ȥ
|
||
|
foreach (DataRow dr in dt.Rows)
|
||
|
{
|
||
|
_Report.DetailGrid.Recordset.Append();
|
||
|
|
||
|
for (int i = 0; i < MatchFieldCount; ++i)
|
||
|
{
|
||
|
if (!dr.IsNull(MatchFieldPairs[i].MatchColumnIndex))
|
||
|
MatchFieldPairs[i].grField.Value = dr[MatchFieldPairs[i].MatchColumnIndex];
|
||
|
}
|
||
|
|
||
|
_Report.DetailGrid.Recordset.Post();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//��������
|
||
|
public void FillParameters()
|
||
|
{
|
||
|
if (dtDataHead.Rows.Count == 0) return;
|
||
|
|
||
|
for (int i = 0; i < dtDataHead.Columns.Count; ++i)
|
||
|
{
|
||
|
foreach (IGRParameter fpar in Report.Parameters)
|
||
|
{
|
||
|
if (String.Compare(fpar.Name, dtDataHead.Columns[i].ColumnName, true) == 0)
|
||
|
{
|
||
|
fpar.Value = dtDataHead.Rows[0][dtDataHead.Columns[i].ColumnName];
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|