public static bool CheckControlInput(Control ctrl, string strCaption, int iLength, bool blnNumber)
{
try
{
if (ctrl.GetType().ToString() == "System.Windows.Forms.TextBox")
{
if (ctrl.Text.Trim() == "")
{
MsgBoxExclamation(strCaption + "不能为空,请输入" + strCaption);
ctrl.Focus();
((TextBox)ctrl).SelectAll();
return false;
}
else if (iLength > 0 && ctrl.Text.Length != iLength)
{
MsgBoxExclamation("请输入" + iLength.ToString() + "位" + strCaption);
ctrl.Focus();
((TextBox)ctrl).SelectAll();
return false;
}
if (blnNumber && !IsNumeric(ctrl.Text))
{
MsgBoxExclamation(strCaption + "必须为数字,请重新输入");
ctrl.Focus();
((TextBox)ctrl).SelectAll();
return false;
}
}
else if (ctrl.GetType().ToString() == "System.Windows.Forms.ComboBox")
{
if (ctrl.Text.Trim() == "")
{
MsgBoxExclamation(strCaption + "不能为空,请选择" + strCaption);
ctrl.Focus();
return false;
}
}
else
{
if (ctrl.Text.Trim() == "")
{
MsgBoxExclamation(strCaption + "不能为空,请输入" + strCaption);
ctrl.Focus();
return false;
}
}
return true;
}
catch (System.Exception e)
{
MsgBoxException(e.Message, "GlobalFunction.CheckControlInput");
return false;
}
}