ValidatorBox.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Bowin.Web.Controls.Mvc
  6. {
  7. public class ValidatorBox
  8. {
  9. public ValidatorBox()
  10. {
  11. this.ValidType = "baseRequired";
  12. this.ValidatorClass = "easyui-validatebox";
  13. this.Required = true;
  14. this.MissingMessage = "必填";
  15. //this.InvalidMessage = "输入的内容不符合,请检查";
  16. this.InvalidMessage = "";
  17. this.MessageTipPosition = ValidatorBox.TipPosition.Default;
  18. ValidTypeParamList = new List<string>();
  19. }
  20. public string ValidatorClass { get; private set; }
  21. public bool Required { get; set; }
  22. public string ValidType { get; set; }
  23. public string MissingMessage { get; set; }
  24. public string InvalidMessage { get; set; }
  25. public TipPosition MessageTipPosition { get; set; }
  26. public virtual List<string> ValidTypeParamList { get; set; }
  27. public virtual Dictionary<string, string> GetOptions()
  28. {
  29. Dictionary<string, string> options = new Dictionary<string, string>();
  30. options.Add(ValidatorBoxOptionKeys.REQUIRED, this.Required.ToString().ToLower());
  31. if (!string.IsNullOrEmpty(this.ValidType))
  32. {
  33. options.Add(ValidatorBoxOptionKeys.VALIDTYPE, this.ValidType );
  34. if (this.ValidTypeParamList.Any())
  35. {
  36. //options[ValidatorBoxOptionKeys.VALIDTYPE] += "[" + string.Join("','", this.ValidTypeParamList) + "]";
  37. }
  38. }
  39. if (!string.IsNullOrEmpty(this.MissingMessage))
  40. {
  41. options.Add(ValidatorBoxOptionKeys.MISSINGMESSAGE, this.MissingMessage );
  42. }
  43. if (!string.IsNullOrEmpty(this.InvalidMessage))
  44. {
  45. options.Add(ValidatorBoxOptionKeys.INVALIDMESSAGE, this.InvalidMessage );
  46. }
  47. if (this.MessageTipPosition != TipPosition.Default)
  48. {
  49. options.Add(ValidatorBoxOptionKeys.TIPPOSITION, TipPositionHelper.ToString(this.MessageTipPosition) );
  50. }
  51. return options;
  52. }
  53. public class ValidatorBoxOptionKeys
  54. {
  55. public static readonly string REQUIRED = "required";
  56. public static readonly string VALIDTYPE = "validType";
  57. public static readonly string MISSINGMESSAGE = "missingMessage";
  58. public static readonly string INVALIDMESSAGE = "invalidMessage";
  59. public static readonly string TIPPOSITION = "tipPosition";
  60. }
  61. public enum TipPosition
  62. {
  63. Left,
  64. Right,
  65. Default
  66. }
  67. class TipPositionHelper
  68. {
  69. public static string ToString(TipPosition tipPosition)
  70. {
  71. if (tipPosition == TipPosition.Left)
  72. {
  73. return "left";
  74. }
  75. return "right";
  76. }
  77. }
  78. }
  79. public class MobileValidator : ValidatorBox
  80. {
  81. public MobileValidator()
  82. {
  83. this.ValidType = "mobile";
  84. this.Required = true;
  85. }
  86. }
  87. public class TelNumberValidator : ValidatorBox
  88. {
  89. public TelNumberValidator()
  90. {
  91. this.ValidType = "telnumber";
  92. this.Required = true;
  93. }
  94. }
  95. public class IDCardValidator : ValidatorBox
  96. {
  97. public IDCardValidator()
  98. {
  99. this.ValidType = "IDCard";
  100. this.Required = true;
  101. }
  102. }
  103. public class OnlyMoneyValidator : ValidatorBox
  104. {
  105. public OnlyMoneyValidator()
  106. {
  107. this.ValidType = "onlyMoney";
  108. this.Required = true;
  109. }
  110. }
  111. public class OnlyDiscountValidator : ValidatorBox
  112. {
  113. public OnlyDiscountValidator()
  114. {
  115. this.ValidType = "onlyDiscount";
  116. this.Required = true;
  117. }
  118. }
  119. public class OnlyNumberValidator : ValidatorBox
  120. {
  121. public OnlyNumberValidator()
  122. {
  123. this.ValidType = "onlyNumber";
  124. this.Required = true;
  125. }
  126. }
  127. public class OnlyCharValidator : ValidatorBox
  128. {
  129. public OnlyCharValidator()
  130. {
  131. this.ValidType = "onlyChar";
  132. this.Required = true;
  133. }
  134. }
  135. }