public void LoadFromFile(string path) { Reset(); CurrentReportMeta = ReportMeta.LoadFromFile(path); LocalReport.ReportPath = path; RefreshReport(); }
public void LoadFromResource(string name, Assembly assembly = null) { Reset(); CurrentReportMeta = ReportMeta.LoadFromResource(name, assembly); LocalReport.ReportEmbeddedResource = name; RefreshReport(); }
public void Reset() { if (CurrentReportMeta != null) { CurrentReportMeta.Dispose(); CurrentReportMeta = null; } ReportViewer.Reset(); }
public void Initialize(RdlDataSource dataSourceElement, ReportMeta reportMeta) { DataSourceElement = dataSourceElement; ReportMeta = reportMeta; IsTransactional = LocalReportsEngineCommon.StringToBool(dataSourceElement.Transaction); string factoryName; lock (DbFactoryNames) if (!DbFactoryNames.TryGetValue(dataSourceElement.ConnectionProperties.DataProvider, out factoryName)) { throw new ArgumentOutOfRangeException("dataSourceElement", "ConnectionProperties.DataProvider is unknown"); } var providerFactory = DbProviderFactories.GetFactory(factoryName); var connectionString = CreateConnectionString(dataSourceElement, providerFactory); AdHocConnection = CreateConnection(providerFactory, connectionString); TransactionConnection = IsTransactional ? CreateConnection(providerFactory, connectionString) : null; }
public static object PhraseToValue(ReportMeta reportMeta, RdlDataTypeEnum dataType, string phrase) { string expression; if (IsExpression(phrase, out expression)) { return(reportMeta.ReportExpressionEvaluator.Evaluate(expression)); } switch (dataType) { case RdlDataTypeEnum.String: return(phrase); case RdlDataTypeEnum.Boolean: return(Boolean.Parse(phrase)); case RdlDataTypeEnum.Integer: return(Int32.Parse(phrase)); case RdlDataTypeEnum.DateTime: return(DateTime.Parse(phrase, CultureInfo.GetCultureInfo("en-US"))); case RdlDataTypeEnum.Float: return(Single.Parse(phrase)); case RdlDataTypeEnum.Binary: throw new NotImplementedException(); case RdlDataTypeEnum.Variant: return(phrase); case RdlDataTypeEnum.VariantArray: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException("dataType"); } }
internal static ReportParameter ElementToObject(RdlReportParameter reportParameterElement, ReportMeta reportMeta) { if (reportParameterElement == null) { throw new ArgumentNullException("reportParameterElement"); } if (reportMeta == null) { throw new ArgumentNullException("reportMeta"); } var reportParameter = new ReportParameter(); reportParameter.DataType = StringToDataTypeEnum(reportParameterElement.DataType); reportParameter.MultiValue = StringToBool(reportParameterElement.MultiValue); // Load available values var validValues = reportParameterElement.ValidValues; if (validValues != null) { var parameterValues = validValues.ParameterValues; var dataSetReference = validValues.DataSetReference; // Explicit list if (parameterValues != null) { var values = from parameterValue in parameterValues select new Tuple <string, object>( parameterValue.Label, PhraseToValue(reportMeta, reportParameter.DataType, parameterValue.Value)); reportParameter.AvailableValues = values.ToArray(); } else if (dataSetReference != null) { // TODO: Datasets etc throw new NotImplementedException(); } } // Load default values var defaultValues = reportParameterElement.DefaultValue; if (defaultValues != null) { var values = defaultValues.Values; var dataSetReference = defaultValues.DataSetReference; // Explicit list if (values != null) { reportParameter.DefaultValues = (from value in values select PhraseToValue(reportMeta, reportParameter.DataType, value)).ToArray(); } else if (dataSetReference != null) { // TODO: Datasets etc throw new NotImplementedException(); } } return(reportParameter); }
internal static IResolvedDataSource ElementToObject(RdlDataSource dataSourceElement, ReportMeta reportMeta) { if (dataSourceElement.ConnectionProperties == null) { // Probably a data source reference. The user should resolve these themselves. // But if not, give them a null object. If it's never referenced, there's no problem. return(null); } if (dataSourceElement.ConnectionProperties == null) { // Again, if there's no connection string the user should have resolved // this data source themselves. But if not, give them a null object. return(null); } Type resolverType; lock (DataSourceResolvers) if (!DataSourceResolvers.TryGetValue(dataSourceElement.ConnectionProperties.DataProvider, out resolverType)) { return(null); } IResolvedDataSource resolved = null; try { resolved = (IResolvedDataSource)Activator.CreateInstance(resolverType); resolved.Initialize(dataSourceElement, reportMeta); } catch (Exception) { if (resolved != null) { resolved.Dispose(); } throw; } return(resolved); }
public void Initialize(RdlDataSource dataSourceElement, ReportMeta reportMeta) { DataSourceElement = dataSourceElement; ReportMeta = reportMeta; IsTransactional = LocalReportsEngineCommon.StringToBool(dataSourceElement.Transaction); string factoryName; lock (DbFactoryNames) if (!DbFactoryNames.TryGetValue(dataSourceElement.ConnectionProperties.DataProvider, out factoryName)) throw new ArgumentOutOfRangeException("dataSourceElement", "ConnectionProperties.DataProvider is unknown"); var providerFactory = DbProviderFactories.GetFactory(factoryName); var connectionString = CreateConnectionString(dataSourceElement, providerFactory); AdHocConnection = CreateConnection(providerFactory, connectionString); TransactionConnection = IsTransactional ? CreateConnection(providerFactory, connectionString) : null; }
public static object PhraseToValue(ReportMeta reportMeta, RdlDataTypeEnum dataType, string phrase) { string expression; if (IsExpression(phrase, out expression)) return reportMeta.ReportExpressionEvaluator.Evaluate(expression); switch(dataType) { case RdlDataTypeEnum.String: return phrase; case RdlDataTypeEnum.Boolean: return Boolean.Parse(phrase); case RdlDataTypeEnum.Integer: return Int32.Parse(phrase); case RdlDataTypeEnum.DateTime: return DateTime.Parse(phrase, CultureInfo.GetCultureInfo("en-US")); case RdlDataTypeEnum.Float: return Single.Parse(phrase); case RdlDataTypeEnum.Binary: throw new NotImplementedException(); case RdlDataTypeEnum.Variant: return phrase; case RdlDataTypeEnum.VariantArray: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException("dataType"); } }
internal static IResolvedDataSource ElementToObject(RdlDataSource dataSourceElement, ReportMeta reportMeta) { if (dataSourceElement.ConnectionProperties == null) // Probably a data source reference. The user should resolve these themselves. // But if not, give them a null object. If it's never referenced, there's no problem. return null; if (dataSourceElement.ConnectionProperties == null) // Again, if there's no connection string the user should have resolved // this data source themselves. But if not, give them a null object. return null; Type resolverType; lock (DataSourceResolvers) if (!DataSourceResolvers.TryGetValue(dataSourceElement.ConnectionProperties.DataProvider, out resolverType)) return null; IResolvedDataSource resolved = null; try { resolved = (IResolvedDataSource) Activator.CreateInstance(resolverType); resolved.Initialize(dataSourceElement, reportMeta); } catch (Exception) { if (resolved != null) resolved.Dispose(); throw; } return resolved; }
internal static ReportParameter ElementToObject(RdlReportParameter reportParameterElement, ReportMeta reportMeta) { if (reportParameterElement == null) throw new ArgumentNullException("reportParameterElement"); if (reportMeta == null) throw new ArgumentNullException("reportMeta"); var reportParameter = new ReportParameter(); reportParameter.DataType = StringToDataTypeEnum(reportParameterElement.DataType); reportParameter.MultiValue = StringToBool(reportParameterElement.MultiValue); // Load available values var validValues = reportParameterElement.ValidValues; if (validValues != null) { var parameterValues = validValues.ParameterValues; var dataSetReference = validValues.DataSetReference; // Explicit list if (parameterValues != null) { var values = from parameterValue in parameterValues select new Tuple<string, object>( parameterValue.Label, PhraseToValue(reportMeta, reportParameter.DataType, parameterValue.Value)); reportParameter.AvailableValues = values.ToArray(); } else if(dataSetReference != null) { // TODO: Datasets etc throw new NotImplementedException(); } } // Load default values var defaultValues = reportParameterElement.DefaultValue; if (defaultValues != null) { var values = defaultValues.Values; var dataSetReference = defaultValues.DataSetReference; // Explicit list if (values != null) { reportParameter.DefaultValues = (from value in values select PhraseToValue(reportMeta, reportParameter.DataType, value)).ToArray(); } else if (dataSetReference != null) { // TODO: Datasets etc throw new NotImplementedException(); } } return reportParameter; }