//验证是否为空 private bool ValidateInput() { bool isOk = true; if (TxtID.Text == "") { TxtID.BackColor = Color.Red; TxtID.Focus(); isOk = false; } if (Txtname.Text == "") { Txtname.BackColor = Color.Red; Txtname.Focus(); isOk = false; } if (Txtpwd.Text == "") { Txtpwd.BackColor = Color.Red; Txtpwd.Focus(); isOk = false; } if (txtAddress.Text == "") { txtAddress.BackColor = Color.Red; txtAddress.Focus(); isOk = false; } if (TxtpaperID.Text == "") { TxtpaperID.BackColor = Color.Red; TxtpaperID.Focus(); isOk = false; } if (TxtcontactTel.Text == "") { TxtcontactTel.BackColor = Color.Red; TxtcontactTel.Focus(); isOk = false; } return(isOk); //返回结果 }
//添加会员 private void btnCustAdd_Click(object sender, EventArgs e) { //验证是否为空 if (ValidateInput()) { //长度必须大于6 if (Txtpwd.Text.Length < 6) { MessageBox.Show("密码长度必须大于六位!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Txtpwd.Focus(); return; } else if (Txtpwd.Text != txtPassAgain.Text) { MessageBox.Show("两次密码不一至!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Txtpwd.Focus(); return; } //写入方法 InsertCust(); } }