Exemple #1
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            CustomProperty prop = null;

            PropertyDescriptor[] newProps = new PropertyDescriptor[this.Count];
            try
            {
                for (int i = 0; i < this.Count; i++)
                {
                    CustomProperty curprop = (CustomProperty)this[i];
                    if (curprop.Visible == true)
                    {
                        prop        = curprop;
                        newProps[i] = new CustomPropertyDescriptor(ref prop, attributes);
                    }
                }
            }
            catch (Exception ex)
            {
                string s = string.Format("在读取 {0} 字段时出现错误,请修改元信息描述数据表。\r\n错误讯息为:{1}", prop.ID, ex.Message);
                System.Windows.Forms.MessageBox.Show(s);
            }

            return(new PropertyDescriptorCollection(newProps));
        }
Exemple #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (context.Instance is CustomClass)
            {
                CustomPropertyDescriptor desc = (CustomPropertyDescriptor)context.PropertyDescriptor;
                if (desc.Property.Value is CustomClass)
                {
                    desc.Property.SetValue(value);

                    /*
                     * DBCustomClass cls = (DBCustomClass)desc.Property.Value;
                     * cls.Value = value;
                     * cls.GetDynamicClass(new object[]{value});
                     * while (cls.Parent != null)
                     * {
                     *  if (cls.Parent is DBCustomClass)
                     *  {
                     *      cls = (DBCustomClass)(cls.Parent);
                     *  }
                     * }
                     * cls.OnAsynNotifyEvent(1);
                     */
                    return(desc.Property.Value);
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }
Exemple #3
0
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
        {
            if (destType == typeof(string) && context.Instance is CustomClass)
            {
                CustomPropertyDescriptor desc = (CustomPropertyDescriptor)context.PropertyDescriptor;
                if (desc.Property.Value is CustomClass)
                {
                    CustomClass cls    = (CustomClass)context.Instance;
                    object      ovalue = null;
                    try
                    {
                        CustomClass childclass = (CustomClass)desc.Property.Value;
                        //string strdesc = childclass.Value == null ? "" : childclass.Value;
                        //ovalue = cls.OnCustomGetTreeValue(childclass, strdesc);
                        ovalue = cls.OnCustomGetTreeValue((CustomProperty)desc.Property);//, strdesc);
                        if (ovalue == null)
                        {
                            if (childclass.DisplayValue == null)
                            {
                                return(childclass.Value.ToString());
                            }
                            else
                            {
                                return(childclass.DisplayValue);
                            }
                        }
                        else
                        {
                            return(ovalue.ToString());
                        }
                        //else
                        //    return "...";
                    }
                    catch
                    {
                    }


                    /*CustomClass cls = (CustomClass)desc.Property.Value;
                     * string strValue = "";
                     * foreach(CustomProperty prop in cls)
                     * {
                     *  strValue = strValue + prop.ID + " = " + prop.Value + " ";
                     * }
                     */
                    //return ((CustomClass)desc.Property.Value).Description;
                }
            }
            return(base.ConvertTo(context, culture, value, destType));
        }
Exemple #4
0
        public object DoEditValue(CustomClass instance, CustomPropertyDescriptor descriptor, object value)
        {
            object newvalue = instance.OnCustomEditValue(descriptor.Property, value);

            if (value is CustomClass)
            {
                object newrealvalue = newvalue is CustomClass ? (newvalue as CustomClass).Value : newvalue;
                if (!(value as CustomClass).Value.Equals(newrealvalue))
                {
                    descriptor.Property.SetValue(newrealvalue);
                }
            }
            return(newvalue == null ? value : newvalue);
        }
Exemple #5
0
        public object DoEditValue(CustomPropertyDescriptor descriptor, object value)
        {
            string strPrePath;// = ((CustomPropertyDescriptor)context.PropertyDescriptor).Property.Prefix;
            string filenamefilter = Path.GetFileName(descriptor.Property.Prefix);
            //oldvalue 要处理为绝对路径
            string stroldvalue = value.ToString().Trim();
            object oldvalue;
            string strRootDir = Helper.AddSlash(Program.RootDir);
            string strCutDir;

            if (stroldvalue.Length > 0) //已经有值,则直接与rootdir组合
            {
                oldvalue   = Helper.CombinePaths(strRootDir, stroldvalue);
                strPrePath = strRootDir;
                strCutDir  = Helper.AddSlash(descriptor.Property.CutPrefix);
            }
            else
            {
                strPrePath = descriptor.Property.Prefix;
                strCutDir  = Helper.AddSlash(descriptor.Property.CutPrefix);
                oldvalue   = Helper.CombinePaths(strPrePath, stroldvalue);
            }

            object newvalue = NewEditValue(oldvalue, filenamefilter); //base.EditValue(context, provider, oldvalue);

            if (!newvalue.Equals(oldvalue) && newvalue != oldvalue)
            {
                //newvalue要处理成相对路径
                //string[] newvaluearray = Helper.split(newvalue.ToString().ToLower(), strPrePath.ToLower());
                //string[] newvaluearray = Helper.split(newvalue.ToString().ToLower(), strRootDir.ToLower());
                string[] newvaluearray = Helper.split(newvalue.ToString().ToLower(), strCutDir.ToLower());
                if (newvaluearray != null && newvaluearray.Length > 1)
                {
                    string strvalue = newvalue.ToString();
                    newvalue = strvalue.Substring(strvalue.Length - newvaluearray[1].Length);
                    newvalue = descriptor.Property.CutPreSlash ? newvalue : ("\\" + newvalue);
                }
                else
                {
                    //return value; //不正确的路径文件,还原为原始文件
                    throw new Exception("不正确的文件,可能是您没有选择正确路径下的文件。");
                }
            }
            else
            {
                return(value);//还原为原始的相对的路径
            }
            return(newvalue);
        }
Exemple #6
0
 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
 {
     if (sourceType == typeof(string) && context.Instance is CustomClass)
     {
         CustomPropertyDescriptor desc = (CustomPropertyDescriptor)context.PropertyDescriptor;
         if (desc.Property.Value is CustomClass)
         {
             DBCustomClass cls = ((DBCustomClass)(desc.Property.Value));
             if (!cls.IsVirtualField) //虚拟字段本身不能修改值
             {
                 return(true);
             }
         }
     }
     return(base.CanConvertFrom(context, sourceType));
 }