Beispiel #1
0
        private WebForms.ReportDataSource GetReportDataSource(RDL.Report reportDef, RDL.DataSet ds)
        {
            //copy the parameters from the QueryString into the ReportParameters definitions (objects)
            var parameters = CurrentReportViewer.LocalReport.GetParameters();

            ds.AssignParameters(parameters);

            var dataSource = reportDef.DataSources.Find(d => d.Name == ds.Query.DataSourceName);

            //run the query to get real data for the report
            System.Data.DataTable tbl = ds.GetDataTable(dataSource.ConnectionProperties.ConnectString);

            //attach the data/table to the Report's dataset(s), by name
            //This refers to the dataset name in the RDLC file
            return(new WebForms.ReportDataSource
            {
                Name = ds.Name,
                Value = tbl
            });
        }
Beispiel #2
0
        private DataTable GetData(string parameterName, string dataSourceName)
        {
            FileInfo reportFullPath = this.ReportFile;

            //check to make sure the file ACTUALLY exists, before we start working on it
            if (reportFullPath == null)
            {
                return(null);
            }

            var errorMessages = new List <ErrorMessage>();

            //map the reporting engine to the .rdl/.rdlc file
            LoadReportDefinitionFile(CurrentReportViewer.LocalReport, reportFullPath);

            // Look-up the DB query in the "DataSets" element of the report file (.rdl/.rdlc which contains XML)
            RDL.Report reportDef = this.ReportDefinition;
            CheckReportParameters(CurrentReportViewer.LocalReport);

            var parameter = reportDef.ReportParameters.FirstOrDefault(p => p.Name.Equals(parameterName));

            if (parameter == null)
            {
                ReportSingleErroMessage($"The parameter {parameterName } was not found in report {ReportName}");
                return(null);
            }
            // Run each query (usually, there is only one) and attach each to the report
            var validValue = parameter.ValidValues.FirstOrDefault(v => v.DataSetName.Equals(dataSourceName));

            if (validValue == null)
            {
                ReportSingleErroMessage($"The parameter {parameterName } has no valid DataSetName ({dataSourceName}) for report {ReportName}");
                return(null);
            }
            RDL.DataSet ds = parameter.ValidValues.FirstOrDefault().DataSet;

            WebForms.ReportDataSource rds = GetReportDataSource(reportDef, ds);
            return((DataTable)rds.Value);
        }