Exemplo n.º 1
0
 public ArrayList GetSortedBindProperties()
 {
     ArrayList bindProp = new ArrayList();
     IComparer bindOrderComparer = new TreeListObjectsOrderComparer(this);
     Type t = this.GetType();
     PropertyInfo[] props = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
     ClassifyProperty(props, null, bindProp);
     bindProp.Sort(bindOrderComparer);
     return bindProp;
 }
Exemplo n.º 2
0
            // bindAll = true => bind all property except "Items" event <TreeListObjects> has no child items
            public int FillDataTable(DataTable table, Hashtable values, bool bindAll)
            {
                this.RowSpan = 0;
                Type t = this.GetType();
                ArrayList fieldProp = new ArrayList(), bindProp = new ArrayList();

                // Classify Property and sort binding property by "BindOrder"
                IComparer bindOrderComparer = new TreeListObjectsOrderComparer(this);
                PropertyInfo[] props = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                ClassifyProperty(props, fieldProp, bindProp);
                bindProp.Sort(bindOrderComparer);

                // get current level values from fields property
                if (values == null) values = new Hashtable();
                foreach (PropertyInfo prop in fieldProp)
                {
                    if (table.Columns.Contains(prop.Name))
                    {
                        values[prop.Name] = prop.GetValue(this, null);
                    }
                }

                // get child level values from binds property
                if (bindProp.Count > 0)
                    foreach (PropertyInfo prop in bindProp)
                    {
                        TreeListObjects objs = (TreeListObjects)prop.GetValue(this, null);
                        if (objs != null) { this.RowSpan += objs.FillDataTable(table, values, bindAll); }
                    }
                // leaf ==> create and add row
                else
                {
                    DataRow row = table.NewRow();
                    foreach (DictionaryEntry val in values) { row[val.Key.ToString()] = val.Value; }
                    table.Rows.Add(row);
                    this.RowSpan = 1;
                }

                // clear current level values
                foreach (PropertyInfo prop in fieldProp)
                {
                    if (values.Contains(prop.Name)) values.Remove(prop.Name);
                }

                // after all return row span for this object level
                return this.RowSpan;
            }