Esempio n. 1
0
        protected virtual IEnumerable GetData()
        {
            if (DataSource != null && IsBoundUsingDataSourceID)
            {
                throw new HttpException("Control bound using both DataSourceID and DataSource properties.");
            }

            if (DataSource != null)
            {
                return(DataSourceResolver.ResolveDataSource(DataSource, DataMember));
            }

            if (!IsBoundUsingDataSourceID)
            {
                return(null);
            }

            IEnumerable result = null;

            DataSourceView boundDataSourceView = ConnectToDataSource();

            boundDataSourceView.Select(DataSourceSelectArguments.Empty, delegate(IEnumerable data) { result = data; });

            return(result);
        }
Esempio n. 2
0
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            DataSourceView view = GetData();

            // view could be null when a user implements his own GetData().
            if (null == view)
            {
                throw new InvalidOperationException(SR.GetString(SR.DataControl_ViewNotFound, ID));
            }

            // DevDiv 1036362: enable async model binding for ListControl
            bool useAsyncSelect = false;

            if (AppSettings.EnableAsyncModelBinding)
            {
                var modelDataView = view as ModelDataSourceView;
                useAsyncSelect = modelDataView != null && modelDataView.IsSelectMethodAsync;
            }

            if (useAsyncSelect)
            {
                _asyncSelectPending = true; // disable post data binding action until the callback is invoked
                view.Select(SelectArguments, OnDataSourceViewSelectCallback);
            }
            else
            {
                IEnumerable data = view.ExecuteSelect(DataSourceSelectArguments.Empty);
                PerformDataBinding(data);
            }
        }
Esempio n. 3
0
        IEnumerable GetData()
        {
            IEnumerable result;

            if (IsBoundUsingDataSourceID)
            {
                if (DataSourceID.Length == 0)
                {
                    return(null);
                }

                if (boundDataSource == null)
                {
                    return(null);
                }

                DataSourceView dsv = boundDataSource.GetView(String.Empty);
                dsv.Select(SelectArguments, new DataSourceViewSelectCallback(SelectCallback));

                result = data;
                data   = null;
            }
            else
            {
                result = DataSourceResolver.ResolveDataSource(DataSource, DataMember);
            }

            return(result);
        }
Esempio n. 4
0
        protected override void OnDataBound(EventArgs e)
        {
            base.OnDataBound(e);
            if (!this.DesignMode)
            {
                ViewState["TotalRowCount"] = 0;

                if (this.PageCount > 1)
                {
                    if (this.SelectArguments.TotalRowCount > -1)
                    {
                        ViewState["TotalRowCount"] = this.SelectArguments.TotalRowCount;
                    }
                }
                else
                {
                    ViewState["TotalRowCount"] = this.Rows.Count;
                }

                if (this.TotalRowCount < 1)
                {
                    IDataSource    IDS = this.GetDataSource();
                    DataSourceView dsv = IDS.GetView(this.DataMember);
                    dsv.Select(DataSourceSelectArguments.Empty, this.SetRowCount);
                }
            }
        }
Esempio n. 5
0
        private void GetSelectedText()
        {
            if (this.DesignMode)
            {
                return;
            }

            if (this.SelectedID == "")
            {
                this.SelectedText = "";
                return;
            }
            if (this.SelectedText != "" && !this.Page.IsCallback)
            {
                return;
            }

            try
            {
                try
                {
                    // call the event
                    GetSeletedItemTextEventArgs e = new GetSeletedItemTextEventArgs();
                    e.SelectedID = this.SelectedID;
                    GetSeletedItemText(this, e);

                    this.SelectedText = e.TextValue;
                }
                catch
                {
                    if (this.DataMember != "")
                    {
                        IDataSource    IDS = this.GetDataSource();
                        DataSourceView dsv = IDS.GetView(this.DataMember);
                        dsv.Select(DataSourceSelectArguments.Empty, this.GetTextFromView);
                    }
                    else
                    {
                        string typeName = this.DataSource.GetType().Name;
                        switch (typeName)
                        {
                        case "DataSet":
                            SetSelectedTextValue(((DataSet)this.DataSource).Tables[0].DefaultView);
                            break;

                        case "DataTable":
                            SetSelectedTextValue(((DataTable)this.DataSource).DefaultView);
                            break;

                        default:
                            SetSelectedTextValue((DataView)this.DataSource);
                            break;
                        }
                    }
                }
            }
            catch
            {}
        }
