Ejemplo n.º 1
0
        public override string GetDesignTimeHtml()
        {
            IEnumerable selectedDataSource = null;
            bool        templatesExist     = this.TemplatesExist;
            Repeater    viewControl        = (Repeater)base.ViewControl;

            if (templatesExist)
            {
                DesignerDataSourceView designerView         = this.DesignerView;
                IEnumerable            designTimeDataSource = null;
                bool   flag2        = false;
                string dataSourceID = string.Empty;
                if (designerView == null)
                {
                    selectedDataSource   = this.GetResolvedSelectedDataSource();
                    designTimeDataSource = this.GetDesignTimeDataSource(selectedDataSource, 5);
                }
                else
                {
                    try
                    {
                        bool flag3;
                        designTimeDataSource = designerView.GetDesignTimeData(5, out flag3);
                    }
                    catch (Exception exception)
                    {
                        if (base.Component.Site != null)
                        {
                            IComponentDesignerDebugService service = (IComponentDesignerDebugService)base.Component.Site.GetService(typeof(IComponentDesignerDebugService));
                            if (service != null)
                            {
                                service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.GetDesignTimeData", exception.Message }));
                            }
                        }
                    }
                }
                try
                {
                    viewControl.DataSource   = designTimeDataSource;
                    dataSourceID             = viewControl.DataSourceID;
                    viewControl.DataSourceID = string.Empty;
                    flag2 = true;
                    viewControl.DataBind();
                    return(base.GetDesignTimeHtml());
                }
                catch (Exception exception2)
                {
                    return(this.GetErrorDesignTimeHtml(exception2));
                }
                finally
                {
                    viewControl.DataSource = null;
                    if (flag2)
                    {
                        viewControl.DataSourceID = dataSourceID;
                    }
                }
            }
            return(this.GetEmptyDesignTimeHtml());
        }
        protected virtual IEnumerable GetDesignTimeDataSource()
        {
            bool                   flag;
            IEnumerable            designTimeData = null;
            DesignerDataSourceView designerView   = this.DesignerView;

            if (designerView != null)
            {
                try
                {
                    designTimeData = designerView.GetDesignTimeData(this.SampleRowCount, out flag);
                }
                catch (Exception exception)
                {
                    if (base.Component.Site != null)
                    {
                        IComponentDesignerDebugService service = (IComponentDesignerDebugService)base.Component.Site.GetService(typeof(IComponentDesignerDebugService));
                        if (service != null)
                        {
                            service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.GetDesignTimeData", exception.Message }));
                        }
                    }
                }
            }
            else
            {
                IEnumerable resolvedSelectedDataSource = ((IDataSourceProvider)this).GetResolvedSelectedDataSource();
                if (resolvedSelectedDataSource != null)
                {
                    designTimeData = DesignTimeData.GetDesignTimeDataSource(DesignTimeData.CreateSampleDataTable(resolvedSelectedDataSource), this.SampleRowCount);
                    flag           = true;
                }
            }
            if (designTimeData != null)
            {
                ICollection is2 = designTimeData as ICollection;
                if ((is2 == null) || (is2.Count > 0))
                {
                    return(designTimeData);
                }
            }
            flag = true;
            return(this.GetSampleDataSource());
        }
        public override string GetDesignTimeHtml()
        {
            bool templatesExist = this.TemplatesExist;

            if (templatesExist)
            {
                IEnumerable            designTimeDataSource;
                DataList               viewControl     = (DataList)base.ViewControl;
                bool                   dummyDataSource = false;
                DesignerDataSourceView designerView    = base.DesignerView;
                if (designerView == null)
                {
                    designTimeDataSource = base.GetDesignTimeDataSource(5, out dummyDataSource);
                }
                else
                {
                    try
                    {
                        designTimeDataSource = designerView.GetDesignTimeData(5, out dummyDataSource);
                    }
                    catch (Exception exception)
                    {
                        if (base.Component.Site != null)
                        {
                            IComponentDesignerDebugService service = (IComponentDesignerDebugService)base.Component.Site.GetService(typeof(IComponentDesignerDebugService));
                            if (service != null)
                            {
                                service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.GetDesignTimeData", exception.Message }));
                            }
                        }
                        designTimeDataSource = null;
                    }
                }
                bool   flag3        = false;
                string dataKeyField = null;
                bool   flag4        = false;
                string dataSourceID = null;
                try
                {
                    viewControl.DataSource = designTimeDataSource;
                    dataKeyField           = viewControl.DataKeyField;
                    if (dataKeyField.Length != 0)
                    {
                        flag3 = true;
                        viewControl.DataKeyField = string.Empty;
                    }
                    dataSourceID             = viewControl.DataSourceID;
                    viewControl.DataSourceID = string.Empty;
                    flag4 = true;
                    viewControl.DataBind();
                    return(base.GetDesignTimeHtml());
                }
                catch (Exception exception2)
                {
                    return(this.GetErrorDesignTimeHtml(exception2));
                }
                finally
                {
                    viewControl.DataSource = null;
                    if (flag3)
                    {
                        viewControl.DataKeyField = dataKeyField;
                    }
                    if (flag4)
                    {
                        viewControl.DataSourceID = dataSourceID;
                    }
                }
            }
            return(this.GetEmptyDesignTimeHtml());
        }
        public override string GetDesignTimeHtml()
        {
            int      minimumRows = 5;
            DataGrid viewControl = (DataGrid)base.ViewControl;

            if (viewControl.AllowPaging && (viewControl.PageSize != 0))
            {
                minimumRows = Math.Min(viewControl.PageSize, 100) + 1;
            }
            bool                   dummyDataSource      = false;
            IEnumerable            designTimeDataSource = null;
            bool                   flag2               = false;
            bool                   flag3               = false;
            bool                   flag4               = false;
            DesignerDataSourceView designerView        = base.DesignerView;
            bool                   autoGenerateColumns = viewControl.AutoGenerateColumns;
            string                 dataKeyField        = string.Empty;
            string                 dataSourceID        = string.Empty;
            string                 designTimeHtml      = null;

            if (designerView == null)
            {
                designTimeDataSource = base.GetDesignTimeDataSource(minimumRows, out dummyDataSource);
            }
            else
            {
                try
                {
                    designTimeDataSource = designerView.GetDesignTimeData(minimumRows, out dummyDataSource);
                }
                catch (Exception exception)
                {
                    if (base.Component.Site != null)
                    {
                        IComponentDesignerDebugService service = (IComponentDesignerDebugService)base.Component.Site.GetService(typeof(IComponentDesignerDebugService));
                        if (service != null)
                        {
                            service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.GetDesignTimeData", exception.Message }));
                        }
                    }
                }
                if (designTimeDataSource == null)
                {
                    return(this.GetEmptyDesignTimeHtml());
                }
            }
            if (!autoGenerateColumns && (viewControl.Columns.Count == 0))
            {
                flag2 = true;
                viewControl.AutoGenerateColumns = true;
            }
            if (dummyDataSource)
            {
                dataKeyField = viewControl.DataKeyField;
                if (dataKeyField.Length != 0)
                {
                    flag3 = true;
                    viewControl.DataKeyField = string.Empty;
                }
            }
            try
            {
                viewControl.DataSource   = designTimeDataSource;
                dataSourceID             = viewControl.DataSourceID;
                viewControl.DataSourceID = string.Empty;
                flag4 = true;
                viewControl.DataBind();
                designTimeHtml = base.GetDesignTimeHtml();
            }
            catch (Exception exception2)
            {
                designTimeHtml = this.GetErrorDesignTimeHtml(exception2);
            }
            finally
            {
                viewControl.DataSource = null;
                if (flag2)
                {
                    viewControl.AutoGenerateColumns = false;
                }
                if (flag3)
                {
                    viewControl.DataKeyField = dataKeyField;
                }
                if (flag4)
                {
                    viewControl.DataSourceID = dataSourceID;
                }
            }
            return(designTimeHtml);
        }
