123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using System.Linq;
- using System.Windows.Controls;
- using FWindSoft.Tools;
- namespace FWindSoft.Wpf.Controls
- {
- //输入控制
- public interface ITextInputControl
- {
- bool InputControl(string fullText);
- ItemCollection Parmerters { get; }
- }
- //为使用调用ItemCollection封装基类,如果在子类定义临时属性也可以
- public abstract class BaseTextInputControl : ITextInputControl
- {
- private ItemCollection m_Paramters;
- protected BaseTextInputControl()
- {
- ComboBox com = new ComboBox();
- this.m_Paramters = com.Items;
- this.m_Paramters.Clear();
- }
- public abstract bool InputControl(string fullText);
- public ItemCollection Parmerters
- {
- get { return this.m_Paramters; }
- }
- }
- #region 控件输入验证族
- public class AccessInteger : BaseTextInputControl
- {
- public override bool InputControl(string fullText)
- {
- if (fullText == null)
- return false;
- if (fullText.Length == 1)
- {
- if ("-".Equals(fullText) || RegexUtil.IsInteger(fullText))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- return RegexUtil.IsInteger(fullText);
- }
- }
- public class AccessPlusInteger : BaseTextInputControl
- {
- public override bool InputControl(string fullText)
- {
- return RegexUtil.IsPlusInteger(fullText);
- }
- }
- public class AccessDecimal : BaseTextInputControl
- {
- public override bool InputControl(string fullText)
- {
- if (fullText.Length == 1)
- {
- if ("-".Equals(fullText) || RegexUtil.IsDecimal(fullText))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- return RegexUtil.IsDecimal(fullText) || (fullText.Count(c => c == '.') == 1 && fullText.IndexOf('.') == fullText.Length - 1 && fullText.IndexOf("-.") < 0);//有一个小数点且在末尾
- }
- }
- public class AccessPlusDecimal : BaseTextInputControl
- {
- public override bool InputControl(string fullText)
- {
- if (fullText.Length == 1)
- {
- if (".".Equals(fullText))
- return false;
- }
- return RegexUtil.IsPlusDecimal(fullText) || (fullText.Count(c => c == '.') == 1 && fullText.IndexOf('.') == fullText.Length - 1);//有一个小数点且在末尾
- }
- }
- public class AccessRangeDecimal : BaseTextInputControl
- {
- public double MaxValue { set; get; }
- public double MinValue { set; get; }
- public override bool InputControl(string fullText)
- {
- double value;
- if (double.TryParse(fullText, out value))
- {
- if (value >= MinValue && value <= MaxValue)
- return true;
- else
- return false;
- }
- else
- {
- return false;
- }
- }
- }
- #endregion
- }
|