我们在做项目的时候经常会用到多层的if...else的判断(封装之前的代码):
private void btnCancelCard_Click(object sender, EventArgs e)
{
//1、判断文本框是否为空
if (txtCancelCardID.Text == "")
{
MessageBox.Show("请将信息填写完整");
}
else
{
List<UserInfo> userlist = userfacade.SelectUser(Convert.ToInt32(txtCancelCardID.Text));
//2、判断是否有该卡号
if (userlist.Count > 0)
{
//3、判断是否正在上机
if (onlinefacade.SelectOnline(Convert.ToInt32(txtCancelCardID.Text)).Count > 0)
{
MessageBox.Show("该卡正在上机,请下机后再退卡");
txtCancelCardID.Text = "";
txtCancelCardID.Focus();
}
else
{
cancel.CardID = Convert.ToInt32(txtCancelCardID.Text);