Inheritance: IEntityCollection, IEnumerable, IComponent
        private SortedList GetSortedListOfProperties(tgEntity entity, tgEntityCollectionBase baseCollection)
        {
            SortedList list = new SortedList();

            tgEntityCollectionBase theBaseCollection = baseCollection != null ? baseCollection : entity.Collection;

            if (theBaseCollection != null)
            {
                if (theBaseCollection.selectedColumns != null)
                {
                    foreach (KeyValuePair <string, int> selectedColumn in theBaseCollection.selectedColumns)
                    {
                        list.Add(selectedColumn.Value, selectedColumn.Key);
                    }
                }

                if (theBaseCollection.extraColumnMetadata != null)
                {
                    foreach (KeyValuePair <string, tgColumnMetadata> extraColumn in theBaseCollection.extraColumnMetadata)
                    {
                        list.Add(extraColumn.Value.Ordinal, extraColumn.Key);
                    }
                }
            }

            return(list);
        }
Beispiel #2
0
        private void BindCollection(tgEntityCollectionBase entities)
        {
            IEntityCollection entityCollection = (IEntityCollection) entities;
            CollectionDataGridView.DataSource = entities;

            if (entityCollection.Query != null && entityCollection.Query.tg.LastQuery != null)
            {
                this.txtLastQuery.Text = entityCollection.Query.tg.LastQuery;
            }
        }
 internal virtual PropertyDescriptorCollection GetProperties(tgEntity entity, tgEntityCollectionBase baseCollection)
 {
     return null;
 }
 virtual internal PropertyDescriptorCollection GetProperties(tgEntity entity, tgEntityCollectionBase baseCollection)
 {
     return(null);
 }
Beispiel #5
0
 public esVisualizerForm(tgEntityCollectionBase entities)
 {
     InitializeComponent();
     BindCollection(entities);
 }
        internal override PropertyDescriptorCollection GetProperties(tgEntity entity, tgEntityCollectionBase baseCollection)
        {
            bool weHaveData  = false;
            int  lastOrdinal = 0;

            tgColumnMetadataCollection esMetaCols = entity.tg.Meta.Columns;

            tgEntityCollectionBase theBaseCollection = baseCollection != null ? baseCollection : entity.Collection;

            bool enableHierarchcialBinding = theBaseCollection != null ? theBaseCollection.EnableHierarchicalBinding : true;

            if (theBaseCollection != null)
            {
                if (theBaseCollection.GetList() != null)
                {
                    // Do we have any entities?
                    weHaveData = theBaseCollection.GetList().Count > 0;

                    if (weHaveData == false)
                    {
                        // If selectedColumns has data then they attempted a load and we know the columns based on thier select statement
                        weHaveData = theBaseCollection.selectedColumns != null && theBaseCollection.selectedColumns.Keys.Count > 0;
                    }
                }
            }

            //------------------------------------------------------------
            // First we deal with Properties from the DataTable.Columns
            // or from the tgColumnMetadataCollection.
            //------------------------------------------------------------
            ArrayList collNested = new ArrayList();
            SortedList <int, PropertyDescriptor> coll = new SortedList <int, PropertyDescriptor>();

            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(entity, true);

            // Note, we check for selectedColumns because we might be a deserialized collection in which
            // case there will not be any selectedColumns
            if (weHaveData && theBaseCollection.selectedColumns != null)
            {
                SortedList list = GetSortedListOfProperties(entity, baseCollection);

                for (int i = 0; i < list.Count; i++)
                {
                    string column = (string)list.GetByIndex(i);

                    if (column == "ESRN")
                    {
                        continue;
                    }

                    tgColumnMetadata esCol = entity.tg.Meta.Columns.FindByColumnName(column);

                    if (esCol != null)
                    {
                        PropertyDescriptor prop = props[esCol.PropertyName];

                        if (prop != null)
                        {
                            coll.Add(lastOrdinal++, prop);
                        }
                    }
                    else
                    {
                        esCol = theBaseCollection.extraColumnMetadata[column];

                        if (esCol != null)
                        {
                            // Extra or Extended Properties
                            tgPropertyDescriptor dpd = new tgPropertyDescriptor
                                                       (
                                typeof(T),
                                column,
                                esCol != null ? esCol.Type : typeof(string),
                                delegate(object p)
                            {
                                return(((tgEntity)p).currentValues[column]);
                            },
                                delegate(object p, object data)
                            {
                                ((tgEntity)p).currentValues[column] = data;
                                ((tgEntity)p).OnPropertyChanged(column);
                            }
                                                       );

                            coll.Add(lastOrdinal++, dpd);
                        }
                    }
                }
            }
            else
            {
                foreach (tgColumnMetadata esCol in esMetaCols)
                {
                    coll.Add(lastOrdinal++, props[esCol.PropertyName]);
                }
            }

            //------------------------------------------------------------
            // Now we deal with extended properties that are using the
            // esExtendedPropertyAttribute technique
            //------------------------------------------------------------
            foreach (PropertyDescriptor prop in props)
            {
                if (prop.Attributes.Contains(tgEntityCollection <T> .extendedPropertyAttribute))
                {
                    coll.Add(lastOrdinal++, prop);
                }
            }

            //------------------------------------------------------------
            // Now we deal with any local properties. Local properties are
            // properties that users may want to bind with that are
            // NOT backed by data in the DataTable
            //------------------------------------------------------------
            List <tgPropertyDescriptor> localProps = entity.GetLocalBindingProperties();

            if (localProps != null)
            {
                foreach (tgPropertyDescriptor esProp in localProps)
                {
                    // We check this incase they add a local based property for a DataColumn
                    // based property, they would do this so it appears in design time, and
                    // we don't want to add a duplicate
                    bool exists = coll.ContainsValue(props[esProp.Name]);

                    if (!exists)
                    {
                        if (props[esProp.Name] != null)
                        {
                            coll.Add(lastOrdinal++, props[esProp.Name]);
                        }
                        else
                        {
                            coll.Add(lastOrdinal++, esProp);
                        }
                    }
                }
            }

            ArrayList tempColl = new ArrayList();

            if (enableHierarchcialBinding)
            {
                List <tgPropertyDescriptor> hierProps = entity.GetHierarchicalProperties();
                if (hierProps != null)
                {
                    foreach (tgPropertyDescriptor esProp in hierProps)
                    {
                        esProp.TrueDescriptor = props[esProp.Name];
                        //  coll.Add(lastOrdinal++, esProp);

                        tempColl.Add(esProp);
                    }
                }
            }

            // Create the collection
            foreach (PropertyDescriptor p in coll.Values)
            {
                tempColl.Add(p);
            }
            tempColl.AddRange(collNested);

            PropertyDescriptorCollection theProps =
                new PropertyDescriptorCollection((PropertyDescriptor[])tempColl.ToArray(typeof(PropertyDescriptor)));

            return(theProps);
        }