#region 参数构建
        private 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;
        }
        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;
        }
        #endregion
        #region 显示报表
        /// <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, DataSet reportData, string reportFile, CrystalReportViewer reportView)
        {
            //使用报表对象加载报表
            ReportDocument 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;

        }
        public void ShowReport(string[] formularFieldsValue, Dictionary<string, string> dicValue, DataTable reportData, string reportFile, CrystalReportViewer reportView)
        {
            //使用报表对象加载报表
            ReportDocument 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;

        }
        public void ShowReport <T>(string[] formularFieldsValue, Dictionary<string, string> dicValue, List<T> reportData, string reportFile, CrystalReportViewer reportView)
        {
            //使用报表对象加载报表
            ReportDocument 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;

        }
        #endregion

posted on 2011-10-19 12:02  万德源  阅读(495)  评论(0编辑  收藏  举报