You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.8 KiB
103 lines
2.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Stone.Common
|
|
{
|
|
public class MyErrorProvider
|
|
{
|
|
private static ErrorProvider errorProvider = new ErrorProvider();
|
|
static MyErrorProvider()
|
|
{
|
|
errorProvider.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
|
|
}
|
|
|
|
public static void SetError(Control control, string error)
|
|
{
|
|
errorProvider.SetError(control, error);
|
|
control.Focus();
|
|
}
|
|
|
|
public static void ClearError(Control control)
|
|
{
|
|
errorProvider.SetError(control, "");
|
|
}
|
|
}
|
|
|
|
public class MyValidator
|
|
{
|
|
/// <summary>
|
|
/// 判断输入是否为空!
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
/// <param name="error"></param>
|
|
/// <returns></returns>
|
|
public static bool IsEmpty(Control control, string error)
|
|
{
|
|
if (control.Text.Trim() == string.Empty)
|
|
{
|
|
MyErrorProvider.SetError(control, error + " 不能为空!");
|
|
return false;
|
|
}
|
|
MyErrorProvider.ClearError(control);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断输入是否是数值
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
/// <param name="error"></param>
|
|
/// <returns></returns>
|
|
public static bool IsNumeric(Control control, string error)
|
|
{
|
|
bool result;
|
|
Regex regex = new Regex("^[0-9]*[0-9][0-9]*$");
|
|
result = regex.IsMatch(control.Text.Trim());
|
|
|
|
if (!result)
|
|
{
|
|
MyErrorProvider.SetError(control, error + " 只能是数字!");
|
|
return result;
|
|
}
|
|
MyErrorProvider.ClearError(control);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断输入是否为Money
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
/// <param name="error"></param>
|
|
/// <returns></returns>
|
|
public static bool IsMoney(Control control, string error)
|
|
{
|
|
bool result;
|
|
result = false;
|
|
try
|
|
{
|
|
double t = Convert.ToDouble(control.Text.Trim());
|
|
if (t < 0)
|
|
{
|
|
result = false;
|
|
}else
|
|
{
|
|
result = true;
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
if (!result)
|
|
{
|
|
MyErrorProvider.SetError(control, error + " 不是正确的金额!");
|
|
return result;
|
|
}
|
|
MyErrorProvider.ClearError(control);
|
|
return result;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|