123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bowin.Web.Controls.Mvc
- {
- public class ValidatorBox
- {
- public ValidatorBox()
- {
- this.ValidType = "baseRequired";
- this.ValidatorClass = "easyui-validatebox";
- this.Required = true;
- this.MissingMessage = "必填";
- //this.InvalidMessage = "输入的内容不符合,请检查";
- this.InvalidMessage = "";
- this.MessageTipPosition = ValidatorBox.TipPosition.Default;
- ValidTypeParamList = new List<string>();
- }
- public string ValidatorClass { get; private set; }
- public bool Required { get; set; }
- public string ValidType { get; set; }
- public string MissingMessage { get; set; }
- public string InvalidMessage { get; set; }
- public TipPosition MessageTipPosition { get; set; }
- public virtual List<string> ValidTypeParamList { get; set; }
- public virtual Dictionary<string, string> GetOptions()
- {
- Dictionary<string, string> options = new Dictionary<string, string>();
- options.Add(ValidatorBoxOptionKeys.REQUIRED, this.Required.ToString().ToLower());
- if (!string.IsNullOrEmpty(this.ValidType))
- {
- options.Add(ValidatorBoxOptionKeys.VALIDTYPE, this.ValidType );
- if (this.ValidTypeParamList.Any())
- {
- //options[ValidatorBoxOptionKeys.VALIDTYPE] += "[" + string.Join("','", this.ValidTypeParamList) + "]";
- }
- }
- if (!string.IsNullOrEmpty(this.MissingMessage))
- {
- options.Add(ValidatorBoxOptionKeys.MISSINGMESSAGE, this.MissingMessage );
- }
- if (!string.IsNullOrEmpty(this.InvalidMessage))
- {
- options.Add(ValidatorBoxOptionKeys.INVALIDMESSAGE, this.InvalidMessage );
- }
- if (this.MessageTipPosition != TipPosition.Default)
- {
- options.Add(ValidatorBoxOptionKeys.TIPPOSITION, TipPositionHelper.ToString(this.MessageTipPosition) );
- }
- return options;
- }
- public class ValidatorBoxOptionKeys
- {
- public static readonly string REQUIRED = "required";
- public static readonly string VALIDTYPE = "validType";
- public static readonly string MISSINGMESSAGE = "missingMessage";
- public static readonly string INVALIDMESSAGE = "invalidMessage";
- public static readonly string TIPPOSITION = "tipPosition";
- }
- public enum TipPosition
- {
- Left,
- Right,
- Default
- }
- class TipPositionHelper
- {
- public static string ToString(TipPosition tipPosition)
- {
- if (tipPosition == TipPosition.Left)
- {
- return "left";
- }
- return "right";
- }
- }
- }
- public class MobileValidator : ValidatorBox
- {
- public MobileValidator()
- {
- this.ValidType = "mobile";
- this.Required = true;
- }
- }
- public class TelNumberValidator : ValidatorBox
- {
- public TelNumberValidator()
- {
- this.ValidType = "telnumber";
- this.Required = true;
- }
- }
- public class IDCardValidator : ValidatorBox
- {
- public IDCardValidator()
- {
- this.ValidType = "IDCard";
- this.Required = true;
- }
- }
-
- public class OnlyMoneyValidator : ValidatorBox
- {
- public OnlyMoneyValidator()
- {
- this.ValidType = "onlyMoney";
- this.Required = true;
- }
- }
- public class OnlyDiscountValidator : ValidatorBox
- {
- public OnlyDiscountValidator()
- {
- this.ValidType = "onlyDiscount";
- this.Required = true;
- }
- }
- public class OnlyNumberValidator : ValidatorBox
- {
- public OnlyNumberValidator()
- {
- this.ValidType = "onlyNumber";
- this.Required = true;
- }
- }
- public class OnlyCharValidator : ValidatorBox
- {
- public OnlyCharValidator()
- {
- this.ValidType = "onlyChar";
- this.Required = true;
- }
- }
- }
|