public class CryReportBasePage : System.Web.UI.Page
{
/// <summary>
/// 报表文档
/// </summary>
protected ReportDocument myReport;
public static string ReportDocBasePath = ConfigurationManager.AppSettings["ReportDocBasePath"].ToString();
protected void Page_Unload(object sender, EventArgs e)
{
if (myReport != null)
{
myReport.Dispose();
}
}
/// <summary>
/// 参数值
/// </summary>
protected Dictionary<string, string> DicParValue = new Dictionary<string, string>();
/// <summary>
/// 公示字段值
/// </summary>
protected ArrayList FormularFieldsValues = new ArrayList();
/// <summary>
/// 网站物理地址
/// </summary>
protected string WebPath = HttpContext.Current.Request.PhysicalApplicationPath;
/// <summary>
/// 报表文件地址
/// </summary>
protected string ReportFilePath = string.Empty;
/// <summary>
/// 根据参数显示报表
/// </summary>
/// <param name="formularFieldsValue"></param>
/// <param name="dicValue"></param>
/// <param name="reportData"></param>
/// <param name="reportFile"></param>
/// <param name="reportView"></param>
public void ShowReport(string[] formularFieldsValue, Dictionary<string, string> dicValue, DataTable reportData, string reportFile, CrystalReportViewer reportView)
{
reportView.HasCrystalLogo = false;
//使用报表对象加载报表
myReport = new ReportDocument();
myReport.Load(reportFile);
DataDefinition dataDefinition = myReport.DataDefinition;
//获取数据对象中的公式字段集合
string[] Text4formularFields = formularFieldsValue;
FormulaFieldDefinitions formularFields = dataDefinition.FormulaFields;
for (int i = 0; i < formularFieldsValue.Length; i++)
{
formularFields[i].Text = formularFieldsValue[i];
}
myReport.SetDataSource(reportData);
reportView.ParameterFieldInfo = GetParameterFields(dicValue);
reportView.ReportSource = myReport;
}
/// <summary>
/// 根据参数显示报表
/// </summary>
/// <param name="formularFieldsValue"></param>
/// <param name="dicValue"></param>
/// <param name="reportData"></param>
/// <param name="reportFile"></param>
/// <param name="reportView"></param>
public void ShowReport(ArrayList formularFieldsValue, Dictionary<string, string> dicValue, DataTable reportData, string reportFile, CrystalReportViewer reportView)
{
reportView.HasCrystalLogo = false;
//使用报表对象加载报表
myReport = new ReportDocument();
myReport.Load(reportFile);
DataDefinition dataDefinition = myReport.DataDefinition;
//获取数据对象中的公式字段集合
FormulaFieldDefinitions formularFields = dataDefinition.FormulaFields;
for (int i = 0; i < formularFieldsValue.Count; i++)
{
formularFields[i].Text = Convert.ToString(formularFieldsValue[i]);
}
myReport.SetDataSource(reportData);
reportView.ParameterFieldInfo = GetParameterFields(dicValue);
reportView.ReportSource = myReport;
reportView.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
}
/// <summary>
/// 根据参数显示报表
/// </summary>
/// <param name="formularFieldsValue"></param>
/// <param name="dicValue"></param>
/// <param name="reportData"></param>
/// <param name="reportFile"></param>
/// <param name="reportView"></param>
public void ShowReport(ArrayList formularFieldsValue, Dictionary<string, string> dicValue, DataTable reportData, CrystalReportViewer reportView)
{
reportView.HasCrystalLogo = false;
//使用报表对象加载报表
myReport = new ReportDocument();
myReport.Load(this.ReportFilePath);
DataDefinition dataDefinition = myReport.DataDefinition;
//获取数据对象中的公式字段集合
FormulaFieldDefinitions formularFields = dataDefinition.FormulaFields;
for (int i = 0; i < formularFieldsValue.Count; i++)
{
formularFields[i].Text = Convert.ToString(formularFieldsValue[i]);
}
myReport.SetDataSource(reportData);
reportView.ParameterFieldInfo = GetParameterFields(dicValue);
reportView.ReportSource = myReport;
reportView.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
}
/// <summary>
/// 得到报表参数数据结构
/// </summary>
/// <param name="dicValue"></param>
/// <returns></returns>
protected ParameterFields GetParameterFields(Dictionary<string, string> dicValue)
{
ParameterFields fields = new ParameterFields();
foreach (string key in dicValue.Keys)
{
fields.Add(this.CreateParameterField(key, dicValue[key]));
}
return fields;
}
/// <summary>
/// 创建报表参数
/// </summary>
/// <param name="FieldName">参数名</param>
/// <param name="FieldValue">参数值</param>
/// <returns></returns>
private ParameterField CreateParameterField(string FieldName, object FieldValue)
{
ParameterField field = new ParameterField();
ParameterDiscreteValue pvalue = new ParameterDiscreteValue();
pvalue.Value = FieldValue;
field.Name = FieldName;
field.CurrentValues.Add(pvalue);
field.AllowCustomValues = false;
//返回参数字段
return field;
}
public void HideGroupTree(CrystalReportViewer crystalReportViewer)
{
crystalReportViewer.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
}
}