コード例 #1
0
ファイル: ContractController.cs プロジェクト: zjchenxk/SYLS
        public JsonResult LoadSearchContractReversesGrid(string sidx, string sord, int page, int rows, string startTime, string endTime, string contractNo, string originalContractNo, string reverserId)
        {
            //读取数据
            string strErrText;
            ContractSystem contract = new ContractSystem();
            List<ContractReverse> listContractReverse = contract.LoadContractReversesByConditions(startTime, endTime, contractNo, originalContractNo, reverserId, LoginAccountId, LoginStaffName, out strErrText);
            if (listContractReverse == null)
            {
                throw new Exception(strErrText);
            }

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

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

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