public int IndexOf(MxDataGridField field)
 {
     if (field != null)
     {
         return this.fields.IndexOf(field);
     }
     return -1;
 }
 public void Remove(MxDataGridField field)
 {
     int index = this.IndexOf(field);
     if (index >= 0)
     {
         this.RemoveAt(index);
     }
 }
 public void Add(MxDataGridField field)
 {
     this.AddAt(-1, field);
 }
 public void AddAt(int index, MxDataGridField field)
 {
     if (index == -1)
     {
         this.fields.Add(field);
     }
     else
     {
         this.fields.Insert(index, field);
     }
     field.SetOwner(this.owner);
     if (this.marked)
     {
         ((IStateManager) field).TrackViewState();
     }
     this.OnFieldsChanged();
 }
Esempio n. 5
0
 protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
 {
     this.pagedDataSource = this.CreatePagedDataSource();
     IEnumerator storedData = null;
     int num = 0;
     ArrayList dataKeysArray = this.DataKeysArray;
     ArrayList list2 = null;
     if (this.itemsArray != null)
     {
         this.itemsArray.Clear();
     }
     else
     {
         this.itemsArray = new ArrayList();
     }
     if (!dataBinding)
     {
         this.pagedDataSource.DataSource = dataSource;
         storedData = this.pagedDataSource.GetEnumerator();
         list2 = this.CreateFieldSet(null, false);
         ICollection is2 = dataSource as ICollection;
         if (is2 == null)
         {
             throw new HttpException(Microsoft.Matrix.Framework.SR.GetString("MxDataGrid_DataSourceMustBeCollection"));
         }
         this.itemsArray.Capacity = is2.Count;
     }
     else
     {
         dataKeysArray.Clear();
         if (dataSource != null)
         {
             ICollection is3 = dataSource as ICollection;
             if (((is3 == null) && this.pagedDataSource.IsPagingEnabled) && !this.pagedDataSource.IsCustomPagingEnabled)
             {
                 throw new HttpException(string.Format(Microsoft.Matrix.Framework.SR.GetString("MxDataGrid_Missing_VirtualItemCount"), this.ID));
             }
             this.pagedDataSource.DataSource = dataSource;
             if (this.pagedDataSource.IsPagingEnabled && ((this.pagedDataSource.CurrentPageIndex < 0) || (this.pagedDataSource.CurrentPageIndex >= this.pagedDataSource.PageCount)))
             {
                 throw new HttpException(Microsoft.Matrix.Framework.SR.GetString("Invalid_CurrentPageIndex"));
             }
             list2 = this.CreateFieldSet(this.pagedDataSource, dataBinding);
             if (this.storedDataValid)
             {
                 storedData = this.storedData;
             }
             else
             {
                 storedData = this.pagedDataSource.GetEnumerator();
             }
             if (is3 != null)
             {
                 int count = this.pagedDataSource.Count;
                 dataKeysArray.Capacity = count;
                 this.itemsArray.Capacity = count;
             }
         }
     }
     int num3 = 0;
     if (list2 != null)
     {
         num3 = list2.Count;
     }
     if (num3 > 0)
     {
         MxDataGridItem item;
         ListItemType editItem;
         MxDataGridField[] array = new MxDataGridField[num3];
         list2.CopyTo(array, 0);
         for (int i = 0; i < array.Length; i++)
         {
             array[i].Initialize();
         }
         Table child = new MxDataGridTable();
         this.Controls.Add(child);
         TableRowCollection rows = child.Rows;
         int itemIndex = 0;
         int dataSourceIndex = 0;
         string dataKeyField = this.DataKeyField;
         bool flag = dataBinding && (dataKeyField.Length != 0);
         bool isPagingEnabled = this.pagedDataSource.IsPagingEnabled;
         int editItemIndex = this.EditItemIndex;
         int selectedIndex = this.SelectedIndex;
         if (this.pagedDataSource.IsPagingEnabled)
         {
             dataSourceIndex = this.pagedDataSource.FirstIndexInPage;
         }
         if (isPagingEnabled)
         {
             this.CreateItem(-1, -1, ListItemType.Pager, false, null, array, rows, this.pagedDataSource);
         }
         this.CreateItem(-1, -1, ListItemType.Header, dataBinding, null, array, rows, null);
         if (this.storedDataValid && (this.firstDataItem != null))
         {
             if (flag)
             {
                 object propertyValue = DataBinder.GetPropertyValue(this.firstDataItem, dataKeyField);
                 dataKeysArray.Add(propertyValue);
             }
             editItem = ListItemType.Item;
             if (itemIndex == editItemIndex)
             {
                 editItem = ListItemType.EditItem;
             }
             else if (itemIndex == selectedIndex)
             {
                 editItem = ListItemType.SelectedItem;
             }
             item = this.CreateItem(0, dataSourceIndex, editItem, dataBinding, this.firstDataItem, array, rows, null);
             this.itemsArray.Add(item);
             num++;
             itemIndex++;
             dataSourceIndex++;
             this.storedDataValid = false;
             this.firstDataItem = null;
         }
         while (storedData.MoveNext())
         {
             object current = storedData.Current;
             if (flag)
             {
                 object obj4 = DataBinder.GetPropertyValue(current, dataKeyField);
                 dataKeysArray.Add(obj4);
             }
             editItem = ListItemType.Item;
             if (itemIndex == editItemIndex)
             {
                 editItem = ListItemType.EditItem;
             }
             else if (itemIndex == selectedIndex)
             {
                 editItem = ListItemType.SelectedItem;
             }
             else if ((itemIndex % 2) != 0)
             {
                 editItem = ListItemType.AlternatingItem;
             }
             item = this.CreateItem(itemIndex, dataSourceIndex, editItem, dataBinding, current, array, rows, null);
             this.itemsArray.Add(item);
             num++;
             dataSourceIndex++;
             itemIndex++;
         }
         this.CreateItem(-1, -1, ListItemType.Footer, dataBinding, null, array, rows, null);
         if (isPagingEnabled)
         {
             this.CreateItem(-1, -1, ListItemType.Pager, false, null, array, rows, this.pagedDataSource);
         }
     }
     int dataSourceCount = -1;
     if (dataBinding)
     {
         if (storedData != null)
         {
             if (this.pagedDataSource.IsPagingEnabled)
             {
                 this.ViewState["PageCount"] = this.pagedDataSource.PageCount;
                 if (this.pagedDataSource.IsCustomPagingEnabled)
                 {
                     dataSourceCount = num;
                 }
                 else
                 {
                     dataSourceCount = this.pagedDataSource.DataSourceCount;
                 }
             }
             else
             {
                 this.ViewState["PageCount"] = 1;
                 dataSourceCount = this.pagedDataSource.DataSourceCount;
             }
         }
         else
         {
             this.ViewState["PageCount"] = 0;
         }
     }
     this.pagedDataSource = null;
     return dataSourceCount;
 }
