//确认事件
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;
}
}