コード例 #1
0
        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;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
 private void addButton_Click(object sender, EventArgs e)
 {
     try
     {
         //dict edit
         SimpleJDictItemDialog dialog = new SimpleJDictItemDialog(new JDictItem());
         DialogResult          res    = dialog.ShowDialog();
         if (res == DialogResult.OK && dialog.DictItem.Key != null)
         {
             JDictItem newObject = dialog.DictItem;
             bool      oPresent  = false;
             foreach (var o in listView.Objects)
             {
                 if (((JDictItem)o).Key.Equals(newObject.Key))
                 {
                     oPresent = true;
                     break;
                 }
             }
             if (oPresent == false)
             {
                 this.listView.AddObject(newObject);
                 this.listView.EnsureModelVisible(newObject);
             }
         }
     }
     catch (Exception ex)
     {
         Log.ShowError(ex);
     }
 }
コード例 #3
0
        public SimpleDictListDialog(string dictId, bool allowMultiSelect)
        {
            InitializeComponent();
            this.Text = FrwCRUDRes.SimpleDictListDialog_Dict;

            this.DictId = dictId;
            ((System.ComponentModel.ISupportInitialize)(listView)).BeginInit();
            //ovl settings
            listView.EmptyListMsg     = FrwCRUDRes.List_No_Records;
            listView.EmptyListMsgFont = new Font("Tahoma", 9);//todo;
            listView.FullRowSelect    = true;
            listView.UseCompatibleStateImageBehavior = false;
            listView.View                        = System.Windows.Forms.View.Details;
            listView.UseFiltering                = true;
            listView.UseFilterIndicator          = true;
            listView.AllowColumnReorder          = true;
            listView.TriStateCheckBoxes          = false;
            listView.CellEditUseWholeCell        = false;
            listView.TintSortColumn              = true;
            listView.ShowItemToolTips            = true;
            listView.UseHotItem                  = true;
            listView.UseHyperlinks               = true;
            listView.ShowCommandMenuOnRightClick = true;
            listView.TintSortColumn              = true;
            listView.MultiSelect                 = allowMultiSelect;

            OLVColumn column = null;

            column                = new OLVColumn();
            column.AspectName     = "Text";
            column.Text           = FrwCRUDRes.SimpleDictListDialog_Name;
            column.Width          = 350;
            column.FillsFreeSpace = true;
            AddColumnToList(column);

            column             = new OLVColumn();
            column.AspectName  = "Image";
            column.Text        = FrwCRUDRes.SimpleDictListDialog_Image;
            column.Width       = 50;
            column.ImageGetter = delegate(object x)
            {
                JDictItem item = (JDictItem)x;

                Image smallImage = BaseOLVListWindow.AddImageToImageList(this.listView, item.Image, null);
                if (smallImage != null)
                {
                    item.Image = smallImage;
                }
                return(smallImage);
            };
            AddColumnToList(column);

            SourceObjects = Dm.Instance.GetDictionaryItems(DictId);


            ((System.ComponentModel.ISupportInitialize)(listView)).EndInit();
        }
コード例 #4
0
        public SimpleJDictItemDialog(JDictItem dictItem)
        {
            InitializeComponent();
            this.Text        = FrwCRUDRes.SimpleJDictItemDialog_Title;
            this.label3.Text = FrwCRUDRes.SimpleJDictItemDialog_Image;
            this.label2.Text = FrwCRUDRes.SimpleJDictItemDialog_Text;
            this.label1.Text = FrwCRUDRes.SimpleJDictItemDialog_Key;

            DictItem         = DictItem;
            textTextBox.Text = DictItem.Text;
            keyTextBox.Text  = DictItem.Key;
            //imageTextBox.Text = DictItem.Image;
        }
コード例 #5
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);
        }