如何用设计模式去除ifelse多重嵌套?

[复制链接]
查看11 | 回复0 | 2021-2-25 10:19:45 | 显示全部楼层 |阅读模式
winform程序,感觉ifelse嵌套有点多了,如何用状态模式去除ifelse嵌套,请高手指教,谢谢。
privatevoidUploadBtn_Click(objectsender,EventArgse){
if(string.IsNullOrWhiteSpace(ScanTbx.Text))return;
stringtext=ScanTbx.Text.Trim();
using(varconnection=SqlCon.TestDbConnection()){
/***********************************************************************/
if(!next){
if(LuhnAlgorithm.IsValidNumber(text)){
stringimei=$"select*fromBindingwhereIMEI='{text}'";
varimeiQuery=connection.Query[B](imei).ToList();
if((imeiQuery.Count==0)||cbxEdit865Code.Checked){
lblIMEI.Text=text;
next=!next;
label1.Text="请扫描小条码";
}
else{
MessageBox.Show("IMEI已扫描","警告",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
}
else{
MessageBox.Show("IMEI错误","警告",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
}
/***********************************************************************/
else{
if(cbxEditCode.Checked){
stringeditSN=$"updateBindingsetSN='{text}'whereIMEI='{lblIMEI.Text}'";
varsqlUpdateSN=connection.Execute(editSN);
if(sqlUpdateSN>0){
next=!next;
label1.Text="请扫描大I条码";
lblIMEI.Text="";
cbxEdit865Code.Checked=false;
/*********************************/
stringquery="select*fromBindingorderbyBindingDatedesc";
varsqlQuery=connection.Query[B](query).ToList();
dataGridView1.DataSource=sqlQuery;
}
else{
MessageBox.Show("修改失败","提示",MessageBoxButtons.OK,
MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
}
else{
stringsn=$"select*fromBindingwhereSN='{text}'";
varsnQuery=connection.Query[B](sn).ToList();
if(snQuery.Count==0){
stringinsert=$"insertintoBinding(IMEI,SN)values("+
$"'{lblIMEI.Text}','{text}')";
varsqlInsert=connection.Execute(insert);
if(sqlInsert>0){
next=!next;
label1.Text="请扫描大条码";
lblIMEI.Text="";
/*********************************/
stringquery="select*fromBindingorderbyBindingDatedesc";
varsqlQuery=connection.Query[B](query).ToList();
dataGridView1.DataSource=sqlQuery;
}
else{
MessageBox.Show("绑定失败","提示",MessageBoxButtons.OK,
MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
}
else{
MessageBox.Show("小条码已扫描","提示",MessageBoxButtons.OK,
MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
}
}
}
ScanTbx.Clear();
ScanTbx.Focus();
return;
}
分 -->
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行