Ejemplo n.º 5
0
            private void RegisterData(WebReport webreport, Report report, IServiceProvider provider)
            {
                string[] dataSources = webreport.ReportDataSources.Split(new char[] { ';' });
                foreach (string dataSource in dataSources)
                {
                    IDataSource ds = FindControlRecursive(webreport.Page, dataSource) as IDataSource;
                    if (ds == null)
                    {
                        continue;
                    }
                    string dataName = (ds as Control).ID;

                    // at design time, use design time data view
                    if (provider != null)
                    {
                        if (ds is AccessDataSource)
                        {
                            // for MS Access data source, try to convert relative DataFile path.
                            // This is needed to avoid the exception when access the database in the design time.
                            AccessDataSource accessDs     = ds as AccessDataSource;
                            string           saveDataFile = accessDs.DataFile;
                            try
                            {
                                accessDs.DataFile = MapPath(provider, accessDs.DataFile);
                                webreport.RegisterDataAsp(report, accessDs, accessDs.ID);
                            }
                            finally
                            {
                                accessDs.DataFile = saveDataFile;
                            }
                        }
                        else
                        {
                            object[] attrs = ds.GetType().GetCustomAttributes(typeof(DesignerAttribute), false);
                            if (attrs != null && attrs.Length == 1)
                            {
                                DesignerAttribute  designerAttr = attrs[0] as DesignerAttribute;
                                DataSourceDesigner dsDesigner   = Activator.CreateInstance(Type.GetType(designerAttr.DesignerTypeName)) as DataSourceDesigner;

                                try
                                {
                                    dsDesigner.Initialize(ds as IComponent);
                                    dsDesigner.RefreshSchema(false);

                                    DesignerDataSourceView view = dsDesigner.GetView("");
                                    bool        isSampleData    = false;
                                    IEnumerable data            = view.GetDesignTimeData(10, out isSampleData);
                                    webreport.RegisterDataAsp(report, data, dataName);
                                }
                                finally
                                {
                                    dsDesigner.Dispose();
                                }
                            }
                        }
                    }
                    else
                    {
                        webreport.RegisterDataAsp(report, ds, dataName);
                    }
                }
            }