Esempio n. 1
0
        /// <summary>
        /// Internals the bind.
        /// </summary>
        private void internalBind()
        {
            MetaClass mc = Mediachase.Ibn.Core.MetaDataWrapper.GetMetaClassByName(ClassName);

            MainGrid.Columns.Clear();

            MainGrid.AllowPaging = true;

            if (!ShowPaging)
            {
                MainGridExt.BottomHeight = 1;
                SetPageSize(-1);
            }
            else
            {
                MainGridExt.BottomHeight = 30;
                MainGrid.PageSize = GetPageSize();
            }

            int width = 0;

            if (this.ShowCheckboxes)
                width += 22 + 7;

            foreach (EntityGridCustomColumnInfo customColumn in this.CustomColumns)
            {
                MainGrid.Columns.Add(customColumn.Column);
                width += customColumn.Width + 7;
            }

            int counter = 0;
            foreach (EntityFieldInfo field in this.VisibleMetaFields)
            {
                if (PlaceName == String.Empty)
                    MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetColumn(this.Page, field.Field));
                else
                    MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetColumn(this.Page, field.Field, PlaceName));

                int cellWidth = GetMetaFieldWidth(counter, field.Width);

                width += cellWidth;

                counter++;
            }

            width += this.VisibleMetaFields.Length * 7;

            MainGrid.Width = width;

            //Adding CssColumn
            MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetCssColumn(this.Page, ClassName));

            internalBindHeader();

            FilterElementCollection fec = new FilterElementCollection();
            fec.AddRange(CurrentProfile.Filters.ToArray());
            if (!String.IsNullOrEmpty(this.SearchKeyword))
            {
                FilterElement fe = CHelper.GetSearchFilterElementByKeyword(this.SearchKeyword, ClassName);
                fec.Add(fe);
            }
            fec.AddRange(AddFilters.ToArray());

            //Sorting
            SortingElementCollection sec = new SortingElementCollection();
            string key = GetPropertyKey(SortingPropertyKey);
            if (_pc[key] != null)
            {
                string sort = _pc[key];
                SortingElementType set = SortingElementType.Asc;
                if (sort.IndexOf(" DESC") >= 0)
                {
                    sort = sort.Substring(0, sort.IndexOf(" DESC"));
                    set = SortingElementType.Desc;
                }

                // O.R. [2009-11-02] check that sorting field exists
                if (mc.Fields.Contains(sort))
                {
                    sec.Add(new SortingElement(sort, set));
                }
                else
                {
                    _pc[key] = null;
                }
            }
            else if (CurrentProfile.Sorting != null)
            {
                // O.R. [2009-11-02] check that sorting fields exist
                foreach (SortingElement sortElement in CurrentProfile.Sorting)
                {
                    if (!mc.Fields.Contains(sortElement.Source))
                    {
                        CurrentProfile.Sorting = null;
                        break;
                    }
                }

                if (CurrentProfile.Sorting != null)
                    sec = CurrentProfile.Sorting;
            }

            if (this.GridFilters.Count > 0)
            {
                fec.AddRange(this.GridFilters);
            }

            if (this.GridSorting.Count > 0)
            {
                sec.AddRange(this.GridSorting);
            }

            if (this.CustomDataSource == null)
            {
                EntityObject[] list;
                try
                {
                    list = BusinessManager.List(ClassName, fec.ToArray(), sec.ToArray());
                }
                catch
                {
                    string sKey = GetPropertyKey(SortingPropertyKey);
                    _pc[sKey] = null;
                    if (this.Parent != null && this.Parent.Parent != null && this.Parent.Parent.Parent != null && this.Parent.Parent.Parent is Mediachase.Ibn.Web.UI.MetaUIEntity.Modules.EntityList)
                        Mediachase.Ibn.Web.UI.MetaUIEntity.Modules.EntityList.SetProfileName(_pc, ClassName, null);
                    throw;
                }

                MainGridExt.IsEmpty = (list.Length == 0);

                if (list.Length == 0)
                {
                    list = new EntityObject[] { new EntityObject(ClassName) };
                    this.Count = 0;
                }
                else
                {
                    this.Count = list.Length;
                }

                MainGrid.DataSource = list;
            }
            else
            {
                MainGrid.DataSource = this.CustomDataSource;
                this.Count = this.CustomDataSource.Length;
            }

            MainGrid.DataBind();

            internalBindPaging();

            #region Appply paging for dashboard
            if (this.DashboardMode)
            {
                MainGridExt.BottomHeight = 16;
                //HtmlControl c = (HtmlControl)MainGrid.BottomPagerRow.FindControl("pagingContainer");
                //c.Style.Add(HtmlTextWriterStyle.Position, "static");
                //c.Style.Add("float", "right");

                //MainGridExt.ServicePath = "debug";
            }
            #endregion

            //if (MainGridExt.IsEmpty)
            //    MainGrid.CssClass = "serverGridBodyEmpty";
        }