using System;
|
using gregn6Lib;
|
using System.Data;
|
using System.Data.OleDb;
|
using System.Windows.Forms;
|
|
namespace BLL
|
{
|
/// <summary>
|
/// GridppReport µÄժҪ˵Ã÷¡£
|
/// </summary>
|
public class Utility
|
{
|
//public const string GetDatabaseConnectionString() = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\Data\Northwind.mdb";
|
|
//´Ëº¯ÊýÓÃÀ´×¢²áGrid++Report£¬Äã±ØÐëÔÚÄãµÄÓ¦ÓóÌÐòÆô¶¯Ê±µ÷Óô˺¯Êý
|
//ÓÃÄã×Ô¼ºµÄÐòÁкŴúÌæ"AAAAAAA"£¬"AAAAAAA"ÊÇÒ»¸öÎÞЧµÄÐòÁкÅ
|
public static void RegisterGridppReport()
|
{
|
GridppReport TempGridppReport = new GridppReport();
|
bool Succeeded = TempGridppReport.Register("AAAAAAA");
|
if ( !Succeeded )
|
System.Windows.Forms.MessageBox.Show("Register Grid++Report Failed, Grid++Report will run in trial mode.", "Register"
|
,System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
|
}
|
|
private struct MatchFieldPairType
|
{
|
public IGRField grField;
|
public int MatchColumnIndex;
|
}
|
|
// ½« DataReader µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static void FillRecordToReport(IGridppReport Report, IDataReader dr)
|
{
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dr.FieldCount)];
|
|
//¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
int MatchFieldCount = 0;
|
for (int i=0; i<dr.FieldCount; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
{
|
if (String.Compare(fld.RunningDBField, dr.GetName(i), true) == 0)
|
{
|
MatchFieldPairs[MatchFieldCount].grField = fld;
|
MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
++MatchFieldCount;
|
break;
|
}
|
}
|
}
|
|
|
// Loop through the contents of the OleDbDataReader object.
|
// ½« DataReader ÖеÄÿһÌõ¼Ç¼ת´¢µ½Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
while (dr.Read())
|
{
|
Report.DetailGrid.Recordset.Append();
|
|
for (int i=0; i<MatchFieldCount; ++i)
|
{
|
if ( !dr.IsDBNull(MatchFieldPairs[i].MatchColumnIndex) )
|
MatchFieldPairs[i].grField.Value = dr.GetValue(MatchFieldPairs[i].MatchColumnIndex);
|
}
|
|
Report.DetailGrid.Recordset.Post();
|
}
|
}
|
|
// ½« DataTable µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static 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();
|
}
|
}
|
|
// ½« DataTable µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static void FillRecordToReport(IGridppReport Report, System.Windows.Forms.DataGridView grd, System.Windows.Forms.DataGridView grd2, bool ByFixCols, int FindCol,bool b)
|
{
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, grd.ColumnCount)];
|
//¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
int MatchFieldCount = 0;
|
int FixCols = 0;
|
if (ByFixCols)
|
{
|
FixCols = 0;
|
}
|
else
|
{
|
FixCols = 0;
|
}
|
//for (int i = FixCols; i < grd.Cols; ++i)
|
//{
|
// foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
// {
|
// if (String.Compare(fld.Name, ClsPub.isStrNull(grd.get_TextMatrix(0,i)), true) == 0)
|
// {
|
// MatchFieldPairs[MatchFieldCount].grField = fld;
|
// MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
// ++MatchFieldCount;
|
// break;
|
// }
|
// }
|
//}
|
// ½« DataTable ÖеÄÿһÌõ¼Ç¼ת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
|
grd2.RowCount = 1;
|
grd2.ColumnCount = 1;
|
int iCol = 0;
|
for (int j = 0; j < grd.RowCount; j++)
|
{
|
iCol = 0;
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[FindCol].Value) != "")
|
{
|
grd2.RowCount = grd2.RowCount + 1;
|
for (int i = FixCols; i < grd.ColumnCount; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
{
|
if (String.Compare(fld.Name, DBUtility.ClsPub.isStrNull(grd.Columns[i].HeaderText), true) == 0)
|
{
|
iCol = iCol + 1;
|
if (j == 0)
|
{
|
grd2.ColumnCount = grd2.ColumnCount + 1;
|
//grd2.set_TextMatrix(0, grd2.Cols - 1, fld.Name);
|
grd2.Columns[grd2.ColumnCount - 2].HeaderText = fld.Name;
|
}
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i].Value) != "")
|
//grd2.set_TextMatrix(j, iCol - 1, DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(j, i + FixCols)));
|
grd2.Rows[j].Cells[iCol - 1].Value = grd.Rows[j].Cells[i + FixCols].Value;
|
}
|
}
|
}
|
}
|
}
|
//
|
for (int i = FixCols; i < grd2.ColumnCount; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
{
|
if (String.Compare(fld.Name, DBUtility.ClsPub.isStrNull(grd2.Columns[i].HeaderText), true) == 0)
|
{
|
MatchFieldPairs[MatchFieldCount].grField = fld;
|
MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
++MatchFieldCount;
|
break;
|
}
|
}
|
}
|
// ½« DataTable ÖеÄÿһÌõ¼Ç¼ת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
for (int j = 0; j < grd2.RowCount; j++)
|
{
|
Report.DetailGrid.Recordset.Append();
|
for (int i = 0; i < MatchFieldCount; ++i)
|
{
|
if (DBUtility.ClsPub.isStrNull(grd2.Rows[j].Cells[i].Value) != "")
|
MatchFieldPairs[i].grField.Value = grd2.Rows[j].Cells[i].Value;
|
}
|
Report.DetailGrid.Recordset.Post();
|
}
|
}
|
|
//// ½« DataTable µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
//public static void FillRecordToReport(IGridppReport Report, AxVSFlex7.AxVSFlexGrid grd, AxVSFlex7.AxVSFlexGrid grd2, bool ByFixCols, int FindCol)
|
//{
|
// MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, grd.Cols)];
|
// //¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
// int MatchFieldCount = 0;
|
// int FixCols = 0;
|
// if (ByFixCols)
|
// {
|
// FixCols = 0;
|
// }
|
// else
|
// {
|
// FixCols = grd.FixedCols;
|
// }
|
// //for (int i = FixCols; i < grd.Cols; ++i)
|
// //{
|
// // foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
// // {
|
// // if (String.Compare(fld.Name, ClsPub.isStrNull(grd.get_TextMatrix(0,i)), true) == 0)
|
// // {
|
// // MatchFieldPairs[MatchFieldCount].grField = fld;
|
// // MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
// // ++MatchFieldCount;
|
// // break;
|
// // }
|
// // }
|
// //}
|
// // ½« DataTable ÖеÄÿһÌõ¼Ç¼ת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
|
// grd2.Rows = 1;
|
// grd2.Cols = 0;
|
// grd2.FixedCols = grd.FixedCols;
|
// grd2.FixedRows = grd.FixedRows;
|
// int iCol = 0;
|
// for (int j = grd.FixedRows; j < grd.Rows; j++)
|
// {
|
// iCol = 0;
|
// if (DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(j, FindCol)) != "")
|
// {
|
// grd2.Rows = grd2.Rows + 1;
|
// for (int i = FixCols; i < grd.Cols; ++i)
|
// {
|
// foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
// {
|
// if (String.Compare(fld.Name, DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(0, i)), true) == 0)
|
// {
|
// iCol = iCol + 1;
|
// if (j == grd.FixedRows)
|
// {
|
// grd2.Cols = grd2.Cols + 1;
|
// grd2.set_TextMatrix(0, grd2.Cols - 1, fld.Name);
|
// }
|
// if (DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(j, i + FixCols)) != "")
|
// grd2.set_TextMatrix(j, iCol - 1, DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(j, i + FixCols)));
|
// }
|
// }
|
// }
|
// }
|
// }
|
// //
|
// for (int i = FixCols; i < grd2.Cols; ++i)
|
// {
|
// foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
// {
|
// if (String.Compare(fld.Name, DBUtility.ClsPub.isStrNull(grd2.get_TextMatrix(0, i)), true) == 0)
|
// {
|
// MatchFieldPairs[MatchFieldCount].grField = fld;
|
// MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
// ++MatchFieldCount;
|
// break;
|
// }
|
// }
|
// }
|
// // ½« DataTable ÖеÄÿһÌõ¼Ç¼ת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
// for (int j = grd2.FixedRows; j < grd2.Rows; j++)
|
// {
|
// Report.DetailGrid.Recordset.Append();
|
// for (int i = 0; i < MatchFieldCount; ++i)
|
// {
|
// if (DBUtility.ClsPub.isStrNull(grd2.get_TextMatrix(j, i + FixCols)) != "")
|
// MatchFieldPairs[i].grField.Value = grd2.get_TextMatrix(j, i + FixCols);
|
// }
|
// Report.DetailGrid.Recordset.Post();
|
// }
|
//}
|
|
//// ½« VSFlexGrid µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
//public static void FillRecordToReport(IGridppReport Report, AxVSFlex7.AxVSFlexGrid grd, bool ByFixCols)
|
//{
|
// MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, grd.Cols)];
|
// //¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
// int MatchFieldCount = 0;
|
// int FixCols = 0;
|
// if (ByFixCols)
|
// {
|
// FixCols = 0;
|
// }
|
// else
|
// {
|
// FixCols = grd.FixedCols;
|
// }
|
// for (int i = FixCols; i < grd.Cols; ++i)
|
// {
|
// foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
// {
|
// if (String.Compare(fld.Name, DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(0, i)), true) == 0)
|
// {
|
// MatchFieldPairs[MatchFieldCount].grField = fld;
|
// MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
// ++MatchFieldCount;
|
// break;
|
// }
|
// }
|
// }
|
// // ½« DataTable ÖеÄÿһÌõ¼Ç¼ת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
// for (int j = grd.FixedRows; j < grd.Rows; j++)
|
// {
|
// Report.DetailGrid.Recordset.Append();
|
// for (int i = 0; i < MatchFieldCount; ++i)
|
// {
|
// if (DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(j, i + FixCols)) != "")
|
// MatchFieldPairs[i].grField.Value = grd.get_TextMatrix(j, i + FixCols);
|
// }
|
// Report.DetailGrid.Recordset.Post();
|
// }
|
//}
|
|
// ½« DataGridView µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static void FillRecordToReport(IGridppReport Report, System.Windows.Forms.DataGridView grd, System.Windows.Forms.DataGridView grd2, int FindCol)
|
{
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, grd.Columns.Count)];
|
//¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
int MatchFieldCount = 0;
|
int FixCols = 0;
|
//½«grd1µÄÊý¾ÝдÈëgrd2£¬Ð´ÈëǰÌᣬ×Ö¶ÎÃûºÍÍø¸ñ±êÌâ Ïàͬ,FindColΪÅжÏÊÇ·ñ¿ÕÐÐ
|
grd2.RowCount = 1;
|
grd2.ColumnCount = 0;
|
int iCol = 0;
|
|
|
//¼Ç¼grdÖеķǿÕÐÐÊý£¬²¢ÓÃÓÚÉèÖÃgrd2µÄÐÐÊý
|
int grd2RowCount = 0;
|
int grd2RowIndex = 0; //×÷Ϊxiang
|
for (int j = 0; j < grd.RowCount; j++) //Ñ»·Íø¸ñ1,
|
{
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[FindCol].Value) != "")//ÊÇ·ñ¿ÕÐÐ
|
{
|
grd2RowCount = grd2RowCount + 1;
|
}
|
}
|
grd2.RowCount = grd2RowCount;
|
|
for (int j = 0; j < grd.RowCount; j++) //Ñ»·Íø¸ñ1,
|
{
|
iCol = 0;
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[FindCol].Value) != "")//ÊÇ·ñ¿ÕÐÐ
|
{
|
for (int i = FixCols; i < grd.Columns.Count; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields) //´Ó¼Ç¼¼¯ÖÐÕÒµ½ Ïàͬ×Ö¶ÎÃû
|
{
|
if (String.Compare(fld.Name, grd.Columns[i].HeaderText, true) == 0)
|
{
|
iCol = iCol + 1;
|
if (j == 0)
|
{
|
grd2.ColumnCount = grd2.ColumnCount + 1;
|
grd2.Columns[grd2.Columns.Count - 1].HeaderText = fld.Name;
|
}
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i + FixCols].Value) != "")
|
{
|
grd2.Rows[grd2RowIndex].Cells[iCol - 1].Value = DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i + FixCols].Value);
|
}
|
}
|
}
|
}
|
grd2RowIndex = grd2RowIndex + 1;
|
}
|
}
|
//½«grd2µÄÊý¾ÝдÈë ¼Ç¼¼¯
|
for (int i = FixCols; i < grd2.Columns.Count; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
{
|
if (String.Compare(fld.Name, grd2.Columns[i].HeaderText, true) == 0)
|
{
|
MatchFieldPairs[MatchFieldCount].grField = fld;
|
MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
++MatchFieldCount;
|
break;
|
}
|
}
|
}
|
// ½«grd2µÄÊý¾ÝдÈë ¼Ç¼¼¯
|
for (int j = 0; j < grd2.RowCount; j++)
|
{
|
Report.DetailGrid.Recordset.Append();
|
for (int i = 0; i < MatchFieldCount; ++i)
|
{
|
if (DBUtility.ClsPub.isStrNull(grd2.Rows[j].Cells[i + FixCols].Value) != "")
|
MatchFieldPairs[i].grField.Value = grd2.Rows[j].Cells[i + FixCols].Value;
|
}
|
Report.DetailGrid.Recordset.Post();
|
}
|
}
|
|
// ½« DataTable µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static void FillRecordToReport(IGridppReport Report, System.Windows.Forms.DataGridView grd, System.Windows.Forms.DataGridView grd2, bool ByFixCols, int FindCol)
|
{
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, grd.ColumnCount)];
|
//¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
int MatchFieldCount = 0;
|
int FixCols = 0;
|
if (ByFixCols)
|
{
|
FixCols = 0;
|
}
|
else
|
{
|
FixCols = 0;
|
}
|
//for (int i = FixCols; i < grd.Cols; ++i)
|
//{
|
// foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
// {
|
// if (String.Compare(fld.Name, ClsPub.isStrNull(grd.get_TextMatrix(0,i)), true) == 0)
|
// {
|
// MatchFieldPairs[MatchFieldCount].grField = fld;
|
// MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
// ++MatchFieldCount;
|
// break;
|
// }
|
// }
|
//}
|
// ½« DataTable ÖеÄÿһÌõ¼Ç¼ת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
|
grd2.RowCount = 1;
|
grd2.ColumnCount = 1;
|
int iCol = 0;
|
for (int j = 0; j < grd.RowCount; j++)
|
{
|
iCol = 0;
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[FindCol].Value) != "")
|
{
|
grd2.RowCount = grd2.RowCount + 1;
|
for (int i = FixCols; i < grd.ColumnCount; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
{
|
if (String.Compare(fld.Name, DBUtility.ClsPub.isStrNull(grd.Columns[i].HeaderText), true) == 0)
|
{
|
iCol = iCol + 1;
|
if (j == 0)
|
{
|
grd2.ColumnCount = grd2.ColumnCount + 1;
|
//grd2.set_TextMatrix(0, grd2.Cols - 1, fld.Name);
|
grd2.Columns[grd2.ColumnCount - 2].HeaderText = fld.Name;
|
}
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i].Value) != "")
|
//grd2.set_TextMatrix(j, iCol - 1, DBUtility.ClsPub.isStrNull(grd.get_TextMatrix(j, i + FixCols)));
|
grd2.Rows[j].Cells[iCol - 1].Value = grd.Rows[j].Cells[i + FixCols].Value;
|
}
|
}
|
}
|
}
|
}
|
//
|
for (int i = FixCols; i < grd2.ColumnCount; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
|
{
|
if (String.Compare(fld.Name, DBUtility.ClsPub.isStrNull(grd2.Columns[i].HeaderText), true) == 0)
|
{
|
MatchFieldPairs[MatchFieldCount].grField = fld;
|
MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
|
++MatchFieldCount;
|
break;
|
}
|
}
|
}
|
// ½« DataTable ÖеÄÿһÌõ¼Ç¼ת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐÈ¥
|
for (int j = 0; j < grd2.RowCount; j++)
|
{
|
Report.DetailGrid.Recordset.Append();
|
for (int i = 0; i < MatchFieldCount; ++i)
|
{
|
if (DBUtility.ClsPub.isStrNull(grd2.Rows[j].Cells[i].Value) != "")
|
MatchFieldPairs[i].grField.Value = grd2.Rows[j].Cells[i].Value;
|
}
|
Report.DetailGrid.Recordset.Post();
|
}
|
}
|
|
// ½« DataGridView µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static void FillRecordToReportBySel(IGridppReport Report, System.Windows.Forms.DataGridView grd, DataTable dt, int FindCol)
|
{
|
try
|
{
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, grd.Columns.Count)];
|
//¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
int MatchFieldCount = 0;
|
int FixCols = 0;
|
DataRow sRow;
|
DataColumn sCol;
|
//½«grd1µÄÊý¾ÝдÈëgrd2£¬Ð´ÈëǰÌᣬ×Ö¶ÎÃûºÍÍø¸ñ±êÌâ Ïàͬ,FindColΪÅжÏÊÇ·ñ¿ÕÐÐ
|
int iCol = 0;
|
bool bb = false;
|
for (int j = 0; j < grd.RowCount; j++) //Ñ»·Íø¸ñ1,
|
{
|
iCol = 0;
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[FindCol].Value) != "")//ÊÇ·ñ¿ÕÐÐ
|
{
|
sRow = dt.NewRow();
|
for (int i = FixCols; i < grd.Columns.Count; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields) //´Ó¼Ç¼¼¯ÖÐÕÒµ½ Ïàͬ×Ö¶ÎÃû
|
{
|
if (String.Compare(fld.Name, grd.Columns[i].HeaderText, true) == 0)
|
{
|
iCol = iCol + 1;
|
if (bb == false)
|
{
|
sCol = new DataColumn();
|
sCol.ColumnName = fld.Name;
|
dt.Columns.Add(sCol);
|
}
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i + FixCols].Value) != "")
|
{
|
|
sRow[iCol - 1] = DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i + FixCols].Value);
|
}
|
}
|
}
|
}
|
dt.Rows.Add(sRow);
|
bb = true;
|
}
|
}
|
//
|
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();
|
}
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show(e.Message);
|
}
|
}
|
|
|
// ½« DataGridView µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static void FillRecordToReport(IGridppReport Report, System.Windows.Forms.DataGridView grd, DataTable dt, int FindCol)
|
{
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, grd.Columns.Count)];
|
//¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
int MatchFieldCount = 0;
|
int FixCols = 0;
|
DataRow sRow;
|
DataColumn sCol;
|
//½«grd1µÄÊý¾ÝдÈëgrd2£¬Ð´ÈëǰÌᣬ×Ö¶ÎÃûºÍÍø¸ñ±êÌâ Ïàͬ,FindColΪÅжÏÊÇ·ñ¿ÕÐÐ
|
int iCol = 0;
|
for (int j = 0; j < grd.RowCount; j++) //Ñ»·Íø¸ñ1,
|
{
|
iCol = 0;
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[FindCol].Value) != "")//ÊÇ·ñ¿ÕÐÐ
|
{
|
sRow = dt.NewRow();
|
for (int i = FixCols; i < grd.Columns.Count; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields) //´Ó¼Ç¼¼¯ÖÐÕÒµ½ Ïàͬ×Ö¶ÎÃû
|
{
|
if (String.Compare(fld.Name, grd.Columns[i].HeaderText, true) == 0)
|
{
|
iCol = iCol + 1;
|
if (j == 0)
|
{
|
sCol = new DataColumn();
|
sCol.ColumnName = fld.Name;
|
dt.Columns.Add(sCol);
|
}
|
if (DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i + FixCols].Value) != "")
|
{
|
|
sRow[iCol - 1] = DBUtility.ClsPub.isStrNull(grd.Rows[j].Cells[i + FixCols].Value);
|
}
|
}
|
}
|
}
|
dt.Rows.Add(sRow);
|
}
|
}
|
//
|
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();
|
}
|
|
}
|
|
|
// ½« DataGridView µÄÊý¾Ýת´¢µ½ Grid++Report µÄÊý¾Ý¼¯ÖÐ
|
public static void FillRecordToReport(IGridppReport Report, DataTable dt_Old, DataTable dt, int FindCol)
|
{
|
MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dt_Old.Columns.Count)];
|
//¸ù¾Ý×Ö¶ÎÃû³ÆÓëÁÐÃû³Æ½øÐÐÆ¥Å䣬½¨Á¢DataReader×Ö¶ÎÓëGrid++Report¼Ç¼¼¯µÄ×Ö¶ÎÖ®¼äµÄ¶ÔÓ¦¹ØÏµ
|
int MatchFieldCount = 0;
|
int FixCols = 0;
|
DataRow sRow;
|
DataColumn sCol;
|
//½«grd1µÄÊý¾ÝдÈëgrd2£¬Ð´ÈëǰÌᣬ×Ö¶ÎÃûºÍÍø¸ñ±êÌâ Ïàͬ,FindColΪÅжÏÊÇ·ñ¿ÕÐÐ
|
int iCol = 0;
|
for (int j = 0; j < dt_Old.Rows.Count; j++) //Ñ»·Íø¸ñ1,
|
{
|
iCol = 0;
|
if (DBUtility.ClsPub.isStrNull(dt_Old.Columns[FindCol].ColumnName) != "")//ÊÇ·ñ¿ÕÐÐ
|
{
|
sRow = dt.NewRow();
|
for (int i = FixCols; i < dt_Old.Columns.Count; ++i)
|
{
|
foreach (IGRField fld in Report.DetailGrid.Recordset.Fields) //´Ó¼Ç¼¼¯ÖÐÕÒµ½ Ïàͬ×Ö¶ÎÃû
|
{
|
if (String.Compare(fld.Name, dt_Old.Columns[i].ColumnName, true) == 0)
|
{
|
iCol = iCol + 1;
|
if (j == 0)
|
{
|
sCol = new DataColumn();
|
sCol.ColumnName = fld.Name;
|
dt.Columns.Add(sCol);
|
}
|
if (DBUtility.ClsPub.isStrNull(dt_Old.Rows[j][i + FixCols]) != "")
|
{
|
sRow[iCol - 1] = DBUtility.ClsPub.isStrNull(dt_Old.Rows[j][i + FixCols]);
|
}
|
}
|
}
|
}
|
dt.Rows.Add(sRow);
|
}
|
}
|
//
|
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 static uint RGBToOleColor(byte r, byte g, byte b)
|
{
|
return ((uint)b)*256*256 + ((uint)g)*256 + r;
|
}
|
|
public static uint ColorToOleColor(System.Drawing.Color val)
|
{
|
return RGBToOleColor(val.R, val.G, val.B);
|
}
|
|
public static string GetSampleRootPath()
|
{
|
string FileName = Application.StartupPath.ToLower();
|
int Index = FileName.LastIndexOf("samples");
|
FileName = FileName.Substring(0, Index);
|
return FileName + @"samples\";
|
}
|
|
public static string GetReportTemplatePath()
|
{
|
return GetSampleRootPath() + @"Reports\";
|
}
|
|
public static string GetReportDataPath()
|
{
|
return GetSampleRootPath() + @"Data\";
|
}
|
|
public static string GetReportDataPathFile()
|
{
|
return GetReportDataPath() + @"NorthWind.mdb";
|
}
|
|
public static string GetDatabaseConnectionString()
|
{
|
return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + GetReportDataPathFile();
|
} }
|
}
|