Automatically generate the number (starting with B followed by 6 digits, and database queries are not repeated), and automatically generate 6 digits

Source: Internet
Author: User

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}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.