示例#1
0
        public JsonResult LoadCarrierDriverGrid(string id, string sidx, string sord, int page, int rows)
        {
            //读取全部数据
            string strErrText;
            DDSystem dd = new DDSystem();
            List<CarrierDriver> listDriver = dd.LoadCarrierDrivers(long.Parse(id), LoginAccountId, LoginStaffName, out strErrText);
            if (listDriver == null)
            {
                throw new Exception(strErrText);
            }

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

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

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from d in data
                      select new
                      {
                          id = d.Id,
                          cell = new string[]
                          {
                              d.Id.ToString(),
                              d.Name,
                              d.LicenseNo,
                              d.MobileTel,
                              d.HomeTel,
                              d.CarNo
                          }
                      }).ToArray()
            };
            return Json(ret, JsonRequestBehavior.AllowGet);
        }