zoukankan      html  css  js  c++  java
  • 自动生成编号(B开头后跟6位,数据库查询不重复)

     1 private string GetAccountNo()
     2         {
     3             try
     4             {
     5                 string shortName="B";
     6                 string latestAccountNO = shortName + "000001";
                //查询数据库 7位且包含“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 {
                 //取第一个
    10 string latestNO = templist.FirstOrDefault().AccountNo; 11 12             //截取后六位 13 latestAccountNO = latestNO.Substring(1, 6);
                 //判断是否能转换整形
    14 int iNewNo = 0; 15 int.TryParse(latestAccountNO,out iNewNo);
    16 if (iNewNo > 0) 17 { 18 latestAccountNO = shortName + (iNewNo + 1).ToString("000000"); 19 } 20 else 21 { 22 latestAccountNO = shortName + "000001"; 23 } 24 25 } 26 return latestAccountNO; 27 } 28 catch (Exception ex) 29 {
               //错误信息日志方法
    30 LogHelper.WriteLog(ex.Message, ex); 31 return ""; 32 } 33 34 }
  • 相关阅读:
    HDU 1060 Leftmost Digit
    HDU 1008 Elevator
    HDU 1042 N!
    HDU 1040 As Easy As A+B
    HDU 1007 Quoit Design
    欧拉函数
    HDU 4983 Goffi and GCD
    HDU 2588 GCD
    HDU 3501 Calculation 2
    HDU 4981 Goffi and Median
  • 原文地址:https://www.cnblogs.com/Neil-Peng/p/8252220.html
Copyright © 2011-2022 走看看