コード例 #1
0
        private NumericValidationDataType GetNumericValidatorDataType(BocTextValueType valueType)
        {
            switch (valueType)
            {
            case BocTextValueType.Byte:
                return(NumericValidationDataType.Byte);

            case BocTextValueType.Int16:
                return(NumericValidationDataType.Int16);

            case BocTextValueType.Int32:
                return(NumericValidationDataType.Int32);

            case BocTextValueType.Int64:
                return(NumericValidationDataType.Int64);

            case BocTextValueType.Decimal:
                return(NumericValidationDataType.Decimal);

            case BocTextValueType.Double:
                return(NumericValidationDataType.Double);

            case BocTextValueType.Single:
                return(NumericValidationDataType.Single);

            default:
                throw new ArgumentOutOfRangeException("valueType", valueType, "Only numeric value types are supported.");
            }
        }
コード例 #2
0
        private BaseValidator CreateTypeValidator(IResourceManager resourceManager)
        {
            BocTextValueType valueType = ActualValueType;

            switch (valueType)
            {
            case BocTextValueType.Undefined:
                return(null);

            case BocTextValueType.String:
                return(null);

            case BocTextValueType.DateTime:
                return(CreateTypeIsDateTimeValidator(resourceManager));

            case BocTextValueType.Date:
                return(CreateTypeIsDateValidator(resourceManager));

            case BocTextValueType.Byte:
            case BocTextValueType.Int16:
            case BocTextValueType.Int32:
            case BocTextValueType.Int64:
            case BocTextValueType.Decimal:
            case BocTextValueType.Double:
            case BocTextValueType.Single:
                return(CreateTypeIsNumericValidator(valueType, resourceManager));

            default:
            {
                throw new InvalidOperationException(
                          "BocTextValue '" + ID + "': Cannot convert " + valueType + " to type " + typeof(ValidationDataType).FullName + ".");
            }
            }
        }
コード例 #3
0
 /// <summary>
 /// Loads <see cref="Text"/>, <see cref="ValueType"/> and <see cref="ActualValueType"/> in addition to the base state.
 /// </summary>
 /// <param name="savedState">The control state object created by <see cref="SaveControlState"/>.</param>
 protected override void LoadControlState(object savedState)
 {
     object[] values = (object[])savedState;
     base.LoadControlState(values[0]);
     _text            = (string)values[1];
     _valueType       = (BocTextValueType)values[2];
     _actualValueType = (BocTextValueType)values[3];
 }
コード例 #4
0
        private static ValidationDataType GetValidationDataType(BocTextValueType valueType)
        {
            switch (valueType)
            {
            case BocTextValueType.Date:
                return(ValidationDataType.Date);

            case BocTextValueType.DateTime:
                return(ValidationDataType.Date);

            case BocTextValueType.Int32:
                return(ValidationDataType.Integer);

            case BocTextValueType.Double:
                return(ValidationDataType.Double);

            default:
                throw new ArgumentException("Cannot convert " + valueType.ToString() + " to type " + typeof(ValidationDataType).FullName + ".");
            }
        }
コード例 #5
0
        private NumberStyles GetNumberStyle(BocTextValueType valueType)
        {
            switch (valueType)
            {
            case BocTextValueType.Byte:
            case BocTextValueType.Int16:
            case BocTextValueType.Int32:
            case BocTextValueType.Int64:
                return(NumberStyles.Number & ~NumberStyles.AllowDecimalPoint);

            case BocTextValueType.Decimal:
                return(NumberStyles.Number);

            case BocTextValueType.Double:
            case BocTextValueType.Single:
                return(NumberStyles.Number | NumberStyles.AllowExponent);

            default:
                throw new ArgumentOutOfRangeException("valueType", valueType, "Only numeric value types are supported.");
            }
        }
コード例 #6
0
        public static BaseValidator[] CreateValidators(BocTextValue textValueControl, string baseID)
        {
            ArrayList validators = new ArrayList();

            if (textValueControl.IsRequired)
            {
                RequiredFieldValidator requiredValidator = new RequiredFieldValidator();
                requiredValidator.ID = baseID + "Required";
                requiredValidator.ControlToValidate = textValueControl.TargetControl.ID;
                requiredValidator.ErrorMessage      = "Enter a value.";
                requiredValidator.Display           = ValidatorDisplay.Dynamic;
                validators.Add(requiredValidator);
            }

            BocTextValueType valueType = textValueControl.ActualValueType;

            if (valueType == BocTextValueType.DateTime)
            {
                DateTimeValidator typeValidator = new DateTimeValidator();
                typeValidator.ID = baseID + "Type";
                typeValidator.ControlToValidate = textValueControl.TargetControl.ID;
                typeValidator.ErrorMessage      = "Wrong type.";
                typeValidator.Display           = ValidatorDisplay.Dynamic;
                validators.Add(typeValidator);
            }
            else if (valueType != BocTextValueType.Undefined && valueType != BocTextValueType.String)
            {
                CompareValidator typeValidator = new CompareValidator();
                typeValidator.ID = baseID + "Type";
                typeValidator.ControlToValidate = textValueControl.TargetControl.ID;
                typeValidator.Operator          = ValidationCompareOperator.DataTypeCheck;
                typeValidator.Type         = GetValidationDataType(valueType);
                typeValidator.ErrorMessage = "Wrong type.";
                typeValidator.Display      = ValidatorDisplay.Dynamic;
                //typeValidator.EnableClientScript = false;
                validators.Add(typeValidator);
            }

            return((BaseValidator[])validators.ToArray(typeof(BaseValidator)));
        }
コード例 #7
0
        private NumericValidator CreateTypeIsNumericValidator(BocTextValueType valueType, IResourceManager resourceManager)
        {
            NumericValidator typeValidator = new NumericValidator();

            typeValidator.ID = ID + "_ValidatorType";
            typeValidator.ControlToValidate = TargetControl.ID;
            if (Property != null)
            {
                typeValidator.AllowNegative = ((IBusinessObjectNumericProperty)Property).AllowNegative;
            }
            typeValidator.DataType    = GetNumericValidatorDataType(valueType);
            typeValidator.NumberStyle = GetNumberStyle(valueType);
            if (string.IsNullOrEmpty(ErrorMessage))
            {
                typeValidator.ErrorMessage = resourceManager.GetString(GetNumericValidatorErrorMessage(GetNumericValidatorDataType(valueType)));
            }
            else
            {
                typeValidator.ErrorMessage = ErrorMessage;
            }
            return(typeValidator);
        }
コード例 #8
0
        /// <summary>
        ///   Refreshes all properties of <see cref="BocTextValue"/> that depend on the current value of
        ///   <see cref="BusinessObjectBoundWebControl.Property"/>.
        /// </summary>
        private void RefreshPropertiesFromObjectModel()
        {
            if (Property != null)
            {
                if (_valueType == BocTextValueType.Undefined)
                {
                    _actualValueType = GetBocTextValueType(Property);
                }

                IBusinessObjectStringProperty stringProperty = Property as IBusinessObjectStringProperty;
                if (stringProperty != null)
                {
                    if (TextBoxStyle.MaxLength == null)
                    {
                        int?length = stringProperty.MaxLength;
                        if (length.HasValue)
                        {
                            TextBoxStyle.MaxLength = length.Value;
                        }
                    }
                }
            }
        }