/// <summary> /// 将 DataTable 的数据转储到 Grid++Report 的数据集中 /// </summary> /// <param name="Report"></param> /// <param name="dt"></param> 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(); } }
private void FillRecordToReport(GridppReport report, IDataReader dr) { MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dr.FieldCount)]; 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; } } } 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(); } }
/// <summary> /// 将 DataReader 的数据转储到 Grid++Report 的数据集中 /// </summary> /// <param name="Report"></param> /// <param name="dr"></param> 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(); } }
/// <summary> /// 将 DataTable 的数据转储到 Grid++Report 的数据集中 /// </summary> /// <param name="Report">报表对象</param> /// <param name="dt">DataTable对象</param> public void FillRecordToReport(IGridppReport report, DataTable dt) { MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(report.DetailGrid.Recordset.Fields.Count, dt.Columns.Count)]; try { //根据字段名称与列名称进行匹配,建立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) { var columnIndex = MatchFieldPairs[i].MatchColumnIndex; if (!dr.IsNull(columnIndex)) { MatchFieldPairs[i].grField.Value = dr[columnIndex]; } } report.DetailGrid.Recordset.Post(); } } catch (Exception E) { Pub.ShowErrorMsg(E); } finally { MatchFieldPairs = null; dt = null; report = null; } }
// 将 DataTable 的数据转储到 Grid++Report 的数据集中 public void FillRecordToReport() { try { MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, printtable.Columns.Count)]; #region //根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系 int MatchFieldCount = 0; for (int i = 0; i < printtable.Columns.Count; ++i) { foreach (IGRField fld in Report.DetailGrid.Recordset.Fields) { if (String.Compare(fld.Name, printtable.Columns[i].ColumnName, true) == 0) { MatchFieldPairs[MatchFieldCount].grField = fld; MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i; ++MatchFieldCount; break; } } } #endregion #region // 将 DataTable 中的每一条记录转储到 Grid++Report 的数据集中去 IGRRecordset Recordset = Report.DetailGrid.Recordset; //数据集 foreach (DataRow dr in printtable.Rows) { try { Recordset.Append(); } catch { } for (int i = 0; i < MatchFieldCount; ++i) { if (!dr.IsNull(MatchFieldPairs[i].MatchColumnIndex)) { MatchFieldPairs[i].grField.Value = dr[MatchFieldPairs[i].MatchColumnIndex]; } } try { Recordset.Post(); } catch { } } #endregion } catch { } }
/// <summary> /// List加载数据集 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Report">报表对象</param> /// <param name="list">列表数据</param> public static void FillRecordToReport <T>(IGridppReport Report, List <T> list) { Type type = typeof(T); //反射类型 MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, type.GetProperties().Length)]; //根据字段名称与列名称进行匹配,建立字段与Grid++Report记录集的字段之间的对应关系 int MatchFieldCount = 0; int i = 0; MemberInfo[] members = type.GetMembers(); foreach (MemberInfo memberInfo in members) { foreach (IGRField fld in Report.DetailGrid.Recordset.Fields) { if (string.Compare(fld.Name, memberInfo.Name, true) == 0) { MatchFieldPairs[MatchFieldCount].grField = fld; MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i; ++MatchFieldCount; break; } } ++i; } // 将 DataTable 中的每一条记录转储到 Grid++Report 的数据集中去 foreach (T t in list) { Report.DetailGrid.Recordset.Append(); for (i = 0; i < MatchFieldCount; ++i) { object objValue = GetPropertyValue(t, MatchFieldPairs[i].grField.Name); if (objValue != null) { MatchFieldPairs[i].grField.Value = objValue; } } Report.DetailGrid.Recordset.Post(); } }
// 将 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(); } }
private void FillRecordToReport(GridppReport reprot, 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(); } }
void grdrpt_FetchRecord() { if (printTable == null) { return; } int index; MatchFieldPairType[] typeArray = new MatchFieldPairType[printTable.Columns.Count]; int num = 0; for (index = 0; index < printTable.Columns.Count; index++) { foreach (grproLib.IGRField field in grdrpt.DetailGrid.Recordset.Fields) { if (string.Compare(field.Name, printTable.Columns[index].ColumnName, true) == 0) { typeArray[num].grField = field; typeArray[num].MatchColumnIndex = index; num++; break; } } } foreach (DataRow row in printTable.Rows) { grdrpt.DetailGrid.Recordset.Append(); for (index = 0; index < num; index++) { if (!row.IsNull(typeArray[index].MatchColumnIndex)) { typeArray[index].grField.Value = row[typeArray[index].MatchColumnIndex]; } } grdrpt.DetailGrid.Recordset.Post(); } }