public void ApplyChanges(ReportParameterValues parameterValues) { var labelIndex = c1FlexGrid1.Cols.Fixed; var valueIndex = labelIndex + 1; parameterValues.Clear(); for (int i = 1; i < c1FlexGrid1.Rows.Count; i++) { var row = c1FlexGrid1.Rows[i]; if (row.IsNew) { continue; } var item = new ReportParameterValue(); if (row[labelIndex] != null) { item.Name = row[labelIndex].ToString(); } if (row[valueIndex] != null) { item.Value = (ScriptObjectValue)row[valueIndex].ToString(); } parameterValues.Add(item); } }
private IReport LoadReport(Serialization.Report xmlReport, bool proxy) { AbstractReport report = null; if (proxy) { report = new ReportProxy(); } else { report = new Report(); } report.Id = xmlReport.Id; report.Name = xmlReport.Name; report.Description = xmlReport.Description; if (xmlReport.NewUntilSpecified) { report.IsNew = xmlReport.NewUntil > DateTime.Now; } else { report.IsNew = false; } report.ReportType = (ReportType)Enum.Parse(typeof(ReportType), xmlReport.ReportType.ToString()); if (xmlReport.ReportProcessingLocation.Use.Equals(Serialization.ActiveReportProcessingLocation.LocalReport)) { string directory = ConfigurationManager.AppSettings["FirstLook.Reports.App.ReportDefinitionLibrary.Xml.XmlReportDefinitionFactory.Report.Directory"]; Serialization.LocalReport localReport = xmlReport.ReportProcessingLocation.LocalReport; LocalReportProcessingLocation location = new LocalReportProcessingLocation(); location.File = directory + Path.DirectorySeparatorChar + localReport.File; location.DataSourceName = localReport.DataSourceName; report.ReportProcessingLocation = location; } else { string serverUrl = ConfigurationManager.AppSettings["FirstLook.Reports.App.ReportDefinitionLibrary.Xml.XmlReportDefinitionFactory.Report.ServerUrl"]; Serialization.ServerReport serverReport = xmlReport.ReportProcessingLocation.ServerReport; RemoteReportProcessingLocation location = new RemoteReportProcessingLocation(); location.Path = serverReport.Path; location.ServerUrl = new Uri(serverUrl); report.ReportProcessingLocation = location; } IList <IReportParameter> reportParameters = new List <IReportParameter>(); if (xmlReport.Parameters != null && xmlReport.Parameters.Length > 0) { foreach (Serialization.Parameter xmlParameter in xmlReport.Parameters) { ReportParameter reportParameter = new ReportParameter(); reportParameter.AllowBlank = xmlParameter.AllowBlank; reportParameter.AllowNull = xmlParameter.AllowNull; reportParameter.Label = xmlParameter.Label; reportParameter.Name = xmlParameter.Name; reportParameter.ReportParameterDataType = (ReportParameterDataType)Enum.Parse(typeof(ReportParameterDataType), xmlParameter.ParameterDataType.ToString()); reportParameter.ReportParameterInputType = (ReportParameterInputType)Enum.Parse(typeof(ReportParameterInputType), xmlParameter.ParameterInputType.ToString()); AbstractReportParameterValues reportParameterValues = new ReportParameterValuesConstant(); if (xmlParameter.ValidValues != null) { if (xmlParameter.ValidValues.Item is Serialization.ParameterRange) { Serialization.ParameterRange xmlParameterRange = (Serialization.ParameterRange)xmlParameter.ValidValues.Item; if (xmlParameterRange.Item is Serialization.DateRange) { Serialization.DateRange xmlDateRange = xmlParameterRange.Item; DateRange dateRange = new DateRange(); dateRange.InitialUnit = (TimeUnit)Enum.Parse(typeof(TimeUnit), xmlDateRange.InitialUnit.ToString()); dateRange.InitialDistance = Int32.Parse(xmlDateRange.InitialDistance); dateRange.DistanceUnit = (TimeUnit)Enum.Parse(typeof(TimeUnit), xmlDateRange.DistanceUnit.ToString());; dateRange.Distance = Int32.Parse(xmlDateRange.Distance); dateRange.NumberOfItems = Int32.Parse(xmlDateRange.NumberOfItems); dateRange.Direction = (TimeDirection)Enum.Parse(typeof(TimeDirection), xmlDateRange.Direction.ToString()); Serialization.DateTimeFormatInfo xmlDtfi = xmlDateRange.DateTimeFormatInfo; System.Globalization.DateTimeFormatInfo dtfi = new System.Globalization.DateTimeFormatInfo(); if (!string.IsNullOrEmpty(xmlDtfi.FullDateTimePattern)) { dtfi.FullDateTimePattern = xmlDtfi.FullDateTimePattern; } if (!string.IsNullOrEmpty(xmlDtfi.LongDatePattern)) { dtfi.LongDatePattern = xmlDtfi.LongDatePattern; } if (!string.IsNullOrEmpty(xmlDtfi.LongTimePattern)) { dtfi.LongTimePattern = xmlDtfi.LongTimePattern; } if (!string.IsNullOrEmpty(xmlDtfi.MonthDayPattern)) { dtfi.MonthDayPattern = xmlDtfi.MonthDayPattern; } if (!string.IsNullOrEmpty(xmlDtfi.ShortDatePattern)) { dtfi.ShortDatePattern = xmlDtfi.ShortDatePattern; } if (!string.IsNullOrEmpty(xmlDtfi.ShortTimePattern)) { dtfi.ShortTimePattern = xmlDtfi.ShortTimePattern; } if (!string.IsNullOrEmpty(xmlDtfi.YearMonthPattern)) { dtfi.YearMonthPattern = xmlDtfi.YearMonthPattern; } int index = 0, selectedIndex = Int32.Parse(xmlDateRange.SelectedIndex); foreach (DateTime value in dateRange.Items()) { ReportParameterValue reportParameterValue = new ReportParameterValue(); reportParameterValue.Label = value.ToString(xmlDateRange.LabelDateTimeFormatSpecifier.ToString(), dtfi); reportParameterValue.Value = value.ToString(xmlDateRange.ValueDateTimeFormatSpecifier.ToString(), dtfi); reportParameterValue.Selected = (index++ == selectedIndex); reportParameterValues.AddReportParameterValue(reportParameterValue); } } else { // ADD NEW RANGE ELEMENT CODE HERE } } else if (xmlParameter.ValidValues.Item is Serialization.DomainModel) { Serialization.DomainModel xmlDomainModel = (Serialization.DomainModel)xmlParameter.ValidValues.Item; IDictionary <string, string> parameterLabelValuePair = new Dictionary <string, string>(); parameterLabelValuePair.Add("Label", xmlDomainModel.Label.Name); parameterLabelValuePair.Add("Value", xmlDomainModel.Value.Name); reportParameterValues = new ReportParameterValuesDynamic(Type.GetType(xmlDomainModel.DomainModelName), xmlDomainModel.InvokeMethod.MethodName, parameterLabelValuePair); foreach (Serialization.MethodArgument argument in xmlDomainModel.InvokeMethod.Arguments) { ((ReportParameterValuesDynamic)reportParameterValues).AddMethodArgumentEntry(argument.Name, Type.GetType(argument.Type), argument.Value, argument.Source.ToString()); } IList <IReportParameterValue> staticParameterValues = new List <IReportParameterValue>(); if (xmlDomainModel.CustomValues != null) { int index = System.Int32.Parse(xmlDomainModel.CustomValues.Insert.Index); foreach (Serialization.ParameterValue parameterValue in xmlDomainModel.CustomValues.Insert.ParameterValue) { ReportParameterValue reportParameterValue = new ReportParameterValue(); reportParameterValue.Label = parameterValue.Label; reportParameterValue.Value = parameterValue.Value; reportParameterValue.Selected = parameterValue.Selected; staticParameterValues.Add(reportParameterValue); } } bool itemSelected = false; // this logic is build on the assumption you can only preselect custom fields - is this a safe assumption? if (xmlDomainModel.Selected != null) { if (xmlDomainModel.Selected.Index != null) { ((ReportParameterValue)staticParameterValues[System.Int32.Parse(xmlDomainModel.Selected.Index)]).Selected = true; itemSelected = true; } if (xmlDomainModel.Selected.Value != null) { foreach (ReportParameterValue x in staticParameterValues) { if (x.Value.Equals(xmlDomainModel.Selected.Value)) { x.Selected = true; itemSelected = true; break; } } } } if (!itemSelected) { if (staticParameterValues.Count > 0) { ((ReportParameterValue)staticParameterValues[0]).Selected = true; } } reportParameterValues.AddReportParameterValues(staticParameterValues); } else // ReportDefinitionLibrary.Xml.ParameterValues { Serialization.ParameterValue[] xmlParameterValues = (Serialization.ParameterValue[])xmlParameter.ValidValues.Item; foreach (Serialization.ParameterValue parameterValue in xmlParameterValues) { ReportParameterValue reportParameterValue = new ReportParameterValue(); reportParameterValue.Label = parameterValue.Label; reportParameterValue.Value = parameterValue.Value; reportParameterValue.Selected = parameterValue.Selected; reportParameterValues.AddReportParameterValue(reportParameterValue); } } } reportParameter.ReportParameterValues = reportParameterValues; reportParameters.Add(reportParameter); } } report.ReportParameters = reportParameters; if (!proxy) { // Work against the RDL to extract data sources and verify parameters IList <IReportDataSource> dataSources = new List <IReportDataSource>(); if (report.ReportProcessingLocation is LocalReportProcessingLocation) { string filename = ((LocalReportProcessingLocation)report.ReportProcessingLocation).File; FirstLook.Reports.App.ReportDefinitionLibrary.ReportDefinitionLanguage.Report rdl = ReportDefinitionLanguageFacade.LoadReport(filename); ReportDefinitionLanguageFacade.PopulateReportDataSources((Report)report, rdl); ReportDefinitionLanguageFacade.VerifyReportParameters((Report)report, rdl); } } return(report); }
/// check parameters prompting user for missing ones /// </summary> /// <param name="parameterNamesToValueMap"></param> /// <returns>true if can continue</returns> public bool ValidateParameters(Dictionary <string, List <ReportParameterValue> > parameterNamesToValueMap) { List <ParameterField> missingParamList = new List <ParameterField>(); //loop thru parameters in crystal doc looking //for them in the paramNameValueMap foreach (ParameterField paramField in this.reportDocument.ParameterFields) { List <ReportParameterValue> objList; parameterNamesToValueMap.TryGetValue(paramField.Name, out objList); if (objList == null || objList.Count == 0) { missingParamList.Add((ParameterField)paramField.Clone()); } } //nithing is missing if (missingParamList.Count == 0) { return(true); } //prepare crystal prompting dialog to prompt user //for values. !!!RM their prompting dlg is messy probably need to do something else ParameterFields parameterFieldInfo = new ParameterFields(); foreach (ParameterField missingField in missingParamList) { parameterFieldInfo.Add(missingField); } PromptingDialog dialog = new PromptingDialog(); if (dialog.DoModal(null, parameterFieldInfo) == -1) { //user canceled the dialog so cannot continue return(false); } //fill the missing fields entered in the dialog into //the crystal document foreach (ParameterField missingField in missingParamList) { ParameterRangeValue rangeValue = missingField.CurrentValues[0] as ParameterRangeValue; ParameterDiscreteValue discreteValue = missingField.CurrentValues[0] as ParameterDiscreteValue; if (rangeValue != null) { List <ReportParameterValue> objList = new List <ReportParameterValue>(); ReportParameterValue paramVal = new ReportParameterValue(rangeValue.StartValue, null); paramVal.IsRange = true; paramVal.EndValue = rangeValue.EndValue; objList.Add(paramVal); parameterNamesToValueMap[missingField.Name] = objList; } else { List <ReportParameterValue> objList = new List <ReportParameterValue>(); objList.Add(new ReportParameterValue(discreteValue.Value, null)); parameterNamesToValueMap[missingField.Name] = objList; } } //ok to continue with report generation since all fields are found return(true); }