Exemple #1
0
 private void SetConstraintsFromBinding(Binding binding)
 {
     if (binding.BindingManagerBase != null)
     {
         if (!this.IsFormatModeAndBindingCompatible(this.ownerControl.FormatMode, binding))
         {
             throw new InvalidOperationException();
         }
         PropertyDescriptorCollection itemProperties     = binding.BindingManagerBase.GetItemProperties();
         PropertyDescriptor           propertyDescriptor = itemProperties.Find(binding.BindingMemberInfo.BindingField, true);
         if (propertyDescriptor != null)
         {
             FilterValuePropertyDescriptor filterValuePropertyDescriptor = propertyDescriptor as FilterValuePropertyDescriptor;
             Type propertyType;
             if (filterValuePropertyDescriptor != null)
             {
                 propertyType = filterValuePropertyDescriptor.ValuePropertyType;
             }
             else
             {
                 propertyType = propertyDescriptor.PropertyType;
             }
             object    obj       = (binding.DataSource is BindingSource) ? ((BindingSource)binding.DataSource).DataSource : binding.DataSource;
             DataTable dataTable = obj as DataTable;
             if (dataTable != null)
             {
                 DataObjectStore dataObjectStore = dataTable.ExtendedProperties["DataSourceStore"] as DataObjectStore;
                 if (dataObjectStore != null)
                 {
                     DataColumn    dataColumn    = dataTable.Columns[binding.BindingMemberInfo.BindingField];
                     ColumnProfile columnProfile = dataColumn.ExtendedProperties["ColumnProfile"] as ColumnProfile;
                     if (!string.IsNullOrEmpty(columnProfile.DataObjectName))
                     {
                         Type dataObjectType = dataObjectStore.GetDataObjectType(columnProfile.DataObjectName);
                         if (null != dataObjectType)
                         {
                             obj          = dataObjectType;
                             propertyType = dataObjectType.GetProperty(columnProfile.MappingProperty).PropertyType;
                         }
                     }
                 }
             }
             PropertyDefinitionConstraint[] propertyDefinitionConstraints = PropertyConstraintProvider.GetPropertyDefinitionConstraints(obj, binding.BindingMemberInfo.BindingField);
             this.SetConstraintsFromType(propertyType, propertyDefinitionConstraints);
         }
     }
 }
 private void SetUncheckedValueByPropertyType(Binding binding)
 {
     if (binding.BindingManagerBase != null)
     {
         PropertyDescriptorCollection itemProperties     = binding.BindingManagerBase.GetItemProperties();
         PropertyDescriptor           propertyDescriptor = itemProperties.Find(binding.BindingMemberInfo.BindingField, true);
         if (propertyDescriptor != null)
         {
             FilterValuePropertyDescriptor filterValuePropertyDescriptor = propertyDescriptor as FilterValuePropertyDescriptor;
             Type type = (filterValuePropertyDescriptor != null) ? filterValuePropertyDescriptor.ValuePropertyType : propertyDescriptor.PropertyType;
             if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Unlimited <>) || (type.GetGenericTypeDefinition() == typeof(Nullable <>) && type.GetGenericArguments()[0].IsGenericType && type.GetGenericArguments()[0].GetGenericTypeDefinition() == typeof(Unlimited <>))))
             {
                 this.uncheckedValue = this.unlimitedString;
                 return;
             }
             this.uncheckedValue = null;
         }
     }
 }
Exemple #3
0
        private bool IsFormatModeAndBindingCompatible(DisplayFormatMode format, Binding binding)
        {
            if (binding == null || binding.BindingManagerBase == null)
            {
                return(true);
            }
            Type type = null;
            PropertyDescriptorCollection itemProperties     = binding.BindingManagerBase.GetItemProperties();
            PropertyDescriptor           propertyDescriptor = itemProperties.Find(binding.BindingMemberInfo.BindingField, true);

            if (propertyDescriptor != null)
            {
                FilterValuePropertyDescriptor filterValuePropertyDescriptor = propertyDescriptor as FilterValuePropertyDescriptor;
                if (filterValuePropertyDescriptor != null)
                {
                    type = filterValuePropertyDescriptor.ValuePropertyType;
                }
                else
                {
                    type = propertyDescriptor.PropertyType;
                }
            }
            if (type == null)
            {
                return(true);
            }
            Type type2 = null;
            Type left  = null;
            bool flag  = false;
            Type left2;

            switch (format)
            {
            case 1:
                left2 = typeof(EnhancedTimeSpan);
                break;

            case 2:
                left2 = typeof(EnhancedTimeSpan);
                break;

            case 3:
                left2 = typeof(EnhancedTimeSpan);
                break;

            case 4:
                left2 = typeof(EnhancedTimeSpan);
                break;

            case 5:
                left2 = typeof(EnhancedTimeSpan);
                flag  = true;
                break;

            case 6:
                left2 = typeof(ByteQuantifiedSize);
                break;

            case 7:
                left2 = typeof(ByteQuantifiedSize);
                break;

            case 8:
                left2 = typeof(ByteQuantifiedSize);
                flag  = true;
                break;

            case 9:
                left2 = typeof(bool);
                flag  = true;
                break;

            case 10:
                left2 = typeof(bool);
                flag  = true;
                break;

            case 11:
                left2 = typeof(bool);
                flag  = true;
                break;

            case 12:
                left2 = typeof(ADObjectId);
                if (typeof(MultiValuedProperty <ADObjectId>).IsAssignableFrom(type))
                {
                    flag = true;
                }
                break;

            case 13:
                left2 = typeof(DateTime);
                flag  = true;
                break;

            case 14:
                left2 = typeof(int);
                flag  = true;
                break;

            case 15:
                left2 = typeof(SmtpDomainWithSubdomains);
                break;

            default:
                left2 = null;
                break;
            }
            if (flag && binding.DataSourceUpdateMode != DataSourceUpdateMode.Never)
            {
                return(false);
            }
            Type type3 = type;

            if (type2 != null)
            {
                return(type.GetInterface(type2.ToString()) != null);
            }
            if (type3.IsGenericType)
            {
                if (type3.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    type3 = type3.GetGenericArguments()[0];
                }
                Type[] genericArguments = type3.GetGenericArguments();
                if (genericArguments.Length == 1 && !genericArguments[0].IsGenericParameter)
                {
                    type3 = genericArguments[0];
                }
            }
            if (type3 == typeof(EnhancedTimeSpan) || type3 == typeof(ByteQuantifiedSize) || type3 == typeof(ADObjectId))
            {
                left = type3;
            }
            if (left2 != null || left != null)
            {
                return(left2 == type3);
            }
            return(format == 0);
        }