Esempio n. 6
0
        protected virtual void PrepareControlHierarchy()
        {
            if (this.Controls.Count != 0)
            {
                Table table = (Table) this.Controls[0];
                table.CopyBaseAttributes(this);
                if (base.ControlStyleCreated)
                {
                    table.ApplyStyle(base.ControlStyle);
                }
                else
                {
                    table.GridLines = System.Web.UI.WebControls.GridLines.Both;
                    table.CellSpacing = 0;
                }
                TableRowCollection rows = table.Rows;
                int count = rows.Count;
                if (count != 0)
                {
                    int num2 = this.Fields.Count;
                    MxDataGridField[] array = new MxDataGridField[num2];
                    if (num2 > 0)
                    {
                        this.Fields.CopyTo(array, 0);
                    }
                    Style s = null;
                    if (this.alternatingItemStyle != null)
                    {
                        s = new TableItemStyle();
                        s.CopyFrom(this.itemStyle);
                        s.CopyFrom(this.alternatingItemStyle);
                    }
                    else
                    {
                        s = this.itemStyle;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        Style style2;
                        Style style3;
                        TableCellCollection cells;
                        MxDataGridItem item = (MxDataGridItem) rows[i];
                        switch (item.ItemType)
                        {
                            case ListItemType.Header:
                                if (this.ShowHeader)
                                {
                                    break;
                                }
                                item.Visible = false;
                                goto Label_0336;

                            case ListItemType.Footer:
                                if (this.ShowFooter)
                                {
                                    goto Label_014D;
                                }
                                item.Visible = false;
                                goto Label_0336;

                            case ListItemType.Item:
                                item.MergeStyle(this.itemStyle);
                                goto Label_0281;

                            case ListItemType.AlternatingItem:
                                item.MergeStyle(s);
                                goto Label_0281;

                            case ListItemType.SelectedItem:
                                style2 = new TableItemStyle();
                                if ((item.ItemIndex % 2) == 0)
                                {
                                    goto Label_0200;
                                }
                                style2.CopyFrom(s);
                                goto Label_020D;

                            case ListItemType.EditItem:
                                style3 = new TableItemStyle();
                                if ((item.ItemIndex % 2) == 0)
                                {
                                    goto Label_0242;
                                }
                                style3.CopyFrom(s);
                                goto Label_024F;

                            case ListItemType.Pager:
                                if (this.pagerStyle.Visible)
                                {
                                    goto Label_0179;
                                }
                                item.Visible = false;
                                goto Label_0336;

                            default:
                                goto Label_0281;
                        }
                        if (this.headerStyle != null)
                        {
                            item.MergeStyle(this.headerStyle);
                        }
                        goto Label_0281;
                    Label_014D:
                        item.MergeStyle(this.footerStyle);
                        goto Label_0281;
                    Label_0179:
                        if (i == 0)
                        {
                            if (this.pagerStyle.IsPagerOnTop)
                            {
                                goto Label_01B1;
                            }
                            item.Visible = false;
                            goto Label_0336;
                        }
                        if (!this.pagerStyle.IsPagerOnBottom)
                        {
                            item.Visible = false;
                            goto Label_0336;
                        }
                    Label_01B1:
                        item.MergeStyle(this.pagerStyle);
                        goto Label_0281;
                    Label_0200:
                        style2.CopyFrom(this.itemStyle);
                    Label_020D:
                        style2.CopyFrom(this.selectedItemStyle);
                        item.MergeStyle(style2);
                        goto Label_0281;
                    Label_0242:
                        style3.CopyFrom(this.itemStyle);
                    Label_024F:
                        if (item.ItemIndex == this.SelectedIndex)
                        {
                            style3.CopyFrom(this.selectedItemStyle);
                        }
                        style3.CopyFrom(this.editItemStyle);
                        item.MergeStyle(style3);
                    Label_0281:
                        cells = item.Cells;
                        int num4 = cells.Count;
                        if ((num2 > 0) && (item.ItemType != ListItemType.Pager))
                        {
                            int num5 = num4;
                            if (num2 < num4)
                            {
                                num5 = num2;
                            }
                            for (int j = 0; j < num5; j++)
                            {
                                if (!array[j].Visible)
                                {
                                    cells[j].Visible = false;
                                }
                                else
                                {
                                    Style headerStyleInternal = null;
                                    switch (item.ItemType)
                                    {
                                        case ListItemType.Header:
                                            headerStyleInternal = array[j].HeaderStyleInternal;
                                            break;

                                        case ListItemType.Footer:
                                            headerStyleInternal = array[j].FooterStyleInternal;
                                            break;

                                        default:
                                            headerStyleInternal = array[j].ItemStyleInternal;
                                            break;
                                    }
                                    cells[j].MergeStyle(headerStyleInternal);
                                }
                            }
                        }
                    Label_0336:;
                    }
                }
            }
        }
