private void EnableControlsByVersion(BindingSource bindingSource, IVersionable dataSource)
        {
            List <Control> list = new List <Control>();

            foreach (Control item in this.removedBindings[bindingSource].Keys)
            {
                list.Add(item);
            }
            foreach (Control control in list)
            {
                List <Binding> list2 = new List <Binding>(this.removedBindings[bindingSource][control]);
                foreach (Binding binding in list2)
                {
                    ExchangeObjectVersion propertyDefinitionVersion = PropertyConstraintProvider.GetPropertyDefinitionVersion(dataSource, binding.BindingMemberInfo.BindingMember);
                    if (!dataSource.ExchangeVersion.IsOlderThan(propertyDefinitionVersion))
                    {
                        control.DataBindings.Add(binding);
                        this.removedBindings[bindingSource][control].Remove(binding);
                        if (this.removedBindings[bindingSource][control].Count == 0)
                        {
                            ISpecifyPropertyState specifyPropertyState = control as ISpecifyPropertyState;
                            if (specifyPropertyState != null)
                            {
                                specifyPropertyState.SetPropertyState(binding.PropertyName, PropertyState.Normal, string.Empty);
                            }
                            else
                            {
                                control.Enabled = true;
                            }
                        }
                    }
                }
            }
        }
        private void DisableControlsByVersion(BindingSource bindingSource, IVersionable dataSource)
        {
            BindingManagerBase bindingManagerBase = this.ContainerBindingContext[bindingSource];

            for (int i = bindingManagerBase.Bindings.Count - 1; i >= 0; i--)
            {
                Binding binding = bindingManagerBase.Bindings[i];
                ExchangeObjectVersion propertyDefinitionVersion = PropertyConstraintProvider.GetPropertyDefinitionVersion(dataSource, binding.BindingMemberInfo.BindingMember);
                if (dataSource.ExchangeVersion.IsOlderThan(propertyDefinitionVersion))
                {
                    if (!this.removedBindings[bindingSource].ContainsKey(binding.Control))
                    {
                        this.removedBindings[bindingSource][binding.Control] = new List <Binding>();
                    }
                    this.removedBindings[bindingSource][binding.Control].Add(binding);
                    ISpecifyPropertyState specifyPropertyState = binding.Control as ISpecifyPropertyState;
                    if (specifyPropertyState != null)
                    {
                        specifyPropertyState.SetPropertyState(binding.PropertyName, PropertyState.UnsupportedVersion, Strings.FeatureVersionMismatchDescription(propertyDefinitionVersion.ExchangeBuild));
                    }
                    else
                    {
                        binding.Control.Enabled = false;
                    }
                    binding.Control.DataBindings.Remove(binding);
                }
            }
        }
Exemplo n.º 3
0
        private void ValidateByRangedValueConstraint(Type constraintType, PropertyDefinitionConstraint constraint, object constraintSource, object value)
        {
            PropertyDefinition propertyDefinition = PropertyConstraintProvider.GetPropertyDefinition(constraintSource.GetType(), this.ownerControl.DataBindings[this.ownerBindingPropertyName].BindingMemberInfo.BindingField);

            if (propertyDefinition != null)
            {
                PropertyConstraintViolationError propertyConstraintViolationError = constraint.Validate(value, propertyDefinition, null);
                if (propertyConstraintViolationError != null)
                {
                    this.ThrowRangeConstraintException(constraintType, constraint, constraintSource, value);
                }
            }
        }
Exemplo n.º 4
0
        public virtual void Retrieve(Type dataObjectType, string propertyName, out Type objectType, out PropertyDefinition propertyDefinition)
        {
            PropertyInfo propertyEx = dataObjectType.GetPropertyEx(propertyName);

            if (propertyEx != null)
            {
                objectType = propertyEx.PropertyType;
            }
            else
            {
                objectType = null;
            }
            propertyDefinition = PropertyConstraintProvider.GetPropertyDefinition(dataObjectType, propertyName);
        }
Exemplo n.º 5
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 DataBindings_CollectionChanged(object sender, CollectionChangeEventArgs e)
        {
            Binding binding = e.Element as Binding;

            if (e.Action == CollectionChangeAction.Add && (binding.PropertyName == "Text" || binding.PropertyName == "Value"))
            {
                object constraintProvider = (binding.DataSource is BindingSource) ? ((BindingSource)binding.DataSource).DataSource : binding.DataSource;
                PropertyDefinitionConstraint[] propertyDefinitionConstraints = PropertyConstraintProvider.GetPropertyDefinitionConstraints(constraintProvider, binding.BindingMemberInfo.BindingField);
                for (int i = 0; i < propertyDefinitionConstraints.Length; i++)
                {
                    if (propertyDefinitionConstraints[i].GetType() == typeof(RangedValueConstraint <int>))
                    {
                        RangedValueConstraint <int> rangedValueConstraint = (RangedValueConstraint <int>)propertyDefinitionConstraints[i];
                        base.Maximum = rangedValueConstraint.MaximumValue;
                        base.Minimum = rangedValueConstraint.MinimumValue;
                        return;
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void GoThroughRangedConstraint(TextBoxConstraintProvider.DealWithRangedConstraint doWork, object value)
        {
            object dataSource = this.ownerControl.DataBindings[this.ownerBindingPropertyName].DataSource;

            while (dataSource is BindingSource)
            {
                dataSource = ((BindingSource)dataSource).DataSource;
            }
            PropertyDefinitionConstraint[] propertyDefinitionConstraints = PropertyConstraintProvider.GetPropertyDefinitionConstraints(dataSource, this.ownerControl.DataBindings[this.ownerBindingPropertyName].BindingMemberInfo.BindingField);
            foreach (PropertyDefinitionConstraint propertyDefinitionConstraint in propertyDefinitionConstraints)
            {
                Type type = propertyDefinitionConstraint.GetType();
                if (type.IsGenericType)
                {
                    Type genericTypeDefinition = type.GetGenericTypeDefinition();
                    if (typeof(RangedValueConstraint <>) == genericTypeDefinition || typeof(RangedNullableUnlimitedConstraint <>) == genericTypeDefinition || typeof(RangedNullableValueConstraint <>) == genericTypeDefinition || typeof(RangedUnlimitedConstraint <>) == genericTypeDefinition)
                    {
                        doWork(type, propertyDefinitionConstraint, dataSource, value);
                    }
                }
            }
        }