// customize the columns of a C1FlexGrid control
        // use dynamic type in order to avoid dependencies.
        static void CustomizeFlexGrid(dynamic flex, Type entityType, EntityDataSource datasource)
        {
            // configure columns
            foreach (dynamic c in flex.Cols)
            {
                // if the column is a key, make it read-only
                var pi = entityType.GetProperty(c.Name);
                if (pi != null)
                {
                    var atts = pi.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false);
                    if (atts.Length > 0)
                    {
                        var att = atts[0] as EdmScalarPropertyAttribute;
                        if (att.EntityKeyProperty)
                        {
                            c.AllowEditing = false;
                        }
                    }

                    // if the column holds entities, give it a data map
                    var type = pi.PropertyType;
                    if (!type.IsPrimitive)                    // typeof(EntityObject).IsAssignableFrom(type))
                    {
                        c.DataMap = datasource.GetLookupDictionary(type);
                    }
                }
            }
        }
Exemple #2
0
        public CollectionPropertyDescriptor(EntityDataSource ds, PropertyDescriptor pd) : base(pd.Name, null)
        {
            _ds = ds;
            _pd = pd;
            var elementType = _pd.PropertyType.GetGenericArguments()[0];

            _listType = typeof(EntityBindingList <>);
            _listType = _listType.MakeGenericType(elementType);
        }
Exemple #3
0
        ListDictionary lookup;                  // lookup dictionary (used to show and edit related entities in grid cells)

        #endregion

        #region Contructor

        /// <summary>
        /// Initializes a new instance of a <see cref="EntitySet"/>.
        /// </summary>
        /// <param name="entityDataSource"><see cref="EntityDataSource"/> that owns the entities.</param>
        /// <param name="propertyInfo"><see cref="PropertyInfo"/> used to retrieve the set from the context.</param>
        internal EntitySet(EntityDataSource entityDataSource, PropertyInfo propertyInfo)
        {
            var type = propertyInfo.PropertyType;

            Debug.Assert(
                type.IsGenericType &&
                type.GetGenericTypeDefinition() == typeof(DbSet <>) &&
                type.GetGenericArguments().Length == 1);

            source       = entityDataSource;
            propertyinfo = propertyInfo;
            elementType  = type.GetGenericArguments()[0];
        }
        // customize the columns of a DataGridView
        static void CustomizeDataGridView(DataGridView gridview, Type entityType, EntityDataSource datasource)
        {
            // configure columns
            for (int colIndex = 0; colIndex < gridview.Columns.Count; colIndex++)
            {
                // get column
                var c = gridview.Columns[colIndex];

                // if the column is a key, make it read-only
                var pi = entityType.GetProperty(c.DataPropertyName);
                if (pi != null)
                {
                    var atts = pi.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false);
                    if (atts.Length > 0)
                    {
                        var att = atts[0] as EdmScalarPropertyAttribute;
                        if (att.EntityKeyProperty)
                        {
                            c.ReadOnly = true;
                        }
                    }

                    // if the column holds entities, give it a data map
                    var type = pi.PropertyType;
                    if (!type.IsPrimitive)
                    //if (typeof(EntityObject).IsAssignableFrom(type))
                    {
                        var map = datasource.GetLookupDictionary(type);
                        if (map != null)
                        {
                            var col = new DataGridViewComboBoxColumn();
                            col.HeaderText       = c.HeaderText;
                            col.DataPropertyName = c.DataPropertyName;
                            col.Width            = c.Width;
                            col.DefaultCellStyle = c.DefaultCellStyle;
                            col.DataSource       = map;
                            col.ValueMember      = "Key";
                            col.DisplayMember    = "Value";
                            gridview.Columns.RemoveAt(colIndex);
                            gridview.Columns.Insert(colIndex, col);
                        }
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of a <see cref="EntityBindingList"/>.
        /// </summary>
        /// <param name="dataSource"><see cref="EntityDataSource"/> that owns the entities on this list.</param>
        /// <param name="query"><see cref="IEnumerable"/> that provides the entities for this list.</param>
        /// <param name="name">A name for identifying this list in its parent (for hierarchical binding).</param>
        public EntityBindingList(EntityDataSource dataSource, IEnumerable query, string name)
        {
            _ds    = dataSource;
            _set   = query as DbSet <T>;
            _coll  = query as EntityCollection <T>;
            _query = query;
            _name  = name;

            // populate list
            if (dataSource != null && !dataSource.DesignMode)
            {
                // at run time, get the data
                Refresh();
            }
            else
            {
                // at design time, add one element to help with binding
                try
                {
                    AddNew();
                }
                catch { }
            }
        }