示例#1
0
        public static void BuildParmsAndData(ReportRequestArgs e, FastReport.Report report, enBuildParmsAndDataActionType actionType)
        {
            if (actionType == enBuildParmsAndDataActionType.SetValue)  // 对模板已有参数赋值
            {
                foreach (FastReport.Data.Parameter parm in report.Parameters)
                {
                    // 参数值是从 fastParms.ReportParameters 中传入的
                    foreach (DataColumn dc in e.RecordDR.Table.Columns)
                    {
                        if (parm.Name.Equals(dc.ColumnName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            parm.Value = e.RecordDR[dc.ColumnName];
                            break;
                        }
                    }
                }
            }
            else    // 添加新的参数至模板
            {
                if (e.RecordDR != null)
                {
                    report.Parameters.Clear();
                    foreach (DataColumn dc in e.RecordDR.Table.Columns)
                    {
                        FastReport.Data.Parameter parm = new FastReport.Data.Parameter(dc.ColumnName);
                        parm.DataType = dc.DataType;
                        parm.Value    = e.RecordDR[dc.ColumnName];
                        report.Parameters.Add(parm);
                    }
                }
            }

            if (e.DSDataSource != null)
            {
                for (int i = 0, j = e.DSDataSource.Tables.Count; i < j; i++)
                {
                    DataTable table = e.DSDataSource.Tables[i];
                    string    description;
                    string    strTableName = table.TableName;
                    report.RegisterData(table, strTableName);
                    //report.RegisterData(e.DSDataSource);
                    //report.ReportInfo.Description = table.TableName;
                    DataSourceBase dataSource = report.GetDataSource(strTableName);
                    dataSource.Enabled = true;
                }
            }
        }
示例#2
0
 public bool AddParam(string paramName, object value)
 {
     try
     {
         FastReport.Data.Parameter param = this.Report.Parameters.FindByName(paramName);
         if (param == null)
         {
             FastReport.Data.Parameter paramNew = new FastReport.Data.Parameter(paramName);
             paramNew.Value = value;
             this.Report.Parameters.Add(paramNew);
         }
         else
         {
             param.Value = value;
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }