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(); } 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 ValidTypeParamList { get; set; } public virtual Dictionary GetOptions() { Dictionary options = new Dictionary(); 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; } } }