下面我们来用一段代码来讲一下,我是怎么生成单据编号的,我写了一个类,如下所示代码:
public class BillNo{ public static object _lock = new object(); public static int count = 1; public static string GetBillNo() { lock(_lock) { if(count >= 10000) { count = 1; } var number = "P" + DateTime.Now.ToString("yyMMddHHmmss") + count.ToString("0000"); count++; return number; } }}
使用的时候直接如下调用:
BillNo.GetBillNo();