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