/// <summary> /// The create. /// </summary> /// <param name="numericAttribute"> /// The numeric attribute. /// </param> /// <param name="rangeAttribute"> /// The range attribute. /// </param> /// <returns> /// The <see cref="NumericFieldOptions"/>. /// </returns> public static NumericFieldOptions Create(NumericAttribute numericAttribute, RangeAttribute rangeAttribute) { var result = new NumericFieldOptions(); if (numericAttribute == null) { result.DisplayFormat = NumericTypes.Numeric; result.NumberOfDecimals = 0; } else { result.DisplayFormat = numericAttribute.NumericType; result.NumberOfDecimals = numericAttribute.NumberOfDigits; } if (rangeAttribute == null) { result.Min = 0; result.Max = 999999999; } else { result.Min = rangeAttribute.Minimum; result.Max = rangeAttribute.Maximum; } return result; }
public override IEnumerable <ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context) { var allValidators = base.GetValidators(metadata, context); var validators = new List <ModelValidator>(); foreach (var v in allValidators) { if (v.GetType().Name == "NumericModelValidator") { NumericAttribute attribute = new NumericAttribute { ErrorMessage = Resources.FieldMustBeNumeric }; DataAnnotationsModelValidator validator = new DataAnnotationsModelValidator(metadata, context, attribute); validators.Add(validator); } else if (v.GetType().Name == "DateModelValidator") { DateAttribute attribute = new DateAttribute { ErrorMessage = Resources.FieldMustBeDate }; DataAnnotationsModelValidator validator = new DataAnnotationsModelValidator(metadata, context, attribute); validators.Add(validator); } else { validators.Add(v); } } return(validators); }
public void PrecisionAttribute_SetsErrorMessage() { String actual = new NumericAttribute(5, 2).FormatErrorMessage("Test"); String expected = Validation.For("Numeric", "Test", 3, 2); Assert.Equal(expected, actual); }
public void ErrorMessageTest() { var attribute = new NumericAttribute(); attribute.ErrorMessage = "SampleErrorMessage"; const string invalidValue = "a"; var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null)); Assert.AreEqual("SampleErrorMessage", result.ErrorMessage); }
public static int GetNumericAtt<T>(this T id) { MemberInfo memberInfo = typeof(T).GetMember(id.ToString()).FirstOrDefault(); if (memberInfo != null) { NumericAttribute attribute = (NumericAttribute) memberInfo.GetCustomAttributes(typeof(NumericAttribute), false).FirstOrDefault(); return attribute.Key; } return 0; }
public AttributeDatum <double> GetNumericAttributeDatum(ConfigFileModel item) { var sqlConnection = new SqlConnection(item.Connection.UserName, item.Connection.Password, item.Connection.Server, item.Connection.DataSource); var numericAttribute = new NumericAttribute(item.AttributeName, sqlConnection, Convert.ToDouble(item.DefaultValue), item.Maximum, item.Minimum); var sectionLocation = new SectionLocation("I dont know yet"); var numericAttributeDatum = new AttributeDatum <double>(numericAttribute, 5, sectionLocation, DateTime.Now); return(numericAttributeDatum); }
public void ErrorResourcesTest() { var attribute = new NumericAttribute(); attribute.ErrorMessageResourceName = "ErrorMessage"; attribute.ErrorMessageResourceType = typeof(ErrorResources); const string invalidValue = "a"; var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null)); Assert.AreEqual(ErrorResources.ErrorMessage, result.ErrorMessage); }
public void GlobalizedErrorResourcesTest() { System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX"); var attribute = new NumericAttribute(); attribute.ErrorMessageResourceName = "ErrorMessage"; attribute.ErrorMessageResourceType = typeof(ErrorResources); const string invalidValue = "a"; var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null)); Assert.AreEqual("mensaje de error", result.ErrorMessage); }
public void IsValidTests() { var attribute = new NumericAttribute(); Assert.IsTrue(attribute.IsValid(null)); // Don't check for required Assert.IsTrue(attribute.IsValid("1234")); Assert.IsTrue(attribute.IsValid("1234.2342")); Assert.IsTrue(attribute.IsValid("12e5")); Assert.IsTrue(attribute.IsValid("12.90")); Assert.IsTrue(attribute.IsValid(14)); Assert.IsTrue(attribute.IsValid(14.50)); Assert.IsFalse(attribute.IsValid("$3.50")); Assert.IsFalse(attribute.IsValid("12abc")); Assert.IsFalse(attribute.IsValid(DateTime.Now)); Assert.IsFalse(attribute.IsValid("fourteen")); }
protected override IEnumerable <ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable <Attribute> attributes) { if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } Type type = metadata.ModelType; NumericAttribute numericAttribute = attributes.OfType <NumericAttribute>().SingleOrDefault(); if (IsNumericType(type)) { yield return(new NumericModelValidator(metadata, context, numericAttribute)); } }
public override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context) { var allValidators = base.GetValidators(metadata, context); var validators = new List<ModelValidator>(); foreach (var v in allValidators) { //如果不是系统默认的数字验证类,则用系统的 if (v.GetType().Name != "NumericModelValidator") { validators.Add(v); } else { //用自定义替换系统的数字验证 var attribute = new NumericAttribute { ErrorMessage = TranslationHelper.L("Custom.NumericModelValidator") }; var validator = new DataAnnotationsModelValidator(metadata, context, attribute); validators.Add(validator); } } return validators; }
public override IEnumerable <ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context) { var allValidators = base.GetValidators(metadata, context); var validators = new List <ModelValidator>(); foreach (var v in allValidators) { if (v.GetType().Name != "NumericModelValidator") { validators.Add(v); } else { NumericAttribute attribute = new NumericAttribute { ErrorMessage = "{0}Need a valid number" }; DataAnnotationsModelValidator validator = new DataAnnotationsModelValidator(metadata, context, attribute); validators.Add(validator); } } return(validators); }
private static string WriteExtenders(PropertyInfo p, out bool isValidatable) { isValidatable = false; StringBuilder sb = new StringBuilder(); sb.Append(".extend({ editState : false, disableValidation : false, empty : true })"); RequiredAttribute requiredAttribute = p.GetCustomAttribute <RequiredAttribute>(); if (requiredAttribute != null) { sb.Append($".extend({{ required: {{ message: \"{requiredAttribute.FormatErrorMessage(p.Name)}\", onlyIf: function() {{ return ko.utils.isPropertyValidatable(self, \"{ p.Name}\"); }} }} }})"); isValidatable = true; } MinLengthAttribute minLengthAttribute = p.GetCustomAttribute <MinLengthAttribute>(); if (minLengthAttribute != null) { sb.Append(string.Format(".extend({ minLength: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", minLengthAttribute.FormatErrorMessage(p.Name), minLengthAttribute.Length, p.Name)); isValidatable = true; } MaxLengthAttribute maxLengthAttribute = p.GetCustomAttribute <MaxLengthAttribute>(); if (maxLengthAttribute != null) { sb.Append(string.Format(".extend({ maxLength: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", maxLengthAttribute.FormatErrorMessage(p.Name), maxLengthAttribute.Length, p.Name)); isValidatable = true; } RegularExpressionAttribute regularExpressionAttribute = p.GetCustomAttribute <RegularExpressionAttribute>(); if (regularExpressionAttribute != null) { sb.Append(string.Format(".extend({ pattern: { message: \"{0}\", params: /{1}/, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", regularExpressionAttribute.FormatErrorMessage(p.Name), regularExpressionAttribute.Pattern, p.Name)); isValidatable = true; } UrlAttribute urlAttribute = p.GetCustomAttribute <UrlAttribute>(); if (urlAttribute != null) { sb.Append(string.Format(".extend({ pattern: { message: \"{0}\", params: /{1}/, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", urlAttribute.FormatErrorMessage(p.Name), urlAttribute, p.Name)); isValidatable = true; } DateAttribute dateAttribute = p.GetCustomAttribute <DateAttribute>(); if (dateAttribute != null) { sb.Append(string.Format(".extend({ date: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } })", dateAttribute.FormatErrorMessage(p.Name), p.Name)); isValidatable = true; } NumericAttribute numericAttribute = p.GetCustomAttribute <NumericAttribute>(); if (numericAttribute != null) { sb.Append( string.Format(".extend({ number: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } }).extend({ numeric: {2} })", numericAttribute.FormatErrorMessage(p.Name), p.Name, numericAttribute.Precision)); isValidatable = true; } EmailAttribute emailAttribute = p.GetCustomAttribute <EmailAttribute>(); if (emailAttribute != null) { sb.Append(string.Format(".extend({ email: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } })", emailAttribute.FormatErrorMessage(p.Name), p.Name)); isValidatable = true; } DigitsAttribute digitsAttribute = p.GetCustomAttribute <DigitsAttribute>(); if (digitsAttribute != null) { sb.Append(string.Format(".extend({ digit: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } }).extend({ numeric: 0 })", digitsAttribute.FormatErrorMessage(p.Name), p.Name)); isValidatable = true; } MinAttribute minAttribute = p.GetCustomAttribute <MinAttribute>(); if (minAttribute != null) { sb.Append(string.Format(".extend({ min: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", minAttribute.FormatErrorMessage(p.Name), minAttribute.Min, p.Name)); isValidatable = true; } MaxAttribute maxAttribute = p.GetCustomAttribute <MaxAttribute>(); if (maxAttribute != null) { sb.Append(string.Format(".extend({ max: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", maxAttribute.FormatErrorMessage(p.Name), maxAttribute.Max, p.Name)); isValidatable = true; } EqualToAttribute equalToAttribute = p.GetCustomAttribute <EqualToAttribute>(); if (equalToAttribute != null) { sb.Append(string.Format(".extend({ equal: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", equalToAttribute.FormatErrorMessage(p.Name), equalToAttribute.OtherProperty, p.Name)); isValidatable = true; } CompareAttribute compareAttribute = p.GetCustomAttribute <CompareAttribute>(); if (compareAttribute != null) { sb.Append(string.Format(".extend({ equal: { message: \"{0}\", params: \"{1}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", compareAttribute.FormatErrorMessage(p.Name), compareAttribute.OtherProperty, p.Name)); isValidatable = true; } FormatterAttribute formatterAttribute = p.GetCustomAttribute <FormatterAttribute>(); if (formatterAttribute != null) { sb.Append(string.Format(".formatted({0}, {1})", formatterAttribute.Formatter, JsonConvert.SerializeObject(formatterAttribute.Arguments))); } return(sb.ToString()); }
public NumericAttributeChange() { NumericAttribute = new NumericAttribute(); }
public NumericAttributeChange(NumericAttribute numericAttribute, decimal valueToAdd, bool isUserEntered) { NumericAttribute = numericAttribute; ValueToAdd = valueToAdd; IsUserEntered = isUserEntered; }
/// <summary> /// Initializes a new instance of the <see cref="FieldParametres"/> class. /// </summary> public FieldParametres() { SectionName = string.Empty; FieldPosition = 0; WidthPercentage = 0; DisplayName = string.Empty; FieldEditor = string.Empty; IsSingleCrossRef = false; IsMultiCrossRef = false; DisplayFieldList = new List<string>(); CrossRefProcessName = string.Empty; IsReverseCrossRef = false; IsMultiReverseCrossRef = false; ImageFieldSize = new PictureOptionsAttribute(96, 96, 320, 240, false); UndefinedLabel = new UndefinedLabelAttribute(null); TrueLabel = new TrueLabelAttribute(null); FalseLabel = new FalseLabelAttribute(null); DateTimeFormat = new DateTimeFormatAttribute(Cebos.Veyron.SharedTypes.DateTimeFormat.DateTime.ToString()); Numeric = new NumericAttribute(); FieldType = new FieldTypeAttribute(ColumnTypes.String); }
/// <summary> /// Gets the numeric field view model vm. /// </summary> /// <param name="prop">The property.</param> /// <param name="model">The model.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldEditorAttr">The field editor attribute.</param> /// <param name="numericAttr">The numeric attribute.</param> /// <returns></returns> private NumericFieldViewModel GetNumericFieldViewModelVM(PropertyInfo prop, IEditableRoot model, PromptAttribute promptAttr, DisplayAttribute display, FieldEditorAttribute fieldEditorAttr, NumericAttribute numericAttr) { var vm = NumericFieldViewModelFactory.CreateExport().Value; SetupField(prop, promptAttr, display, vm, model, 0); vm.FieldType = GetFieldEditor(prop, fieldEditorAttr); vm.NumericType = numericAttr.NumericType; vm.NumberOfDigits = numericAttr.NumberOfDigits; return vm; }
public NumericModelValidator(ModelMetadata metadata, ControllerContext controllerContext, NumericAttribute numericAttribute) : base(metadata, controllerContext) { _numericAttribute = numericAttribute; }
public NumericAttributeTests() { attribute = new NumericAttribute(5, 2); }