Ejemplo n.º 1
0
        /// <summary>
        /// Internals the bind.
        /// </summary>
        private void internalBind()
        {
            MainGrid.Columns.Clear();

            McMetaViewPreference mvPref = GetMetaViewPreference();

            MainGrid.AllowPaging = true;

            if (mvPref.Attributes["PageSize"] != null)
            {
                int pageSize = Convert.ToInt32(mvPref.Attributes.GetValue("PageSize").ToString());
                if (pageSize != -1)
                {
                    MainGrid.PageSize = pageSize;
                }
                else
                {
                    MainGrid.PageSize = 10000;
                    //MainGrid.AllowPaging = false;
                }

                //CHelper.SafeSelect(ddPaging, mvPref.Attributes.Get("PageSize").ToString());
            }
            else
            {
                MainGrid.PageSize = 10;
                mvPref.Attributes.Set("PageSize", 10);
                Mediachase.Ibn.Core.UserMetaViewPreference.Save((int)DataContext.Current.CurrentUserId, mvPref);
            }

            int width = 0;

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

            #region Check Additional columns from xml

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

            #endregion


            int counter = 0;
            foreach (MetaField field in this.VisibleMetaFields)
            {
                int cellWidth = 0;

                if (PlaceName == String.Empty)
                {
                    MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetColumn(this.Page, field));
                }
                else
                {
                    MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetColumn(this.Page, field, PlaceName));
                }


                cellWidth = mvPref.GetMetaFieldWidth(counter, 100);
                if (cellWidth == 0)
                {
                    cellWidth = 100;
                }
                width += cellWidth;

                counter++;
            }

            width += this.VisibleMetaFields.Length * 7;


            MainGrid.Width = width;

            #region Adding PrimaryKeyColumn
            MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetCssColumn(this.Page, CurrentView.MetaClass.Name));
            #endregion

            internalBindHeader();

            FilterElement fe = null;

            if (this.SearchKeyword != string.Empty)
            {
                fe = ListManager.CreateFilterByKeyword(mvPref.MetaView.MetaClass, this.SearchKeyword);
                mvPref.Filters.Add(fe);
            }

            MetaObject[] list = CurrentView.List(mvPref);

            if (fe != null)
            {
                mvPref.Filters.Remove(fe);
            }

            if (CurrentView.PrimaryGroupBy == null && CurrentView.SecondaryGroupBy == null)
            {
                MainGridExt.IsEmpty = (list.Length == 0);

                if (list.Length == 0)
                {
                    list = new MetaObject[] { new MetaObject(CurrentView.MetaClass) };
                }

                MainGrid.DataSource = list;
            }
            else
            {
                if (CurrentView.SecondaryGroupBy != null)
                {
                    list = MetaViewGroupUtil.ExcludeCollapsed(MetaViewGroupByType.Secondary, CurrentView.SecondaryGroupBy, CurrentView.PrimaryGroupBy, mvPref, list);
                }

                list = MetaViewGroupUtil.ExcludeCollapsed(MetaViewGroupByType.Primary, CurrentView.PrimaryGroupBy, null, mvPref, list);

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

                if (list.Length == 0)
                {
                    list = new MetaObject[] { new MetaObject(CurrentView.MetaClass) };
                }

                MainGrid.DataSource = list;
            }

            this.Count = list.Length;
            if (MainGridExt.IsEmpty)
            {
                this.Count = 0;
            }
            MainGrid.DataBind();

            internalBindPaging();

            if (list.Length == 0)
            {
                MainGrid.CssClass = "serverGridBodyEmpty";
            }
        }