您的位置:首页 > 编程语言

水晶报表参数传递代码 同时 可以翻页

2008-12-30 13:56 495 查看

水晶报表参数传递代码

2008-06-10 13:40:00

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared.Interop;
using System.Text;//命名空间
using System.IO;// 命名空间

public partial class zmx_report1 : System.Web.UI.Page
{
    string reportname;
    string title;
    public bool flag = false;//定义一个bool型的变量 为实现翻页做准备

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            flag = true;
        }
        try
        {
            DataSet lds = (DataSet)Session["TmpDataSet"];
            reportname = (string)Session["ReportName"];
            title = (string)Session["Title"];
            if (title == null) title = "";

            //HYC 2007-10-24 传递参数,实现翻页 =============================
            if (this.flag == true)
            {               
                ParameterFields parfs = new ParameterFields();//实例化一个参数集
                ParameterField parf = new ParameterField();//实例化一个参数
                ParameterDiscreteValue pdv = new ParameterDiscreteValue(); //实例化一个参数值
                    parf.Name = "zmx";//参数名
                    pdv.Value = title;//参数值
                    parf.CurrentValues.Add(pdv);//将参数值绑定到具体的参数
                    parfs.Add(parf);//将参数写到参数组
                    CrystalReportViewer1.ParameterFieldInfo = parfs;//将参数传递给水晶报表
            }
            //==================HYC====2007-10-24=============================
              
                ReportDocument ōrpt = new ReportDocument();
               
                if (reportname == "日出勤表") reportname = "RCQB";
                else if (reportname == "考勤时间明细表") reportname = "KQSJMXB";
                else if (reportname == "出勤统计表") reportname = "CQTJB";
                else if (reportname == "个人出勤月明细表")
                {
                    reportname = "GRCQYMXB";
                    orpt.PrintOptions.PaperSize = PaperSize.PaperA3;

                }
                else if (reportname == "个人出勤时长表")
                {
                    reportname = "GRCQSCB";
                    orpt.PrintOptions.PaperSize = PaperSize.PaperA3;
                }
                else if (reportname == "月份考勤簿")
                {
                    reportname = "GRCQSCB";
                    orpt.PrintOptions.PaperSize = PaperSize.PaperA3;
                }
                else if (reportname == "工时报工表") reportname = "GSBGB";
                else if (reportname == "请假明细表") reportname = "QJMXB";
                else if (reportname == "迟到早退表") reportname = "CDZTB";
                orpt.Load(Server.MapPath(@"../Report/" + reportname + ".rpt"));//加载相对应的报表
                orpt.SetDataSource(lds.Tables[0]);//将dataset绑定报表
                //orpt.Refresh();//ZYM 2005-10-25
                CrystalReportViewer1.ReportSource = orpt;
                CrystalReportViewer1.DisplayGroupTree = false;
                //CrystalReportViewer1.RefreshReport();//ZYM 2005-10-25        
          
        }
        catch (Exception ex)
        {
            Response.Write("error");
        }
    }
  
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息