Пример #1
0
        public JsonResult LoadDispatchedPaperPlanGoodsGrid(string sidx, string sord, int page, int rows, string dispatchBillId, string planId)
        {
            //读取数据
            string strErrText;
            DispatchSystem dispatch = new DispatchSystem();
            List<DispatchBillGoods> listGoods = dispatch.LoadDispatchedDeliverPlanAllGoods(long.Parse(dispatchBillId), long.Parse(planId), 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 ?? "GoodsNo") + " " + (sord ?? "ASC");
            var data = listGoods.OrderBy(sortExpression).Skip((nPageIndex - 1) * nPageSize).Take(nPageSize).ToList();

            //记录编号
            for (int i = 0; i < data.Count; i++)
            {
                data[i].Id = i + 1;
            }

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from g in data
                      select new
                      {
                          id = g.Id,
                          cell = new string[] {
                              g.GoodsId.ToString(),
                              g.GoodsNo,
                              g.GoodsName,
                              g.Brand,
                              g.SpecModel,
                              g.GWeight,
                              g.Grade,
                              g.BatchNo,
                              g.Packing,
                              g.Warehouse,
                              g.Location,
                              g.Packages.ToString(),
                              g.PieceWeight.ToString("#0.######"),
                              g.Tunnages.ToString("#0.######"),
                              g.ProductionDate,
                              g.EnterWarehouseBillId.ToString(),
                              g.EnterWarehouseBillNo,
                              g.ActualPackages.ToString(),
                              g.ActualTunnages.ToString("#0.######")
                          }
                      }).ToArray(),
                userdata = new
                {
                    GoodsNo = InnoSoft.LS.Resources.Labels.Total,
                    Packages = data.Sum(s => s.Packages),
                    Tunnages = data.Sum(s => s.Tunnages),
                    ActualPackages = data.Sum(s => s.ActualPackages),
                    ActualTunnages = data.Sum(s => s.ActualTunnages)
                }
            };
            return Json(ret, JsonRequestBehavior.AllowGet);
        }