The first GUID is automatically generated by the algorithm and theoretically produces globally unique values but is not convenient for users to remember order numbers
Console.WriteLine(System.Guid.NewGuid()); Console.ReadKey(); // Result: 5322D297-51b4-4198-8625-CC465C948852
Random rand = new Random(); Random rand = new Random(); int shu2 = rand.Next(1000, 9999); string randId = DateTime.Now.ToString(“yyyyMMddHHmmss”) + shu2; Console.WriteLine(randId); Console.ReadLine();
The third to the order number set up since the increase Don’t repeat But only one mark column Id cannot be only the fourth kind of a little bit more simple, can be caused by user Id (digital), time, generate a random number combinations, because the user Id is unique, the generated order number would not be repeated Fifth with 64 – bit encryption MD5 for user name and time, Then use the encrypted signature as the order number. 6 IP address, time, machine code, user name, random number timestamp (10)+ province ID (6)+ city ID (6)+ district ID (6)+ quad-digit random number (4)
In order to solve the concurrency, add lock directly to the area block that generates the order number
1. Create a project
2. Create the BillNumberBuilder class
3. Create an OrderIdHelper class
Generated by 4.
Generate results
Wen20170309180733
Wen20170309180735