c#生成连续单号

bill.BillCode = GetBillCode("JH");//生成单号
if (bill.BillCode == "no")
{
bill.BillCode = GetBillCode("JH");//再次生成单号
}

/// <summary>
/// 生成单号
/// </summary>
/// <returns></returns>
public string GetBillCode(string head)
{
string res = "";
try
{
string temp = DateTime.Now.ToString("yyyyMM");//六位年月
int totalCount;//没用
string flowid;
var lastbill = CurrentDal.LoadPageEntities(a => a.BillCode.Substring(2, 6) == temp, a => a.BillCode, 1, 1, false, out totalCount).FirstOrDefault();
if (lastbill == null)
{
flowid = "00001";
}
else
{
flowid = string.Format("{0:00000}", (Convert.ToInt32(lastbill.BillCode.Substring(8, 5)) + 1));
}
res = head + temp + flowid;
}
catch
{
res = "no";
}
return res;
}

上一篇:wp8开发笔记之应用程序真机发布调试


下一篇:使用QTP12.2录制windows applications,没有脚本产生