private void ListView_FormatCell(object sender, FormatCellEventArgs e) { object item = e.Model; if (item != null) { PropertyInfo p = item.GetType().GetProperty("IsArchived"); if (p != null && p.PropertyType == typeof(bool) && (bool)(p.GetValue(item)) == true) { e.SubItem.ForeColor = Color.Gray; } else { if (e.Column.AspectName == null) { return; } Type pType = AttrHelper.GetPropertyType(SourceObjectType, e.Column.AspectName); PropertyInfo propInfo = SourceObjectType.GetProperty(e.Column.AspectName); JExpired expiredProp = AttrHelper.GetAttribute <JExpired>(propInfo); if (expiredProp != null) { object propValue = null; if (expiredProp.ExpiredProperty != null) { PropertyInfo propInfo1 = SourceObjectType.GetProperty(expiredProp.ExpiredProperty); if (propInfo1 != null) { propValue = AttrHelper.GetPropertyValue(e.Model, propInfo1); } } else { propValue = AttrHelper.GetPropertyValue(e.Model, propInfo); } if (propValue != null) { ModelHelper.ExpiredToColor(propValue.ToString(), e.SubItem.ForeColor); } } else { JDictProp dictProp = AttrHelper.GetAttribute <JDictProp>(propInfo); if (dictProp != null && (dictProp.DictPropertyStyle == DisplyPropertyStyle.ColoredTextOnly || dictProp.DictPropertyStyle == DisplyPropertyStyle.ColoredTextAndImage)) { object propValue = AttrHelper.GetPropertyValue(e.Model, propInfo); if (propValue != null) { JDictItem ditem = Dm.Instance.GetDictText(dictProp.Id, propValue.ToString()); if (ditem != null && ditem.TextColor != null && ditem.TextColor != Color.Black) { e.SubItem.ForeColor = ditem.TextColor; } } } } } } }
private void bag1_GetValue(object sender, PropertySpecEventArgs e) { try { if (tempSourceObject != null) { if (e.Property.PropTag != null && e.Property.PropTag is IField) { e.Value = (e.Property.PropTag as IField).Value; } else { string aspectName = e.Property.PropTag as string;// Type pType = AttrHelper.GetPropertyType(SourceObjectType, aspectName); e.Value = Dm.Instance.GetCustomPropertyValue(tempSourceObject, aspectName, true, AppManager.Instance.PropertyWindowTruncatedMaxItemCount, AppManager.Instance.PropertyWindowTruncatedMaxLength); } } else { e.Value = null; } } catch (Exception ex) { Log.ShowError(ex); } }
// 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); }