public ActionResult Account(DateTime?start, DateTime?end, int pageIndex = 1) { AccountModel model = new AccountModel(); AccountPageResult changeModel = new AccountPageResult(); //查询数据 changeModel = accountService.GetPageList(0, start, end, pageIndex, PageSize); model.accountList = changeModel.AccountList; model.AccountTotol.sr = accountService.GetIncomeTotal(); model.AccountTotol.zc = accountService.GetPayTotal(); model.AccountTotol.yl = model.AccountTotol.sr - model.AccountTotol.zc; model.AccountTotol.bl = (model.AccountTotol.zc / model.AccountTotol.sr) * 100; //分页 Pagination pager = new Pagination(); pager.PageIndex = pageIndex; pager.PageSize = PageSize; pager.TotalCount = changeModel.TotalCount; if (changeModel.TotalCount <= PageSize) { model.Page = ""; } else { model.Page = pager.GetPagerHtml(); } return(Json(new AjaxResult { Status = "1", Data = model })); }
public ActionResult Account() { AccountModel model = new AccountModel(); AccountPageResult changeModel = new AccountPageResult(); AccountDTO totaldto = new AccountDTO(); totaldto.sr = accountService.GetIncomeTotal(); totaldto.zc = accountService.GetPayTotal(); totaldto.yl = totaldto.sr - totaldto.zc; if (totaldto.sr == 0) { totaldto.bl = 0; } else { totaldto.bl = (totaldto.zc / totaldto.sr) * 100; } //查询数据 changeModel = accountService.GetPageList(0, null, null, 1, PageSize); model.accountList = changeModel.AccountList; model.AccountTotol = totaldto; //分页 Pagination pager = new Pagination(); pager.PageIndex = 1; pager.PageSize = PageSize; pager.TotalCount = changeModel.TotalCount; if (changeModel.TotalCount <= PageSize) { model.Page = ""; } else { model.Page = pager.GetPagerHtml(); } return(View(model)); }
/// <summary> /// 分页查询 /// </summary> /// <param name="UserID"></param> /// <param name="UserCode"></param> /// <param name="ToUserCode"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public AccountPageResult GetPageList(long UserID, DateTime?start, DateTime?end, int pageIndex, int pageSize) { using (MyDbContext dbcontext = new MyDbContext()) { CommonService <UserRecordEntity> record = new CommonService <UserRecordEntity>(dbcontext); CommonService <BonusEntity> bonus = new CommonService <BonusEntity>(dbcontext); AccountPageResult pageResult = new AccountPageResult(); var recordQuery = record.GetAll(); var bonusQuery = bonus.GetAll(); var bonusGroup = bonusQuery.GroupBy(bg => bg.AddTime).Select(y => new { BDate = y.Key, zc = y.Sum(m => m.Amount) }); var qeury = recordQuery.GroupBy(rg => DbFunctions.TruncateTime(rg.RecordTime)).Select(s => new { RDate = s.Key, sr = s.Sum(w => w.ReMoney) }) .Join(bonusGroup, r => r.RDate, b => DbFunctions.TruncateTime(b.BDate), (r, b) => new { r.RDate, r.sr, b.zc }); pageResult.TotalCount = qeury.Count(); pageResult.AccountList = qeury.OrderByDescending(p => p.RDate).Skip((pageIndex - 1) * pageSize) .Take(pageSize).ToList() .Select(p => new AccountDTO { recordTime = (DateTime)p.RDate, zc = p.zc, sr = p.sr, yl = p.sr - p.zc }) .ToArray(); return(pageResult); } }