C#生成日期流水账号

生成类似 LS14120002       
private String GenNewOrder() { String newOrder; var orders = LYOrder.Items; String lastOrder = ((Order)orders[orders.Count - 1]).OrderNum; //int len = lastOrder.Length; String dateOld = lastOrder.Substring(2, 4); int indexOld = Convert.ToInt32(lastOrder.Substring(6, 4)); String indexNew = (indexOld + 1).ToString(); String dateNow = System.DateTime.Now.ToString("yyMM");//获取年月 if (dateOld.Equals(dateNow))//同一个月的单 { switch (indexNew.Length) { case 1: indexNew = "000" + indexNew; break; case 2: indexNew = "00" + indexNew; break; case 3: indexNew = "0" + indexNew; break; } newOrder = " LS" + dateNow + indexNew; } else { newOrder = " LS" + dateNow + "0001"; } return newOrder; }

 

posted @ 2016-05-08 10:12  文洁丫头  阅读(1005)  评论(0编辑  收藏  举报