using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MyWeb { /// /// autoNum 的摘要描述 /// public class autoNum { private Model.ezEntities _db = new Model.ezEntities(); public autoNum() { // // TODO: 在這裡新增建構函式邏輯 // } public string createOrderNumber() { //Application.Lock(); string order_no = "AA" + DateTime.Now.ToString("yyMMdd"); var qry = _db.companies.AsQueryable(); //var prod = qry.Where(q => q.last_order_no.Contains(order_no)).FirstOrDefault(); var prod = qry.Where(q => q.num == 1).FirstOrDefault(); if (prod != null) { if (!string.IsNullOrEmpty(prod.last_order_no) && prod.last_order_no.Contains(order_no)) { int tmp = Convert.ToInt32(prod.last_order_no.Replace(order_no, "")) + 1; order_no = order_no + tmp.ToString("0000"); } else { order_no = order_no + "0001"; } prod.last_order_no = order_no; _db.SaveChanges(); } else order_no = ""; //Application.UnLock(); return order_no; } } }