Example #1
0
        public ActionResult NewReceiver()
        {
            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
            ReceiverViewModel model = new ReceiverViewModel();

            model.Distances = new List<ReceiverDistanceViewModel>();
            model.Distances.Add(new ReceiverDistanceViewModel());

            return View(model);
        }
Example #2
0
        public ActionResult NewReceiver(ReceiverViewModel model)
        {
            if (ModelState.IsValid)
            {
                //创建数据
                Receiver data = new Receiver();
                data.Name = model.Name;
                data.Country = model.Country;
                data.Province = model.Province;
                data.City = model.City;
                data.Address = model.Address;
                data.Contact = model.Contact;
                data.ContactTel = model.ContactTel;

                List<ReceiverDistance> listDistance = new List<ReceiverDistance>();
                if (model.Distances != null)
                {
                    foreach (ReceiverDistanceViewModel m in model.Distances)
                    {
                        ReceiverDistance d = new ReceiverDistance();
                        d.ReceiverName = model.Name;
                        d.StartCountry = m.StartCountry;
                        d.StartProvince = m.StartProvince;
                        d.StartCity = m.StartCity;
                        d.KM = m.KM;
                        listDistance.Add(d);
                    }
                }

                //保存数据
                string strErrText;
                DDSystem dd = new DDSystem();
                if (dd.InsertReceiver(data, listDistance, LoginAccountId, LoginStaffName, out strErrText) > 0)
                {
                    return Json(string.Empty);
                }
                else
                {
                    return Json(strErrText);
                }
            }
            return View(model);
        }
Example #3
0
        public ActionResult ModifyReceiver(string id)
        {
            string strErrText;

            //生成Model数据
            DDSystem dd = new DDSystem();
            Receiver data = dd.LoadReceiver(long.Parse(id), LoginAccountId, LoginStaffName, out strErrText);
            if (data == null)
            {
                throw new Exception(strErrText);
            }

            ReceiverViewModel model = new ReceiverViewModel();
            model.Id = data.Id;
            model.Name = data.Name;
            model.Country = data.Country;
            model.Province = data.Province;
            model.City = data.City;
            model.Address = data.Address;
            model.Contact = data.Contact;
            model.ContactTel = data.ContactTel;

            model.Distances = new List<ReceiverDistanceViewModel>();
            model.Distances.Add(new ReceiverDistanceViewModel());

            //生成国家下拉列表项
            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", model.Country);

            //生成空的省份下拉列表项
            List<Province> listState = null;
            if (!string.IsNullOrEmpty(model.Country))
            {
                listState = dd.LoadProvincesByCountry(model.Country, LoginAccountId, LoginStaffName, out strErrText);
                if (listState == null)
                {
                    throw new Exception(strErrText);
                }
            }
            else
            {
                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", model.Province);

            //生成空的城市下拉列表项
            List<City> listCity = null;
            if (!string.IsNullOrEmpty(model.Province))
            {
                listCity = dd.LoadCitysByProvince(model.Country, model.Province, LoginAccountId, LoginStaffName, out strErrText);
                if (listCity == null)
                {
                    throw new Exception(strErrText);
                }
            }
            else
            {
                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.City);

            return View(model);
        }