Ejemplo n.º 1
0
        public JsonResult LoadCanPlanGoodsDispatchHistoryGrid(string sidx, string sord, int page, int rows, string planId, string goodsId)
        {
            string strErrText;

            //读取数据
            DispatchSystem dispatch = new DispatchSystem();
            List<DispatchBillGoods> listGoods = dispatch.LoadAllDispatchBillGoodsByConditions(planId, goodsId, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, LoginAccountId, LoginStaffName, out strErrText);
            if (listGoods == null)
            {
                throw new Exception(strErrText);
            }

            //提取当前页面数据
            int nTotalRows = listGoods.Count;
            int nPageIndex = page;
            int nPageSize = rows;
            int nTotalPages = nTotalRows / nPageSize;
            if (nTotalRows % nPageSize > 0)
                nTotalPages++;

            string sortExpression = (sidx ?? "CreateTime") + " " + (sord ?? "ASC");
            var data = listGoods.OrderBy(sortExpression).Skip((nPageIndex - 1) * nPageSize).Take(nPageSize).ToList();

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from g in data
                      select new
                      {
                          id = g.Id,
                          cell = new string[] {
                              g.Id.ToString(),
                              g.CreateTime.ToString("yyyy-MM-dd"),
                              g.CarNo,
                              g.TrailerNo,
                              g.Piles.ToString("#0.######"),
                              g.TenThousands.ToString("#0.######")
                          }
                      }).ToArray(),
                userdata = new
                {
                    CreateTime = InnoSoft.LS.Resources.Labels.Total,
                    Piles = data.Sum(s => s.Piles),
                    TenThousands = data.Sum(s => s.TenThousands)
                }
            };
            return Json(ret, JsonRequestBehavior.AllowGet);
        }