using System;
using System.Data;
using System.ComponentModel;
using System.Collections;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
namespace Ylgl.Ent.Report
{
/// <summary>
/// BindReport 的摘要说明。
/// </summary>
public class BindReport
{
ReportClass Rept = null;
ArrayList al = new ArrayList();
Hashtable _ParameterFields = null;
/// <summary>
/// 报表中的参数集合
/// </summary>
public Hashtable ParameterFields
{
get
{
if(_ParameterFields ==null)
{
_ParameterFields = new Hashtable();
}
return _ParameterFields;
}
set
{
_ParameterFields = value;
}
}
/// <summary>
/// 用于构造当前实例的表明命名空间
/// </summary>
/// <param name="NamespaceName"></param>
public BindReport(string NamespaceName)
{
Type type = Type.GetType(NamespaceName,true);
Rept = (ReportClass)Activator.CreateInstance(type);
}
/// <summary>
/// 报表绑定方法
/// </summary>
/// <param name="DataSource">数据源</param>
/// <param name="ReportViewer">报表显示控件</param>
public void BindMainReport(IListSource DataSource,CrystalReportViewer ReportViewer)
{
Rept.SetDataSource(DataSource);
//绑定子报表
if(al.Count != 0)
{
for(int i=0;i<al.Count;i++)
{
SubReport sr = (SubReport)al[0];
SubreportObject oSubreport1 =(SubreportObject)Rept.ReportDefinition.Sections[sr.Place].ReportObjects[sr.SubObject];
ReportDocument oSub1 = oSubreport1.OpenSubreport(sr.SubPath);
oSub1.SetDataSource(sr.DataSource);
}
}
//给参数字段赋值
if(ParameterFields != null)
{
ParameterFields fs = Rept.ParameterFields;
foreach(DictionaryEntry de in ParameterFields)
{
ParameterField ParameterName = fs[de.Key.ToString()];
ParameterDiscreteValue ParameterValue = new ParameterDiscreteValue();
ParameterValue.Value = de.Value;
ParameterName.CurrentValues.Add(ParameterValue);
}
ReportViewer.ParameterFieldInfo = fs;
}
ReportViewer.ReportSource=Rept;
ReportViewer.DataBind();
}
/// <summary>
/// 设置添加绑定一个子报表到当前实例中
/// </summary>
/// <param name="dt">子报表数据源</param>
/// <param name="_SubObject">用于显示子报表的对象名</param>
/// <param name="_SubPath">子报表文件路径</param>
/// <param name="place">子报表位置索引</param>
public void SetSubReport(IListSource dt,string _SubObject,string _SubPath,int place)
{
SubReport sr = new SubReport();
sr.DataSource = dt;
sr.SubObject = _SubObject;
sr.SubPath = _SubPath;
sr.Place = place;
al.Add(sr);
}
构造子报表数据类型
}
}
using System.Data;
using System.ComponentModel;
using System.Collections;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
namespace Ylgl.Ent.Report
{
/// <summary>
/// BindReport 的摘要说明。
/// </summary>
public class BindReport
{
ReportClass Rept = null;
ArrayList al = new ArrayList();
Hashtable _ParameterFields = null;
/// <summary>
/// 报表中的参数集合
/// </summary>
public Hashtable ParameterFields
{
get
{
if(_ParameterFields ==null)
{
_ParameterFields = new Hashtable();
}
return _ParameterFields;
}
set
{
_ParameterFields = value;
}
}
/// <summary>
/// 用于构造当前实例的表明命名空间
/// </summary>
/// <param name="NamespaceName"></param>
public BindReport(string NamespaceName)
{
Type type = Type.GetType(NamespaceName,true);
Rept = (ReportClass)Activator.CreateInstance(type);
}
/// <summary>
/// 报表绑定方法
/// </summary>
/// <param name="DataSource">数据源</param>
/// <param name="ReportViewer">报表显示控件</param>
public void BindMainReport(IListSource DataSource,CrystalReportViewer ReportViewer)
{
Rept.SetDataSource(DataSource);
//绑定子报表
if(al.Count != 0)
{
for(int i=0;i<al.Count;i++)
{
SubReport sr = (SubReport)al[0];
SubreportObject oSubreport1 =(SubreportObject)Rept.ReportDefinition.Sections[sr.Place].ReportObjects[sr.SubObject];
ReportDocument oSub1 = oSubreport1.OpenSubreport(sr.SubPath);
oSub1.SetDataSource(sr.DataSource);
}
}
//给参数字段赋值
if(ParameterFields != null)
{
ParameterFields fs = Rept.ParameterFields;
foreach(DictionaryEntry de in ParameterFields)
{
ParameterField ParameterName = fs[de.Key.ToString()];
ParameterDiscreteValue ParameterValue = new ParameterDiscreteValue();
ParameterValue.Value = de.Value;
ParameterName.CurrentValues.Add(ParameterValue);
}
ReportViewer.ParameterFieldInfo = fs;
}
ReportViewer.ReportSource=Rept;
ReportViewer.DataBind();
}
/// <summary>
/// 设置添加绑定一个子报表到当前实例中
/// </summary>
/// <param name="dt">子报表数据源</param>
/// <param name="_SubObject">用于显示子报表的对象名</param>
/// <param name="_SubPath">子报表文件路径</param>
/// <param name="place">子报表位置索引</param>
public void SetSubReport(IListSource dt,string _SubObject,string _SubPath,int place)
{
SubReport sr = new SubReport();
sr.DataSource = dt;
sr.SubObject = _SubObject;
sr.SubPath = _SubPath;
sr.Place = place;
al.Add(sr);
}
构造子报表数据类型
}
}