Esempio n. 7
0
 protected virtual void InitializeItem(MxDataGridItem item, MxDataGridField[] fields)
 {
     TableCellCollection cells = item.Cells;
     for (int i = 0; i < fields.Length; i++)
     {
         TableCell cell = new TableCell();
         fields[i].InitializeCell(cell, i, item.ItemType);
         cells.Add(cell);
     }
 }
Esempio n. 8
0
 protected MxDataGridItem CreateItem(int itemIndex, int dataSourceIndex, ListItemType itemType, bool dataBind, object dataItem, MxDataGridField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
 {
     MxDataGridItem item = this.CreateItem(itemIndex, dataSourceIndex, itemType);
     MxDataGridItemEventArgs e = new MxDataGridItemEventArgs(item);
     if (itemType != ListItemType.Pager)
     {
         this.InitializeItem(item, fields);
         if (dataBind)
         {
             item.DataItem = dataItem;
         }
         this.OnItemCreated(e);
         rows.Add(item);
         if (dataBind)
         {
             item.DataBind();
             this.OnItemDataBound(e);
             item.DataItem = null;
         }
         return item;
     }
     this.InitializePager(item, fields.Length, pagedDataSource);
     this.OnItemCreated(e);
     rows.Add(item);
     return item;
 }
Esempio n. 9
0
 protected virtual ArrayList CreateFieldSet(PagedDataSource dataSource, bool useDataSource)
 {
     int num;
     ArrayList list = new ArrayList();
     MxDataGridField[] array = new MxDataGridField[this.Fields.Count];
     this.Fields.CopyTo(array, 0);
     for (num = 0; num < array.Length; num++)
     {
         list.Add(array[num]);
     }
     if (this.AutoGenerateFields)
     {
         ArrayList autoGenFieldsArray = null;
         if (useDataSource)
         {
             autoGenFieldsArray = this.CreateAutoGeneratedFields(dataSource);
             this.autoGenFieldsArray = autoGenFieldsArray;
         }
         else
         {
             autoGenFieldsArray = this.autoGenFieldsArray;
         }
         if (autoGenFieldsArray == null)
         {
             return list;
         }
         int count = autoGenFieldsArray.Count;
         for (num = 0; num < count; num++)
         {
             list.Add(autoGenFieldsArray[num]);
         }
     }
     return list;
 }