Home > Net >  How to use design patterns to remove ifelse multiple nested?
How to use design patterns to remove ifelse multiple nested?

Time:02-23

Winform procedure, have a little more, feel ifelse nested how ifelse nested by the state pattern, please advise, thank you,
 private void UploadBtn_Click (object sender, EventArgs e) {
If (string. IsNullOrWhiteSpace (ScanTbx. Text)) return;
A string of text=ScanTbx. Text. The Trim ();
Using (var connection=SqlCon TestDbConnection ()) {
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
if (! Next) {
If (LuhnAlgorithm IsValidNumber (text)) {
String imei=$" select * from Binding where imei='{text} ";
Var imeiQuery=connection. Query (imei). ToList ();
If ((imeiQuery. Count==0) | | cbxEdit865Code. Checked) {
LblIMEI. Text=Text;
Next=! Next;
Label1. Text="please scan small barcode";
}
The else {
MessageBox. Show (" IMEI scanned ", "warning", MessageBoxButtons. OK, MessageBoxIcon. Error, MessageBoxDefaultButton. For the);
}
}
The else {
IMEI MessageBox. Show (" Error ", "warning", MessageBoxButtons. OK, MessageBoxIcon. Error, MessageBoxDefaultButton. For the);
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
The else {
If (cbxEditCode. Checked) {
String editSN=$" update Binding set SN='{text} where IMEI=' {lblIMEI. Text} ";
Var sqlUpdateSN=connection. The Execute (editSN);
If (sqlUpdateSN & gt; 0 {
Next=! Next;
Label1. Text="please scan barcode I";
LblIMEI. Text="";
CbxEdit865Code. Checked=false;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
String query="select * from the Binding order by BindingDate desc";
Var this=connection. Query (query). ToList ();
DataGridView1. The DataSource=this;
}
The else {
MessageBox. Show (" modify "failure," tip ", MessageBoxButtons. OK,
MessageBoxIcon Error, MessageBoxDefaultButton. For);
}
}
The else {
String of sn=$" select * from Binding where sn='{text} ";
Var snQuery=connection. Query (sn). ToList ();
If (snQuery. Count==0) {
String insert=$" insert into Binding (IMEI, SN) values (" +
$" '{lblIMEI. Text}', '{Text}) ";
Var sqlInsert=connection. The Execute (insert);
If (sqlInsert & gt; 0 {
Next=! Next;
Label1. Text="please scan barcode";
LblIMEI. Text="";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
String query="select * from the Binding order by BindingDate desc";
Var this=connection. Query (query). ToList ();
DataGridView1. The DataSource=this;
}
The else {
MessageBox. Show (" binding "failure," tip ", MessageBoxButtons. OK,
MessageBoxIcon Error, MessageBoxDefaultButton. For);
}
}
The else {
MessageBox. Show (" little barcode scanned ", "prompt", MessageBoxButtons. OK,
MessageBoxIcon Error, MessageBoxDefaultButton. For);
}
}
}
}
ScanTbx. The Clear ();
ScanTbx. Focus ();
return;
}
  •  Tags:  
  • C#
  • Related