if (comboBox2.Text.Trim().Length <= 0)
{
MessageBox.Show("收据号没有写", "错误", MessageBoxButtons.OK);
return ; }
if (comboBox2 .Items .Contains (comboBox2 .Text ))
{
MessageBox .Show ("收据编号重复了","错误",MessageBoxButtons .OK );
return;
}
if (comboBox1.Text.Trim().Length <= 0)
{
MessageBox.Show("姓名没有写", "错误", MessageBoxButtons.OK);
return; }
if (comboBox1.Items.Contains(comboBox1.Text.Trim()))
{
MessageBox.Show("没有这个人", "错误", MessageBoxButtons.OK);
return;
}
if (maskedTextBox2.Text.Trim().Length <= 0)
{
MessageBox.Show("金额没有写", "错误", MessageBoxButtons.OK);
return;
}
if (maskedTextBox3.Text.Trim().Length <= -0)
{
MessageBox.Show("刷卡金额没有写", "错误", MessageBoxButtons.OK);
return ;
}
else
{
//得到值内容
this.学员报名收入TableAdapter1.InsertQuery报名收入(收据编号, Convert.ToString(开票日期), 姓名, 项目, 金额, 刷卡金额, 销售);
}
请问检查输入字段怎么能写一个过程或是函数更简单的调用,因为有很多窗体都要做输入检查
{
MessageBox.Show("收据号没有写", "错误", MessageBoxButtons.OK);
return ; }
if (comboBox2 .Items .Contains (comboBox2 .Text ))
{
MessageBox .Show ("收据编号重复了","错误",MessageBoxButtons .OK );
return;
}
if (comboBox1.Text.Trim().Length <= 0)
{
MessageBox.Show("姓名没有写", "错误", MessageBoxButtons.OK);
return; }
if (comboBox1.Items.Contains(comboBox1.Text.Trim()))
{
MessageBox.Show("没有这个人", "错误", MessageBoxButtons.OK);
return;
}
if (maskedTextBox2.Text.Trim().Length <= 0)
{
MessageBox.Show("金额没有写", "错误", MessageBoxButtons.OK);
return;
}
if (maskedTextBox3.Text.Trim().Length <= -0)
{
MessageBox.Show("刷卡金额没有写", "错误", MessageBoxButtons.OK);
return ;
}
else
{
//得到值内容
this.学员报名收入TableAdapter1.InsertQuery报名收入(收据编号, Convert.ToString(开票日期), 姓名, 项目, 金额, 刷卡金额, 销售);
}
请问检查输入字段怎么能写一个过程或是函数更简单的调用,因为有很多窗体都要做输入检查
/// <summary>
/// 检测指定文本控件是否为空
/// </summary>
/// <param name="txtName">控件名称</param>
/// <param name="str">文本提示</param>
/// <returns></returns>
public static bool jctxt(Control txtName,string str)
{
bool Flag=false;
if (txtName.Text.Trim().Length == 0)
{
MessageBox.Show(str,"提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
txtName.Focus();
Flag=true;
}
return Flag;
}
#endregion
public bool ValidateShouJu(string str)
{
if (str.IsNullOrEmpty()) return false; string val = str.Trim();
...
return true;
}用的时候 bool b = ValidateShouJu(Combobox1.text);
public delegate void myDelegate(string str1,comboBox b2);public void 收据(string str1,comboBox b2)
{
if (str1.Trim().Length <= 0)
{
MessageBox.Show("收据号没有写", "错误", MessageBoxButtons.OK);
return ; }
if (b2 .Items .Contains (comboBox2 .Text ))
{
MessageBox .Show ("收据编号重复了","错误",MessageBoxButtons .OK );
return;
}
}
public void 姓名(string str1,comboBox b2)
{
判断....同上
}
实现:
myDelegate gd1 = new myDelegate(收据);
myDelegate gd2 = new myDelegate(姓名);
(gd1 + gd2)(传值);
需要就往上加不需要就往下减.
因为你的报错信息不同.所以要把错信息都定义出来.
public delegate void myDelegate(string str1,comboBox b2);public void 收据(string str1,comboBox b2)
{
if (str1.Trim().Length <= 0)
{
MessageBox.Show("收据号没有写", "错误", M……