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;
}
分 --> |