需要文件一個XSD,RPT

在向子報表中傳參數時,要保持子報表和主表里的參數名稱唯一,即使是傳的是同一值時,在報表中也要用同的不同的參數名稱取值

在傳子報表時只是多傳一數據源
    //主要把數據填入報表中

  public void gfunProcRptForm(DataSet dstData, DataSet SubdstData, string strReportName, string strSubReportName, int intPrintType, string strPrintDate, string strDataDate, string strRemark)
    {

        //要有子報表時在這里多new一個報表文檔

        ReportDocument RptDoc = new ReportDocument();//主報表
        ReportDocument SubRptDoc = new ReportDocument();//子報表
        frmProcRptForm.frmProcRptForm RptProcRptForm = new frmProcRptForm.frmProcRptForm();
        ParameterValues ParaValue = new ParameterValues();
        ParameterDiscreteValue ParaDisValue = new ParameterDiscreteValue();
        WS_TrustProile.WS_TrustProile wsTrustProile = new WS_TrustProile.WS_TrustProile();

        string strsubReportFilePath = "";
        string strSourceReportFilePath = "";
        DataSet dstTrustProile;

        strsubReportFilePath = "";
        dstTrustProile = wsTrustProile.GetTrustProfile();

        if (dstTrustProile.Tables[0].Rows.Count > 0)
        {
            if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["subReportFilePath"]))
            {
                strsubReportFilePath = dstTrustProile.Tables[0].Rows[0]["subReportFilePath"].ToString();
            }
            if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["SourceReportFilePath"]))
            {
                strSourceReportFilePath = dstTrustProile.Tables[0].Rows[0]["SourceReportFilePath"].ToString();
            }
            if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["CMPYName"]))
            {
                sysCMPYName = dstTrustProile.Tables[0].Rows[0]["CMPYName"].ToString();
            }
            comGFunction.CopyFileSTOD("rpt" + strReportName + ".rpt", "2", strSourceReportFilePath, strsubReportFilePath);
        }
        RptDoc.Load(strsubReportFilePath + "rpt" + strReportName + ".rpt");
      
        RptDoc.Database.Tables[0].SetDataSource(dstData.Tables[0]);

        //向主報表中添加子報表
        SubRptDoc = RptDoc.Subreports["rpt" + strSubReportName + ".rpt"];

       //添加子報表數據
        SubRptDoc.SetDataSource(SubdstData.Tables [0]);
        //指定報表參數 - lblCMPYName
        ParaDisValue.Value = sysCMPYName;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblCMPYName"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblRemark
        ParaDisValue.Value = strRemark;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblRemark"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblSystemUserName
        ParaDisValue.Value = "(" + sysUserID + ")" + sysUserName;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblSystemUserName"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblReportNo
        ParaDisValue.Value = strReportName;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblReportNo"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblPrintDate
        ParaDisValue.Value = strPrintDate;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblPrintDate"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblDataDate
        ParaDisValue.Value = strDataDate;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblDataDate"].ApplyCurrentValues(ParaValue);
        RptProcRptForm.CReportViewer.ReportSource = RptDoc;


        if (intPrintType == 1)
        {
            RptDoc.PrintToPrinter(1, true, 0, 0);
        }
        else
        {
            RptProcRptForm.ShowDialog();
        }
    }

posted on 2008-09-23 14:31  Blade  阅读(613)  评论(0编辑  收藏  举报