예제 #1
0
        public ActionResult NewContract(ContractViewModel model)
        {
            if (ModelState.IsValid)
            {
                //创建数据
                Contract data = new Contract();
                data.DispatchBillId = model.DispatchBillId;
                data.CarNo = model.CarNo;
                data.TrailerNo = model.TrailerNo;
                data.CarType = model.CarType;
                data.DriverName = model.DriverName;
                data.DriverLicenseNo = model.DriverLicenseNo;
                data.DriverMobileTel = model.DriverMobileTel;
                data.DriverHomeTel = model.DriverHomeTel;
                data.CarrierId = model.CarrierId;
                data.CarrierName = model.CarrierName;
                data.GoodsName = model.GoodsName;
                data.Packing = model.Packing;
                data.StartPlace = model.StartPlace;
                data.DestPlace = model.DestPlace;
                data.ShipmentTime = DateTime.Parse(model.ShipmentTime);
                data.ArrivalTime = DateTime.Parse(model.ArrivalTime);
                data.TotalPackages = model.TotalPackages;
                data.TotalTunnages = model.TotalTunnages;
                data.TotalPiles = model.TotalPiles;
                data.TotalTenThousands = model.TotalTenThousands;
                data.TotalTransportCharges = model.TotalTransportCharges;
                data.PrepayTransportCharges = model.PrepayTransportCharges;
                data.ResidualTransportCharges = model.ResidualTransportCharges;
                data.OriginalContractNo = model.OriginalContractNo;
                data.IsPrestowage = true;

                List<ContractDeliverPlan> listPlan = new List<ContractDeliverPlan>();
                if (model.DeliverPlans != null)
                {
                    foreach (ContractDeliverPlanViewModel m in model.DeliverPlans)
                    {
                        ContractDeliverPlan p = new ContractDeliverPlan();
                        p.PlanId = m.PlanId;
                        p.Packages = m.Packages;
                        p.Tunnages = m.Tunnages;
                        p.Piles = m.Piles;
                        p.TenThousands = m.TenThousands;
                        p.TransportChargeExpression = m.TransportChargeExpression;
                        p.TransportPriceExpression = m.TransportPriceExpression;
                        p.KM = m.KM;
                        p.TransportPrice = m.TransportPrice;
                        p.TransportCharges = m.TransportCharges;
                        p.Remark = m.Remark;
                        listPlan.Add(p);
                    }
                }

                //保存数据
                string strErrText;
                ContractSystem contract = new ContractSystem();
                if (contract.InsertContract(data, listPlan, LoginAccountId, LoginStaffName, out strErrText) > 0)
                {
                    return Json(string.Empty);
                }
                else
                {
                    return Json(strErrText);
                }
            }
            return View(model);
        }