Esempio n. 6
0
        protected override void PerformSelect()
        {
            if (!IsBoundUsingDataSourceID)
            {
                OnDataBinding(EventArgs.Empty);
            }

            DataSourceView dataSourceView = GetData();

            DataSourceViewSelectCallback callback =
                delegate(IEnumerable data)
            {
                if (IsBoundUsingDataSourceID)
                {
                    OnDataBinding(EventArgs.Empty);
                }
                PerformDataBinding(data);
            };

            if (EnablePaging && dataSourceView.CanPage)
            {
                DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments();
                selectArguments.StartRowIndex = PageSize * PageIndex;
                selectArguments.MaximumRows   = PageSize;
                dataSourceView.Select(selectArguments, callback);
            }
            else
            {
                DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments();
                if (dataSourceView.CanPage)
                {
                    selectArguments.AddSupportedCapabilities(DataSourceCapabilities.None);
                    selectArguments.StartRowIndex = 0;
                    selectArguments.MaximumRows   = Int16.MaxValue;
                }
                dataSourceView.Select(selectArguments, callback);
            }

            RequiresDataBinding = false;
            MarkAsDataBound();

            OnDataBound(EventArgs.Empty);
        }
Esempio n. 7
0
        public DataSet getDataSet()
        {
            DataSourceView tmp_dsv = this.Open();

            tmp_dsv.Select(DataSourceSelectArguments.Empty, do_nada);
            SageCRMDataSourceView s_dsv = (tmp_dsv as SageCRMDataSourceView);
            DataSet newds = new DataSet();

            newds.Tables.Add(s_dsv.data);
            return(newds);
        }
        protected override void PerformSelect()
        {
            if (this.DataSourceID.Length == 0)
            {
                this.OnDataBinding(EventArgs.Empty);
            }
            DataSourceView data = this.GetData();

            this._arguments = this.CreateDataSourceSelectArguments();
            this._ignoreDataSourceViewChanged = true;
            base.RequiresDataBinding          = false;
            this.MarkAsDataBound();
            data.Select(this._arguments, new DataSourceViewSelectCallback(this.OnDataSourceViewSelectCallback));
        }
Esempio n. 9
0
        protected void PerformSelect()
        {
            if (!this.IsBoundUsingDataSourceID)
            {
                this.OnDataBinding(EventArgs.Empty);
            }

            DataSourceView view = GetData();

            if (view != null)
            {
                view.Select(this.SelectArguments, this.OnSelect);
                this.MarkAsDataBound();
            }
        }
Esempio n. 10
0
            /// <summary>
            /// Заполнить спсок DataSourceOther.
            /// </summary>
            public void FillDataSourceOther(int maximumRows)
            {
                var            list     = new List <KeyValuePair <long, string> >();
                DataSourceView view     = DataSource.GetView("default");
                var            baseView = view as BaseDataSourceView <long>;

                if (baseView != null)
                {
                    baseView.CancelTreeUse = true;
                }
                IEnumerable dataSourceData = null;
                var         arguments      = new DataSourceSelectArguments();

                if (maximumRows > 0)
                {
                    arguments.MaximumRows = maximumRows;
                }

                view.Select(arguments, delegate(IEnumerable data) { dataSourceData = data; });
                if (dataSourceData != null)
                {
                    var          enumerator   = dataSourceData.GetEnumerator();
                    PropertyInfo propertyID   = null;
                    PropertyInfo propertyName = null;
                    if (enumerator.MoveNext())
                    {
                        var fieldName = FindHelper.GetContentFieldName("nameRu", "nameKz");
                        var row       = enumerator.Current;
                        propertyID   = row.GetType().GetProperty("id");
                        propertyName = row.GetType().GetProperty(fieldName);
                        list.Add(
                            new KeyValuePair <long, string>(
                                (long)propertyID.GetValue(row, null),
                                (propertyName.GetValue(row, null) ?? string.Empty).ToString()));
                    }

                    while (enumerator.MoveNext())
                    {
                        var row = enumerator.Current;
                        list.Add(
                            new KeyValuePair <long, string>(
                                (long)propertyID.GetValue(row, null),
                                (propertyName.GetValue(row, null) ?? string.Empty).ToString()));
                    }
                }

                DataSourceOther = list;
            }
