예제 #1
0
 /// <summary>
 /// 获取枚举的描述
 /// </summary>
 /// <param name="enumType"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string GetEnumDisplay(Type enumType, string value)
 {
     try
     {
         object enumObj = Enum.Parse(enumType, value, true);
         if (enumObj == null)
         {
             return("");
         }
         FieldInfo field = enumType.GetField(enumObj.ToString());
         if (field == null)
         {
             return(enumObj.ToString());
         }
         var obj = field.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute), false);
         if (obj != null && obj.Count() != 0)
         {
             System.ComponentModel.DataAnnotations.DisplayAttribute md = obj[0] as System.ComponentModel.DataAnnotations.DisplayAttribute;
             return(md.Name);
         }
         return(enumObj.ToString());
     }
     catch { }
     return("");
 }
예제 #2
0
 public void CanRenderAPropertyWithoutThrowingAnException()
 {
     var someObject = new SomeType() {SomeProperty = "SomeValue"};
     var properties = Properties.For(someObject);
     var annotation = new System.ComponentModel.DataAnnotations.DisplayAttribute();
     var helper = new RazorTemplateHtmlHelper();
     var html = properties.Render(helper);
     Assert.AreEqual(expected, html);
 }
        public PlusPropertyDescriptor(PropertyDescriptor inner) : base(inner)
        {
            this.innerPropertyDescriptor = inner;
            this.displayAttribute        = this.Attributes[typeof(System.ComponentModel.DataAnnotations.DisplayAttribute)] as System.ComponentModel.DataAnnotations.DisplayAttribute;

            this.dataFormatAttribute = this.Attributes[typeof(DataFormatAttribute)] as DataFormatAttribute;

            if (this.displayAttribute != null)
            {
                this.Order = this.displayAttribute.GetOrder().GetValueOrDefault();
            }
        }
예제 #4
0
        public void CanRenderAPropertyWithoutThrowingAnException()
        {
            var someObject = new SomeType()
            {
                SomeProperty = "SomeValue"
            };
            var properties = Properties.For(someObject);
            var annotation = new System.ComponentModel.DataAnnotations.DisplayAttribute();
            var helper     = new RazorTemplateHtmlHelper();
            var html       = properties.Render(helper);

            Assert.AreEqual(expected, html);
        }
예제 #5
0
        /// <summary>
        /// 设备属性下拉数据
        /// </summary>
        /// <returns></returns>
        public APIRst GetAttribCombox()
        {
            APIRst rst = new APIRst();

            try
            {
                DataTable dtSource = new DataTable();
                dtSource.Columns.Add("Id", typeof(System.Int32));
                dtSource.Columns.Add("Text", typeof(System.String));
                System.Reflection.FieldInfo[] fields = typeof(MdAttrib).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                foreach (System.Reflection.FieldInfo field in fields)
                {
                    MdAttrib aa  = (MdAttrib)Enum.Parse(typeof(MdAttrib), field.Name);
                    var      obj = field.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute), false);
                    if (obj != null && obj.Count() != 0)
                    {
                        System.ComponentModel.DataAnnotations.DisplayAttribute md = obj[0] as System.ComponentModel.DataAnnotations.DisplayAttribute;
                        dtSource.Rows.Add(new object[] { (int)aa, md.Name });
                    }
                }

                var res1 = from s1 in dtSource.AsEnumerable()
                           select new
                {
                    Id   = CommFunc.ConvertDBNullToInt32(s1["Id"]),
                    Text = CommFunc.ConvertDBNullToString(s1["Text"]),
                };
                rst.data = res1.ToList();
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("设备属性下拉数据错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
예제 #6
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);
                    }
                }
            }
        }
예제 #7
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;
            }
        }