首页 > 其他 > 详细

订单号生成规则,谁用谁知道

时间:2015-12-07 10:17:17      阅读:125      评论:0      收藏:0      [点我收藏+]
 1 class Program
 2     {
 3         //订单号数据源,实际项目中,这里是从数据库中读取过来的
 4         string[] strList = { "201512000001", "201512000002", "201512000003", "201512000004", 
 5                              "201512000008", "201512000007", "201512000006", "201512000005", 
 6                              "201512000009", "201512000010", "201512000011", "201512000012",
 7                              "201512000013","201512000014","201512000015" };        
 8         static void Main(string[] args)
 9         {
10             Program p = new Program();
11             Console.WriteLine(p.GetOrderNum());
12             Console.ReadKey();
13         }
14 
15         public string GetOrderNum()
16         {
17             string result = "";            
18             string YearMonth = DateTime.Now.ToString("yyyyMM");
19             var count = Count(YearMonth);//201512  5
20             result = YearMonth + "0000001";
21             var dd = count.ToString().Length;
22             switch (dd)
23             {
24                 case 1:
25                     result = YearMonth + "00000" + (count + 1);
26                     break;
27                 case 2:
28                     result = YearMonth + "0000" + (count + 1);
29                     break;
30                 case 3:
31                     result = YearMonth + "000" + (count + 1);
32                     break;
33                 case 4:
34                     result = YearMonth + "00" + (count + 1);
35                     break;
36                 case 5:
37                     result = YearMonth + "0" + (count + 1);
38                     break;
39                 default:
40                     result = YearMonth + (count + 1);
41                     break;
42             }
43             return result;
44         }
45         
46         public int Count(string yearMonth) {
47             int result = 0;
48             result = strList.Count(item=>item.Contains(yearMonth));
49             return result;
50         }       
51     }

谁有更好的生成规则,不妨一起讨论下

订单号生成规则,谁用谁知道

原文:http://www.cnblogs.com/axinno1/p/5025268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!