Learn to write a generic document code generator with me

Let's use a piece of code to talk about how I generate the document number. I wrote a class, as shown in the following code:

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;
        }
    }
}

When using it, call it directly as follows:

BillNo.GetBillNo ();

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325086923&siteId=291194637