/// <summary> /// Gets information about requireFields and parameters of the report /// </summary> /// <param name="generationParameter">Description of all reports</param> /// <param name="generationItem">Description of the report to generate</param> /// <param name="requiredFieldNames">hashset of fieldname that are used in the report</param> /// <param name="parameterNamesToValueMap">dictionary of parameters and values</param> public void PopulateReportConfiguration(ReportGenerationParameter generationParameter, ReportGenerationItem generationItem, HashSet <string> requiredFieldNames, Dictionary <string, List <ReportParameterValue> > parameterNamesToValueMap) { if (String.IsNullOrEmpty(generationItem.TemplatePath) || !generationItem.TemplatePath.EndsWith(".rpt")) { return; } this.generationItem = generationItem; this.reportDocument = new ReportDocument(); this.reportDocument.Load(generationItem.TemplatePath); this.reportDocList = new List <ReportDocument>(); reportDocList.Add(reportDocument); //find fieldnames for this document FindReportFields(reportDocument, requiredFieldNames); //find documens and fieldNames in subReports WalkSubReports(reportDocument.ReportDefinition.Sections, reportDocList, requiredFieldNames); //!!! RM need to deal with lists of items .for defaults until then not filling in report's //default values foreach (ParameterField paramField in reportDocument.ParameterFields) { List <ReportParameterValue> valuesList = new List <ReportParameterValue>(); foreach (ParameterValue curVal in paramField.CurrentValues) { //TODO: !!!RM need to change paramter value to a system type and not use the crystal type valuesList.Add(new ReportParameterValue(curVal, null)); } parameterNamesToValueMap[paramField.Name] = valuesList; } }
/// <summary> /// Sets up the report based on the generationItem and configureArgs. may or may not build the report /// </summary> /// <param name="generationItem">Description of the report to generate</param> /// <param name="configureArgs">report instance data</param> public void ConfigureReport(ReportGenerationItem generationItem, ReportGetDataSourceEventArgs getDataSourceArgs, Dictionary <string, List <ReportParameterValue> > parameterNamesToValueMap) { //get the configuration args this.getDataSourceArgs = getDataSourceArgs; this.parameterNamesToValueMap = parameterNamesToValueMap; //need to set source before seting params foreach (ReportDocument doc in this.reportDocList) { doc.SetDataSource(this.getDataSourceArgs.DataSource); } //loop thru parameters that are set and set them into the crystal documnet foreach (ParameterField paramField in reportDocument.ParameterFields) { ParameterValues currentParameterValues = new ParameterValues(); List <ReportParameterValue> objList; this.parameterNamesToValueMap.TryGetValue(paramField.Name, out objList); //convert all the data to a string and let crystal covert it to its known type for (int i = 0; i < objList.Count; i++) { object val = objList[i].Value; if (val == null) { continue; } object convertedObject = null; convertedObject = val.ToString(); objList[i].Value = convertedObject; if (objList[i].EndValue != null) { objList[i].EndValue = objList[i].EndValue.ToString(); } } //create single or range crystal values foreach (ReportParameterValue paramVal in objList) { if (paramVal.IsRange == false) { ParameterDiscreteValue pv = new ParameterDiscreteValue(); pv.Value = paramVal.Value; currentParameterValues.Add(pv); } else { ParameterRangeValue pv = new ParameterRangeValue(); pv.StartValue = paramVal.Value; pv.EndValue = paramVal.EndValue; currentParameterValues.Add(pv); } } //apply the newly set parameter values to the document so they will be used in the generation ParameterFieldDefinitions parameterFieldDefinitions = reportDocument.DataDefinition.ParameterFields; ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions[paramField.Name]; parameterFieldDefinition.ApplyCurrentValues(currentParameterValues); } }