Esempio n. 11
0
        /// <summary>
        ///  Issues an asynchronous request for data to the data source using the arguments from CreateDataSourceSelectArguments.
        /// </summary>
        protected override void PerformSelect()
        {
            // We need to call OnDataBinding here if we're potentially bound to a DataSource (instead of a DataSourceID)
            // because the databinding statement that is the datasource needs to be evaluated before the call to GetData()
            // happens, because we don't rebind when the datasource is changed unless DataSourceID.Length > 0.
            if (!IsDataBindingAutomatic)
            {
                OnDataBinding(EventArgs.Empty);
            }
            DataSourceView view = GetData();

            _arguments = CreateDataSourceSelectArguments();
            _ignoreDataSourceViewChanged = true;
            RequiresDataBinding          = false;
            MarkAsDataBound();
            view.Select(_arguments, OnDataSourceViewSelectCallback);
        }
Esempio n. 12
0
        protected virtual IEnumerable GetData()
        {
            if (DataSourceID.Length == 0)
            {
                return(null);
            }

            if (boundDataSource == null)
            {
                ConnectToDataSource();
            }

            DataSourceView dsv = boundDataSource.GetView(String.Empty);

            dsv.Select(SelectArguments, new DataSourceViewSelectCallback(SelectCallback));
            return(data);
        }
        /// <summary>
        /// Handles the data binding.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void HandleDataBinding(object sender, EventArgs e)
        {
            Control ctrl = (Control)sender;
            object  val  = GetValue(ctrl.NamingContainer) ?? string.Empty;

            if (data == null)
            {
                //Cache the data from the DataSourceControl, so that we only get the data once.  If
                //we just set the DataSourceID on the dropdown, the select command would get called
                //once for each row.
                DataSourceControl dsc = this.Control.NamingContainer.FindControl(this.DataSourceID) as DataSourceControl;
                DataSourceView    dsv = ((IDataSource)dsc).GetView("DefaultView");
                dsv.Select(DataSourceSelectArguments.Empty, new DataSourceViewSelectCallback(this.DataSourceCallback));
            }

            if (ctrl is EntityDropDownList)
            {
                EntityDropDownList eddl = (EntityDropDownList)ctrl;
                eddl.DataTextField  = this.DataTextField;
                eddl.DataValueField = this.DataValueField;
                eddl.DataSource     = this.data;
                eddl.AppendNullItem = this.AppendNullItem;
            }
            else if (ctrl is Label)
            {
                Label label             = (Label)ctrl;
                EntityDropDownList temp = new EntityDropDownList();
                temp.DataTextField  = this.DataTextField;
                temp.DataValueField = this.DataValueField;
                temp.DataSource     = this.data;
                temp.Visible        = false;
                temp.AppendNullItem = this.AppendNullItem;
                label.Controls.Add(temp);
                temp.DataBind();

                label.Text = String.Empty;
                foreach (ListItem listItem in temp.Items)
                {
                    if (0 == String.Compare(listItem.Value, val.ToString()))
                    {
                        label.Text = listItem.Text;
                    }
                }
            }
        }
