示例#1
0
        public JsonResult LoadSaveReversesGrid(string sidx, string sord, int page, int rows, string saveReverses)
        {
            //读取数据
            List<Contract> listReverseContract = new List<Contract>();
            if (saveReverses != string.Empty)
            {
                //生成冲帐明细数据
                List<ContractReverseDetail> listReverseDetail = new List<ContractReverseDetail>();
                string[] reverses = saveReverses.Split(',');
                foreach (string reverse in reverses)
                {
                    if (reverse != string.Empty)
                    {
                        string[] s = reverse.Split('|');
                        ContractReverseDetail detail = new ContractReverseDetail();
                        detail.ContractId = long.Parse(s[0]);
                        detail.ReverseAmount = decimal.Parse(s[1]);
                        detail.WithholdAmount = decimal.Parse(s[2]);
                        detail.FactpaymentAmount = decimal.Parse(s[3]);
                        listReverseDetail.Add(detail);
                    }
                }

                //读取冲帐合同数据
                string strErrText;
                var strContractIds = string.Join(",", (from d in listReverseDetail select d.ContractId).ToArray<long>());
                ContractSystem contract = new ContractSystem();
                List<Contract> listContract = contract.LoadReverseContractsByContractIds(strContractIds, LoginAccountId, LoginStaffName, out strErrText);
                if (listContract == null)
                {
                    throw new Exception(strErrText);
                }

                //过滤数据
                foreach (ContractReverseDetail detail in listReverseDetail)
                {
                    Contract o = listContract.Find(delegate(Contract c) { return c.Id == detail.ContractId; });
                    if (o == null)
                    {
                        throw new Exception(InnoSoft.LS.Resources.Strings.FindReverseContractDataFaild);
                    }
                    o.ReverseAmount = detail.ReverseAmount;
                    o.WithholdAmount = detail.WithholdAmount;
                    o.FactpaymentAmount = detail.FactpaymentAmount;
                    listReverseContract.Add(o);
                }
            }

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

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

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from c in data
                      select new
                      {
                          id = c.Id,
                          cell = new string[] {
                              c.Id.ToString(),
                              c.ContractNo,
                              c.OriginalContractNo,
                              c.CarNo,
                              c.TrailerNo,
                              c.DriverName,
                              c.DriverMobileTel,
                              c.ReverseAmount.ToString(),
                              c.WithholdAmount.ToString(),
                              c.FactpaymentAmount.ToString()
                          }
                      }).ToArray(),
                userdata = new
                {
                    ContractNo = 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);
        }