Example #1
0
        /// <summary>
        /// 填充DataReader类型的数据源的数据到报表的明细网格的记录集的对应字段中
        /// </summary>
        /// <param name="rpt"></param>
        /// <param name="dr"></param>
        private void FillRecordToReport(GridppReport rpt, IDataReader dr)
        {
            MatchFieldPairType[] matchFieldPair = new MatchFieldPairType[System.Math.Min(report.DetailGrid.Recordset.Fields.Count, dr.FieldCount)];
            int matchFieldPairIndex = 0;
            for (int i = 0; i < dr.FieldCount; i++)
            {
                foreach (IGRField fld in report.DetailGrid.Recordset.Fields)
                {
                    if (string.Compare(fld.Name, dr.GetName(i)) == 0)
                    {
                        matchFieldPair[matchFieldPairIndex].field = fld;
                        matchFieldPair[matchFieldPairIndex].MatchColumnIndex = i;
                        matchFieldPairIndex++;
                        break;
                    }
                }
            }

            while (dr.Read())
            {
                report.DetailGrid.Recordset.Append();
                foreach (MatchFieldPairType fieldPair in matchFieldPair)
                {
                    if (!dr.IsDBNull(fieldPair.MatchColumnIndex))
                    {
                        fieldPair.field.Value = dr.GetValue(fieldPair.MatchColumnIndex);
                    }
                }
                report.DetailGrid.Recordset.Post();
            }
        }
Example #2
0
        /// <summary>
        /// 填充DataTable类型的数据源的数据到报表的明细网格的记录集的对应字段中
        /// </summary>
        /// <param name="rpt"></param>
        /// <param name="dt"></param>
        private void FillRecordToReport(GridppReport rpt, DataTable dt)
        {
            MatchFieldPairType[] matchFieldPair = new MatchFieldPairType[System.Math.Min(report.DetailGrid.Recordset.Fields.Count, dt.Columns.Count)];
            int matchFieldPairIndex = 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)
                    {
                        matchFieldPair[matchFieldPairIndex].field = fld;
                        matchFieldPair[matchFieldPairIndex].MatchColumnIndex = i;
                        matchFieldPairIndex++;
                        break;
                    }
                }
            }

            foreach (DataRow dr in dt.Rows)
            {
                report.DetailGrid.Recordset.Append();
                foreach (MatchFieldPairType fieldPair in matchFieldPair)
                {
                    if(!dr.IsNull(fieldPair.MatchColumnIndex))
                    fieldPair.field.Value = dr[fieldPair.MatchColumnIndex];
                }
                report.DetailGrid.Recordset.Post();
            }
        }