using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; using Chloe; using DB.Entity; using Tool; namespace DB.Service { public class FromPlanService { public void Insert(FromPlan plan) { using (var dbContext = DbFactory.GetContext) { dbContext.Insert(plan); } } public FromPlan Query(long id) { using (var dbContext = DbFactory.GetContext) { return dbContext.QueryByKey(id); } } public void Update(FromPlan plan) { using (var dbContext = DbFactory.GetContext) { dbContext.Update(plan); } } public void Del(long id) { using (var dbContext = DbFactory.GetContext) { dbContext.DeleteByKey(id); } } public string GetMaxCode() { using (var dbContext = DbFactory.GetContext) { string dt = DateTime.Now.ToString("yyyyMMdd"); string code = dbContext.Query() .Where(x => x.Code.StartsWith(dt)).OrderByDesc(x => x.ID) .Select(x => x.Code).FirstOrDefault(); if (string.IsNullOrEmpty(code)) { return dt + "001"; } int s = code.Substring(8).ToInt() + 1; return dt + s.ToString().PadLeft(3, '0'); } } public PagedList GetPagedList(int pageIndex, int pageSize) { using (var dbContext = DbFactory.GetContext) { var dao = dbContext.Query() .OrderByDesc(x => x.ID) .Paging(pageIndex, pageSize); PagedList paged = new PagedList(dao.DataList, dao.Totals.ToInt(), pageIndex, pageSize); return paged; } } } }