Automatically generate the number (starting with B followed by 6 digits, and database queries are not repeated), and automatically generate 6 digits
1 private string GetAccountNo () 2 {3 try 4 {5 string shortName = "B"; 6 string latestAccountNO = shortName + "000001 ";
// Query the database with 7 characters including "B" 7 var templist = twRep. getAll (). where (x => x. accountNo. length = 7 & x. accountNo. contains (shortName )). orderByDescending (x => x. accountNo ). toList (); 8 if (templist. count> 0) 9 {
// Obtain the first 10 string latestNO = templist. FirstOrDefault (). AccountNo; 11 12 // capture the last six digits 13 latestAccountNO = latestNO. Substring (1, 6 );
// Determine whether the integer can be converted to 14 int iNewNo = 0; 15 int. TryParse (latestAccountNO, out iNewNo );
16 if (iNewNo> 0) 17 {18 latestAccountNO = shortName + (iNewNo + 1 ). toString ("000000"); 19} 20 else21 {22 latestAccountNO = shortName + "000001"; 23} 24 25} 26 return latestAccountNO; 27} 28 catch (Exception ex) 29 {
// Error Message log Method 30 LogHelper. WriteLog (ex. Message, ex); 31 return ""; 32} 33 34}