Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public ActionResult ReverseContracts(ContractReverseViewModel model)
        {
            if (ModelState.IsValid)
            {
                //创建数据
                ContractReverse data = new ContractReverse();
                data.Id = model.Id;
                data.ReverseAmount = model.ReverseAmount;
                data.WithholdAmount = model.WithholdAmount;
                data.FactpaymentAmount = model.FactpaymentAmount;
                data.CreatorId = model.CreatorId;
                data.CreatorName = model.CreatorName;

                List<ContractReverseDetail> listDetail = new List<ContractReverseDetail>();
                if (model.Details != null)
                {
                    foreach (ContractReverseDetailViewModel m in model.Details)
                    {
                        ContractReverseDetail d = new ContractReverseDetail();
                        d.Id = m.Id;
                        d.ReverseId = 0;
                        d.ContractId = m.ContractId;
                        d.ReverseAmount = m.ReverseAmount;
                        d.WithholdAmount = m.WithholdAmount;
                        d.FactpaymentAmount = m.FactpaymentAmount;
                        listDetail.Add(d);
                    }
                }

                //保存数据
                string strErrText;
                ContractSystem contract = new ContractSystem();
                if (contract.InsertContractReverse(data, listDetail, LoginAccountId, LoginStaffName, out strErrText) > 0)
                {
                    return Json(string.Empty);
                }
                else
                {
                    return Json(strErrText);
                }
            }
            return View(model);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 新增冲帐记录明细数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool InsertContractReverseDetail(ContractReverseDetail data, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            //创建存储过程参数
            SqlParameter[] Params =
                {
                    MakeParam(REVERSEID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.ReverseId),
                    MakeParam(CONTRACTID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.ContractId),
                    MakeParam(REVERSEAMOUNT_PARAM, SqlDbType.Decimal, 13, ParameterDirection.Input, (object)data.ReverseAmount),
                    MakeParam(WITHHOLDAMOUNT_PARAM, SqlDbType.Decimal, 13, ParameterDirection.Input, (object)data.WithholdAmount),
                    MakeParam(FACTPAYMENTAMOUNT_PARAM, SqlDbType.Decimal, 13, ParameterDirection.Input, (object)data.FactpaymentAmount),
                    MakeParam(OPSTAFFID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)nOpStaffId),
                    MakeParam(OPSTAFFNAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)strOpStaffName),
                };

            if (Execute("InsertContractReverseDetail", Params, out strErrText) >= 0)
                return true;
            else
                return false;
        }