码迷,mamicode.com
首页 > 其他好文 > 详细

case break结构与return的有关要点

时间:2015-04-18 01:08:30      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

//确认事件
private void cmd_ok_Click(object sender, EventArgs e)
{
//客户名称是否为空
if (txt_banhao.Text.TrimEnd() == "")
{
MessageBox.Show("电脑版号不能为空", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
txt_banhao.Focus();
return;//这个return必须写才能跳出整个点击事件,因为不会执行break,不写return就会往下执行switch语句
}

switch (lab_state.Text)
{
case "添加": //if()else()里面的return最多只能有一个,否则break会有警告
if (SpareIsExist(txt_banhao.Text.TrimEnd()) == true)
{
MessageBox.Show("该电脑版号已存在", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
//return; //不写return也行,因为会跳过else而执行break强制结束该点击按钮事件
}
else
{
//不存在旧版号
Ulock_Contral();
lab_logindate.Text = DateTime.Now.ToString("yyyy-MM-dd");
lab_update.Text = DateTime.Now.ToString("yyyy-MM-dd");
txt_banhao.Enabled = false;
cmd_ok.Enabled = false;
//return;//不写return也行,程序也会执行break结束 "添加"这个条件
}

break;

case "修改":

if (SpareIsExist(txt_banhao.Text.TrimEnd()) == true)
{
if (_state_touchang == "已投产")
{
MessageBox.Show("注意该版号已投产", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
//解锁各控件
Ulock_Contral();
txt_banhao.Enabled = false;
cmd_ok.Enabled = false;

}

if (lab_formstate.Text == "未制版")
{
//解锁各控件
Ulock_Contral();
txt_banhao.Enabled = false;
cmd_ok.Enabled = false;

}
if (lab_formstate.Text == "已制版")
{
MessageBox.Show("注意该版号已制版", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
//解锁各控件
Ulock_Contral();
txt_banhao.Enabled = false;
cmd_ok.Enabled = false;

}
if (lab_formstate.Text == "已投产")
{
MessageBox.Show("该版号已投产无法修改", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
//解锁各控件
//Ulock_Contral();
//txt_banhao.Enabled = false;
//cmd_ok.Enabled = false;

}

}
else
{

MessageBox.Show("不存在该电脑版号", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

}

break;

case "删除":

if (SpareIsExist(txt_banhao.Text.TrimEnd()) == true)
{
if (_state_touchang == "已投产")
{
MessageBox.Show("已投产不能删除", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

}

if (lab_formstate.Text == "未制版")
{
//解锁各控件
//Ulock_Contral();
txt_banhao.Enabled = false;
cmd_ok.Enabled = false;
cmd_save.Enabled = true;

}
else
{
MessageBox.Show("已制版不能删除", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

}

}
else
{

MessageBox.Show("不存在该电脑版号", "关闭", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

}

break;

}

}

case break结构与return的有关要点

标签:

原文地址:http://www.cnblogs.com/tangfei/p/4436420.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!