C#实现在购物车系统中生成不重复订单号的方法
程序员文章站
2022-04-11 08:05:51
本文实例讲述了c#实现在购物车系统中生成不重复订单号的方法。分享给大家供大家参考。具体分析如下:
订单号在购物过程中起到了很好的识别作用,更方便的有利于工作人员识别商品,...
本文实例讲述了c#实现在购物车系统中生成不重复订单号的方法。分享给大家供大家参考。具体分析如下:
订单号在购物过程中起到了很好的识别作用,更方便的有利于工作人员识别商品,代码如下:
#region 生成单据号 /// <summary> /// 生成单据号 /// </summary> /// <param name="pfromtype"></param> /// <returns></returns> public static string getformcode(formtype pfromtype) { string formcode = ""; switch(pfromtype) { case formtype.caigou: { formcode = "cg"; break; } case formtype.chaixie: { formcode = "cx"; break; } case formtype.chuku: { formcode = "ck"; break; } case formtype.lingliao: { formcode = "ll"; break; } case formtype.peichang: { formcode = "pc"; break; } case formtype.ruku: { formcode = "rk"; break; } case formtype.shengchan: { formcode = "sc"; break; } case formtype.sunyi: { formcode = "sy"; break; } case formtype.tuihuo: { formcode = "th"; break; } case formtype.xiaoshou: { formcode = "xs"; break; } case formtype.peisong: { formcode = "ps"; break; } case formtype.zengpin: { formcode = "zp"; break; } case formtype.fukuan: { formcode = "fk"; break; } case formtype.shoukuan: { formcode = "sk"; break; } } formcode += datetime.now.year.tostring(); formcode += datetime.now.month.tostring().length == 1?"0" + datetime.now.month.tostring() : datetime.now.month.tostring(); formcode += datetime.now.day.tostring().length == 1?"0" + datetime.now.day.tostring() : datetime.now.day.tostring(); formcode += datetime.now.hour.tostring().length == 1?"0" + datetime.now.hour.tostring() : datetime.now.hour.tostring(); formcode += datetime.now.minute.tostring().length == 1?"0" + datetime.now.minute.tostring() : datetime.now.minute.tostring(); formcode += datetime.now.second.tostring().length == 1?"0" + datetime.now.second.tostring() : datetime.now.second.tostring(); if(datetime.now.millisecond.tostring().length == 1) { formcode += "00" + datetime.now.millisecond.tostring(); } else if (datetime.now.millisecond.tostring().length == 2) { formcode += "0" + datetime.now.millisecond.tostring(); } else { formcode += datetime.now.millisecond.tostring(); } return formcode; } #endregion
希望本文所述对大家的c#程序设计有所帮助。