
1 /// <summary> 2 /// 过滤,取最大值 3 /// </summary> 4 /// <returns>Id</returns> 5 public string FilteringId() 6 { 7 // 英字4桁のIdからMAX値取得 8 var regex = new Regex(@"^[a-z]{4}$"); 9 string[] idList = this.XXRepo.All().Select(m => m.Id).ToArray(); 10 string maxId = idList.Where(m => regex.IsMatch(m) && m != "zzzz").Max(); 11 if (string.Empty.Equals(maxId)) 12 { 13 return "aaaa"; 14 } 15 return this.NumberingForId(maxId); 16 } 17 //------------------------------cut-line--------------------------------------------------------- 18 /// <summary> 19 /// 进位 20 /// </summary> 21 /// <param name="maxId">maxId</param> 22 /// <returns>Id</returns> 23 public string NumberingForId(string maxId) 24 { 25 int length = maxId.Length; 26 char[] ch = new char[length]; 27 for (int i = 0; i < length; i++) 28 { 29 ch[i] = maxId[i]; 30 } 31 // 进位 32 bool carry = true; 33 int p = length; 34 while (carry) 35 { 36 p--; 37 ch[p] = this.LetterIncrement(ch[p]); 38 if (ch[p] == 'a') 39 { 40 carry = true; 41 } 42 else 43 { 44 carry = false; 45 } 46 } 47 return new string(ch); 48 } 49 //-------------------cut-line------------------------------------------------- 50 /// <summary> 51 /// 进位方法 52 /// </summary> 53 /// <param name="ch">ch</param> 54 /// <returns>ch</returns> 55 public char LetterIncrement(char ch) 56 { 57 if (ch == 122) 58 { 59 ch = (char)97; 60 } 61 else 62 { 63 ch++; 64 } 65 return ch; 66 }