コード例 #1
0
        public void LoadFromFile(string path)
        {
            Reset();

            CurrentReportMeta      = ReportMeta.LoadFromFile(path);
            LocalReport.ReportPath = path;

            RefreshReport();
        }
コード例 #2
0
        public void LoadFromResource(string name, Assembly assembly = null)
        {
            Reset();

            CurrentReportMeta = ReportMeta.LoadFromResource(name, assembly);
            LocalReport.ReportEmbeddedResource = name;

            RefreshReport();
        }
コード例 #3
0
        public void Reset()
        {
            if (CurrentReportMeta != null)
            {
                CurrentReportMeta.Dispose();
                CurrentReportMeta = null;
            }

            ReportViewer.Reset();
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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");
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        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");
            }
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        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;
        }