This article describes the method of C# to generate non-repeated order numbers in the shopping cart system. Share it for your reference. The specific analysis is as follows:
The order number plays a good role in identifying products during shopping, and is more convenient for staff to identify products. The code is as follows:
#region Generate document number/// <summary> /// Generate document number/// </summary> /// <param name="pFromType"></param> /// <returns></returns> public static string GetFormCode(FormType pFromType) { string formcode = ""; switch(pFromType) { case : { formcode = "CG"; break; } case : { formcode = "CX"; break; } case : { formcode = "CK"; break; } case : { formcode = "LL"; break; } case : { formcode = "PC"; break; } case : { formcode = "RK"; break; } case : { formcode = "SC"; break; } case : { formcode = "SY"; break; } case : { formcode = "TH"; break; } case : { formcode = "XS"; break; } case : { formcode = "PS"; break; } case : { formcode = "ZP"; break; } case : { formcode = "FK"; break; } case : { formcode = "SK"; break; } } formcode += (); formcode += ().Length == 1?"0" + () : (); formcode += ().Length == 1?"0" + () : (); formcode += ().Length == 1?"0" + () : (); formcode += ().Length == 1?"0" + () : (); formcode += ().Length == 1?"0" + () : (); if(().Length == 1) { formcode += "00" + (); } else if (().Length == 2) { formcode += "0" + (); } else { formcode += (); } return formcode; } #endregion
I hope this article will be helpful to everyone's C# programming.