Example #1
0
        /// <summary>
        /// Append extender controls to current cell based on data type of given property.
        /// </summary>
        /// <param name="tableCell">Current table cell.</param>
        /// <param name="propertyName">Property name.</param>
        /// <param name="criteriaIndex">Index of the criteria.</param>
        private void UpdateValueControl(TableCell tableCell, string propertyName, int criteriaIndex)
        {
            DataTypes type = DataTypes.String;

            type = GetPropertyType(propertyName);

            switch (type)
            {
            case DataTypes.DateTime:
            {
                if (tableCell.FindControl(_Calender) == null)
                {
                    RangeValidator rngValidator = new RangeValidator();
                    rngValidator.ID           = _rangeValidatorId;
                    rngValidator.Type         = ValidationDataType.Date;
                    rngValidator.MinimumValue = DateTime.MinValue.Date.AddYears(_minimumDate).ToString(CoreHelper.GetDateFormat(), CultureInfo.InvariantCulture);
                    rngValidator.MaximumValue = DateTime.MaxValue.Date.AddYears(_maximumYearDate).AddMonths(_maximumMonthDate).AddDays(_maximumDayDate).ToString(CoreHelper.GetDateFormat(), CultureInfo.InvariantCulture);
                    rngValidator.ErrorMessage = string.Format(CultureInfo.CurrentCulture,
                                                              Resources.GlobalResource.InvalidCriteria, (criteriaIndex + 1), propertyName, CoreHelper.GetDateFormat());
                    rngValidator.Text              = _Star;
                    rngValidator.Display           = ValidatorDisplay.Dynamic;
                    rngValidator.ControlToValidate = _Value;
                    rngValidator.ValidationGroup   = ValidationGroup;
                    tableCell.Controls.Add(rngValidator);
                }
                break;
            }

            case DataTypes.Int16:
            case DataTypes.Int32:
            {
                if (tableCell.FindControl(_MaskedEdit) == null)
                {
                    RangeValidator rngValidator = new RangeValidator();
                    rngValidator.ID = _rangeValidatorId;
                    rngValidator.ControlToValidate = _Value;
                    rngValidator.ValidationGroup   = ValidationGroup;
                    rngValidator.Display           = ValidatorDisplay.Dynamic;
                    rngValidator.Type = ValidationDataType.Integer;
                    rngValidator.Text = _Star;
                    if (type == DataTypes.Int16)
                    {
                        rngValidator.MinimumValue = short.MinValue.ToString(CultureInfo.InvariantCulture);
                        rngValidator.MaximumValue = short.MaxValue.ToString(CultureInfo.InvariantCulture);
                    }
                    else if (type == DataTypes.Int32)
                    {
                        rngValidator.MinimumValue = int.MinValue.ToString(CultureInfo.InvariantCulture);
                        rngValidator.MaximumValue = int.MaxValue.ToString(CultureInfo.InvariantCulture);
                    }
                    rngValidator.ErrorMessage = string.Format(CultureInfo.InvariantCulture, Resources.GlobalResource.InvalidCriteriaNumber, (criteriaIndex + 1), propertyName);;
                    tableCell.Controls.Add(rngValidator);
                }
                break;
            }

            case DataTypes.Int64:
            {
                CustomValidator customValidator = new CustomValidator();
                customValidator.ID = _customValidatorId;
                customValidator.ControlToValidate = _Value;
                customValidator.ValidationGroup   = ValidationGroup;
                customValidator.Display           = ValidatorDisplay.Dynamic;
                customValidator.Text = _Star;
                customValidator.ClientValidationFunction = _longTypeRangeValidatorScript;
                customValidator.ErrorMessage             = string.Format(CultureInfo.InvariantCulture, Resources.GlobalResource.InvalidCriteriaNumber, (criteriaIndex + 1), propertyName);;
                tableCell.Controls.Add(customValidator);
                break;
            }
            }
        }