Beispiel #1
0
        internal void SetColumnsFromModel()
        {
            this.columns = new List <BsGridColumn <TRow> >();

            Type type = typeof(TRow);

            PropertyInfo[] properties = type.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                BsGridColumnAttribute columnAttr = null;
                if (ReflectionHelpers.TryGetAttribute(property, out columnAttr))
                {
                    if (columnAttr.Usage != BsGridColumnUsage.Excel)
                    {
                        var column = new BsGridColumn <TRow>(property, this.viewContext);

                        column.IsSortable = columnAttr.IsSortable;
                        column.SetWidth(columnAttr.Width, columnAttr.MediumWidth, columnAttr.SmallWidth, columnAttr.ExtraSmallWidth);
                        column.SetOrder(columnAttr.Order);

                        System.ComponentModel.DataAnnotations.DisplayAttribute displayAttribute = null;
                        if (ReflectionHelpers.TryGetAttribute(property, out displayAttribute))
                        {
                            column.DisplayName = displayAttribute.GetName();
                        }
                        else
                        {
                            column.DisplayName = property.Name;
                        }

                        this.columns.Add(column);
                    }
                }
            }
        }
Beispiel #2
0
        //private void applyAttributes(PropertyInfo pi)
        private void applyAttributes(string propertyName)
        {
            IColumnAdapter gc = _target.ColumnByFieldName(propertyName);

            if (ReferenceEquals(null, gc))
            {
                return;
            }
            // take all first, but cache just custom, but we need Standard Display
            IEnumerable <Attribute> attrs = ReflectionHelper.GetAttributesFromPath(_dataType, propertyName);
            IList <CustomAttribute> ac    = new List <CustomAttribute>();

            foreach (Attribute a in attrs)
            {
                if (a is CustomAttribute)
                {
                    GridColumnPopulated gcp = new GridColumnPopulated {
                        FieldName = propertyName, RepositoryItem = null, Column = gc
                    };
                    (a as CustomAttribute).applyGridColumnPopulation(this, gcp);
                    ac.Add(a as CustomAttribute);
                    RepositoryItem ri = gcp.RepositoryItem;
                    if (ri != null)
                    {
                        _target.RepositoryItems.Add(ri);
                        _repositories[propertyName] = ri;
                        if (gc != null)
                        {
                            gc.ColumnEdit = ri;
                        }
                    }
                }
                if (a is xwcs.core.db.binding.attributes.StyleAttribute)
                {
                    xwcs.core.db.binding.attributes.StyleAttribute sa = a as xwcs.core.db.binding.attributes.StyleAttribute;
                    if (sa.VAlignment != VAlignment.Default)
                    {
                        gc.VAlignment = sa.VAlignment;
                    }
                    if (sa.HAlignment != HAlignment.Default)
                    {
                        gc.HAlignment = sa.HAlignment;
                    }

                    if (!ReferenceEquals(sa.ColumnWidth, null))
                    {
                        if (sa.ColumnWidth >= 0)
                        {
                            gc.Width = sa.ColumnWidth;
                        }
                    }
                    if (sa.BackgrounColor > 0)
                    {
                        gc.BackGrndColor                       = sa.BackgrounColor;
                        gc.AppearanceCell.BackColor            = System.Drawing.Color.FromArgb((int)sa.BackgrounColor);
                        gc.AppearanceCell.Options.UseBackColor = true;
                    }
                }

                // handle column name
                if (a is System.ComponentModel.DataAnnotations.DisplayAttribute)
                {
                    System.ComponentModel.DataAnnotations.DisplayAttribute da = a as System.ComponentModel.DataAnnotations.DisplayAttribute;

                    gc.Caption      = da.GetName() ?? gc.Caption;
                    gc.Caption      = da.GetShortName() ?? gc.Caption;
                    gc.VisibleIndex = da.GetOrder() ?? gc.VisibleIndex;

                    if (gc.Caption.ToUpper() != (da.GetName() ?? gc.Caption).ToUpper())
                    {
                        gc.ToolTip = da.GetName();
                    }
                    if (gc.ToolTip.ToUpper() != (da.GetDescription() ?? gc.ToolTip).ToUpper())
                    {
                        if (gc.ToolTip != "")
                        {
                            gc.ToolTip = gc.ToolTip + "\n";
                        }
                        gc.ToolTip = gc.ToolTip + da.GetDescription();
                    }
                }
            }

            if (ac.Count > 0)
            {
                _attributesCache[propertyName] = ac;
            }
        }