Esempio n. 14
0
        private int GetTotalRowCount()
        {
            int            totalRowCount  = 0;
            DataSourceView dataSourceView = GetData();

            if (dataSourceView.CanRetrieveTotalRowCount)
            {
                DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments();
                selectArguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
                selectArguments.RetrieveTotalRowCount = true;
                DataSourceViewSelectCallback callback =
                    delegate
                {
                    totalRowCount = selectArguments.TotalRowCount;
                };
                dataSourceView.Select(selectArguments, callback);
            }
            return(totalRowCount);
        }
Esempio n. 15
0
        /// <summary>
        ///  Issues an asynchronous request for data to the data source using the arguments from CreateDataSourceSelectArguments.
        /// </summary>
        protected override void PerformSelect()
        {
            // We need to call OnDataBinding here if we're potentially bound to a DataSource (instead of a DataSourceID)
            // because the databinding statement that is the datasource needs to be evaluated before the call to GetData()
            // happens, because we don't rebind when the datasource is changed unless DataSourceID.Length > 0.
            if (!IsDataBindingAutomatic)
            {
                OnDataBinding(EventArgs.Empty);
            }
            DataSourceView view = GetData();

            _ignoreDataSourceViewChanged = true;
            RequiresDataBinding          = false;
            MarkAsDataBound();

            // when PerformSelect is called in async method, setting _arguments
            // to a new instance causes�an�exception�deep�in�ListView.
            // Instead, we should use SelectArguments.
            view.Select(SelectArguments, OnDataSourceViewSelectCallback);
        }
Esempio n. 16
0
        protected virtual IEnumerable GetData()
        {
            _selectResult = null;
            DataSourceView view = ConnectToDataSourceView();

            if (view != null)
            {
                Debug.Assert(_currentViewValid);

                // create a handle here to make sure this is a synchronous operation.
                _selectWait = new EventWaitHandle(false, EventResetMode.AutoReset);
                view.Select(SelectArguments, new DataSourceViewSelectCallback(DoSelect));
                _selectWait.WaitOne();
            }
            else if (DataSource != null)
            {
                _selectResult = DataSource as IEnumerable;
            }
            return(_selectResult);
        }
Esempio n. 17
0
        void InitDataSource(IDataSource dataSource, string dataMember)
        {
            DataSourceView view = dataSource.GetView(dataMember);

            view.Select(DataSourceSelectArguments.Empty, data => report.DataSource = data);
        }
Esempio n. 18
0
        public IEnumerable GetData()
        {
            var data = DataSource as IEnumerable;

            if (data != null)
            {
                return(data);
            }

            if (GetCache != null)
            {
                var cache = GetCache();
                if (cache != null)
                {
                    return(cache);
                }
            }

            var            idataSource = DataSource as IDataSource;
            DataSourceView view        = null;

            if (idataSource != null)
            {
                view = idataSource.GetView("Default");
            }
            else if (!string.IsNullOrEmpty(ProjectName) && !string.IsNullOrEmpty(TableName))
            {
                var type = BuildManager.GetType(ProjectName + "." + TableName + "JournalDataSourceView", false, true);
                if (type != null)
                {
                    view = (DataSourceView)Activator.CreateInstance(type);
                }
            }

            if (view != null)
            {
                var baseView = view as IDataSourceView;
                if (baseView != null && SelectedValue != null)
                {
                    baseView.SelectedRowKey = SelectedValue.ToString();
                }

                if (baseView != null && !string.IsNullOrEmpty(SelectMode))
                {
                    data = baseView.GetSelectIRow("mode=" + SelectMode);
                }
                else
                {
                    view.Select(
                        new DataSourceSelectArguments(),
                        delegate(IEnumerable dataSource) { data = dataSource; });
                }

                if (SetCache != null)
                {
                    var result = data.Cast <object>().ToList();
                    SetCache(result);
                    return(result);
                }

                return(data);
            }

            return(null);
        }