Example #1
0
        public ActionResult NewCarrier(CarrierViewModel model)
        {
            if (ModelState.IsValid)
            {
                //创建数据
                Carrier data = new Carrier();
                data.Name = model.Name;
                data.BusinessType = model.BusinessType;
                data.PaymentType = model.PaymentType;

                List<CarrierCar> listCar = new List<CarrierCar>();
                if (model.Cars != null)
                {
                    foreach (CarrierCarViewModel m in model.Cars)
                    {
                        CarrierCar c = new CarrierCar();
                        c.CarrierId = m.CarrierId;
                        c.CarNo = m.CarNo;
                        c.TrailerNo = m.TrailerNo;
                        c.CarryingCapacity = m.CarryingCapacity;
                        listCar.Add(c);
                    }
                }

                List<CarrierDriver> listDriver = new List<CarrierDriver>();
                if (model.Drivers != null)
                {
                    foreach (CarrierDriverViewModel m in model.Drivers)
                    {
                        CarrierDriver d = new CarrierDriver();
                        d.CarrierId = m.CarrierId;
                        d.CarNo = m.CarNo;
                        d.Name = m.Name;
                        d.LicenseNo = m.LicenseNo;
                        d.MobileTel = m.MobileTel;
                        d.HomeTel = m.HomeTel;
                        listDriver.Add(d);
                    }
                }

                List<CarrierSettlementExpression> listExpression = new List<CarrierSettlementExpression>();
                if (model.SettlementExpressions != null)
                {
                    foreach (CarrierSettlementExpressionViewModel m in model.SettlementExpressions)
                    {
                        CarrierSettlementExpression e = new CarrierSettlementExpression();
                        e.CarrierId = m.CarrierId;
                        e.PlanType = m.PlanType;
                        e.TransportChargeExpression = m.TransportChargeExpression;
                        e.TransportPriceExpression = m.TransportPriceExpression;
                        listExpression.Add(e);
                    }
                }

                List<CarrierTransportPrice> listPrice = new List<CarrierTransportPrice>();
                if (model.TransportPrices != null)
                {
                    foreach (CarrierTransportPriceViewModel m in model.TransportPrices)
                    {
                        CarrierTransportPrice p = new CarrierTransportPrice();
                        p.CarrierId = m.CarrierId;
                        p.StartCountry = m.StartCountry;
                        p.StartProvince = m.StartProvince;
                        p.StartCity = m.StartCity;
                        p.DestCountry = m.DestCountry;
                        p.DestProvince = m.DestProvince;
                        p.DestCity = m.DestCity;
                        p.PlanType = m.PlanType;
                        p.StartTime = DateTime.Parse(m.StartTime);
                        p.EndTime = DateTime.Parse(m.EndTime);
                        p.TransportPrice = m.TransportPrice;
                        listPrice.Add(p);
                    }
                }

                //保存数据
                string strErrText;
                DDSystem dd = new DDSystem();
                if (dd.InsertCarrier(data, listCar, listDriver, listExpression, listPrice, LoginAccountId, LoginStaffName, out strErrText) > 0)
                {
                    return Json(string.Empty);
                }
                else
                {
                    return Json(strErrText);
                }
            }
            return View(model);
        }
Example #2
0
        public ActionResult NewCarrier()
        {
            string strErrText;

            //生成国家下拉列表项
            DDSystem dd = new DDSystem();
            List<Country> listCountry = dd.LoadCountrys(LoginAccountId, LoginStaffName, out strErrText);
            if (listCountry == null)
            {
                throw new Exception(strErrText);
            }
            List<SelectListItem> selectListCountry = new List<SelectListItem>();
            selectListCountry.Add(new SelectListItem { Text = string.Empty, Value = string.Empty });
            selectListCountry.AddRange(from c in listCountry
                                       select new SelectListItem
                                       {
                                           Text = c.Name,
                                           Value = c.Name
                                       });
            ViewData["Countrys"] = new SelectList(selectListCountry, "Value", "Text");

            //生成空的省份下拉列表项
            List<Province> listState = new List<Province>();
            List<SelectListItem> selectListState = new List<SelectListItem>();
            selectListState.Add(new SelectListItem { Text = string.Empty, Value = string.Empty });
            selectListState.AddRange(from s in listState
                                     select new SelectListItem
                                     {
                                         Text = s.Name,
                                         Value = s.Name
                                     });
            ViewData["Provinces"] = new SelectList(selectListState, "Value", "Text");

            //生成空的城市下拉列表项
            List<City> listCity = new List<City>();
            List<SelectListItem> selectListCity = new List<SelectListItem>();
            selectListCity.Add(new SelectListItem { Text = string.Empty, Value = string.Empty });
            selectListCity.AddRange(from ci in listCity
                                    select new SelectListItem
                                    {
                                        Text = ci.Name,
                                        Value = ci.Name
                                    });
            ViewData["Citys"] = new SelectList(selectListCity, "Value", "Text");

            //创建空的Model
            CarrierViewModel model = new CarrierViewModel();

            model.Cars = new List<CarrierCarViewModel>();
            model.Cars.Add(new CarrierCarViewModel());

            model.Drivers = new List<CarrierDriverViewModel>();
            model.Drivers.Add(new CarrierDriverViewModel());

            model.SettlementExpressions = new List<CarrierSettlementExpressionViewModel>();
            model.SettlementExpressions.Add(new CarrierSettlementExpressionViewModel());

            model.TransportPrices = new List<CarrierTransportPriceViewModel>();
            model.TransportPrices.Add(new CarrierTransportPriceViewModel());

            return View(model);
        }