コード例 #1
0
        static public bool IsTextColoredFieldPresent(Type t)
        {
            var pl = AttrHelper.GetPropertiesWithAttribute <JDictProp>(t);

            foreach (var p in pl)
            {
                JDictProp d = AttrHelper.GetAttribute <JDictProp>(p);
                if (d.DictPropertyStyle == DisplyPropertyStyle.ColoredTextOnly || d.DictPropertyStyle == DisplyPropertyStyle.ColoredTextAndImage)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        // create a typical handler for the image
        protected bool CreateImageGetterDelegate(OLVColumn column, Type sourceObjectType)
        {
            Type pType = AttrHelper.GetPropertyType(sourceObjectType, column.AspectName);
            // the code for the case of the dictionary is implemented
            JImageName imageNameAttr = AttrHelper.GetAttribute <JImageName>(SourceObjectType, column.AspectName);
            JImageRef  imageRefAttr  = AttrHelper.GetAttribute <JImageRef>(SourceObjectType, column.AspectName);
            JDictProp  dictAttr      = AttrHelper.GetAttribute <JDictProp>(SourceObjectType, column.AspectName);

            if (dictAttr != null && dictAttr.DictPropertyStyle != DisplyPropertyStyle.TextOnly &&
                dictAttr.AllowMultiValues == false) //todo
            {
                column.ImageGetter = delegate(object x)
                {
                    if (dictAttr.AllowMultiValues)
                    {
                        return(null);
                    }
                    object value = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (value == null)
                    {
                        return(null);
                    }
                    JDictItem item = Dm.Instance.GetDictText(dictAttr.Id, value.ToString());
                    if (item == null)
                    {
                        return(null);
                    }
                    Image smallImage = AddImageToImageList(this.listView, item.Image, null);
                    if (smallImage != null && item.Image == null)
                    {
                        item.Image = smallImage;
                    }
                    return(smallImage);
                };
                return(true);
            }
            else if (imageNameAttr != null && imageNameAttr.DictPropertyStyle != DisplyPropertyStyle.TextOnly)
            {
                column.ImageGetter = delegate(object x)
                {
                    object value = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (value == null)
                    {
                        return(null);
                    }
                    Image smallImage = AddImageToImageList(this.listView, null, value.ToString());
                    //if (smallImage != null && item.Image == null) item.Image = smallImage;
                    return(smallImage);
                };
                return(true);
            }
            else if (imageRefAttr != null && imageRefAttr.DictPropertyStyle != DisplyPropertyStyle.TextOnly)
            {
                column.ImageGetter = delegate(object x)
                {
                    object value = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (value == null)
                    {
                        return(null);
                    }
                    PropertyInfo propInfo      = x.GetType().GetProperty(column.AspectName);
                    PropertyInfo imagePropInfo = AttrHelper.GetPropertiesWithAttribute <JImageName>(propInfo.PropertyType).FirstOrDefault <PropertyInfo>();
                    if (imagePropInfo == null)
                    {
                        return(null);
                    }
                    value = imagePropInfo.GetValue(value);
                    if (value == null)
                    {
                        return(null);
                    }

                    AttrHelper.GetProperty <JImageName>(propInfo.PropertyType);
                    Image smallImage = AddImageToImageList(this.listView, null, value.ToString());
                    //if (smallImage != null && item.Image == null) item.Image = smallImage;
                    return(smallImage);
                };
                return(true);
            }
            else if (pType == typeof(JAttachment) || AttrHelper.IsGenericListTypeOf(pType, typeof(JAttachment)) ||
                     AttrHelper.GetAttribute <JText>(sourceObjectType, column.AspectName) != null)
            {
                column.ImageGetter = delegate(object x)
                {
                    object v = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (v != null)
                    {
                        Image smallImage = null;
                        if (AttrHelper.GetAttribute <JText>(sourceObjectType, column.AspectName) != null)
                        {
                            if (string.IsNullOrEmpty(v as string) == false)
                            {
                                smallImage = (Image)Properties.Resources.book_open;
                            }
                        }
                        else if (pType == typeof(JAttachment) || AttrHelper.IsGenericListTypeOf(pType, typeof(JAttachment)))
                        {
                            smallImage = (Image)Properties.Resources.attachment;
                        }
                        return(smallImage);
                    }
                    else
                    {
                        return(null);
                    }
                };
                return(true);
            }
            return(false);
        }