public ActionResult NewOrganization() { string strErrText; //生成上级组织部门下拉列表项 OrganizationSystem organ = new OrganizationSystem(); List<Organization> listOrganization = organ.LoadOrganizations(LoginAccountId, LoginStaffName, out strErrText); if (listOrganization == null) { throw new Exception(strErrText); } List<SelectListItem> selectListOrganization = new List<SelectListItem>(); selectListOrganization.Add(new SelectListItem { Text = string.Empty, Value = "0" }); selectListOrganization.AddRange(from o in listOrganization orderby o.FullName select new SelectListItem { Text = o.FullName, Value = o.Id.ToString() }); ViewData["Organizations"] = new SelectList(selectListOrganization, "Value", "Text"); //生成国家下拉列表项 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["Countries"] = 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["States"] = 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["Cities"] = new SelectList(selectListCity, "Value", "Text"); //创建空的Model OrganizationViewModel model = new OrganizationViewModel(); return View(model); }
public ActionResult NewOrganization(OrganizationViewModel model) { if (ModelState.IsValid) { //创建数据 Organization data = new Organization(); data.Name = model.Name; data.ParentId = model.ParentId; data.CountryName = model.CountryName ?? string.Empty; data.ProvinceName = model.StateName ?? string.Empty; data.CityName = model.CityName ?? string.Empty; data.Address = model.Address ?? string.Empty; data.PostalCode = model.PostalCode ?? string.Empty; data.Remark = model.Remark ?? string.Empty; //保存数据 string strErrText; OrganizationSystem organ = new OrganizationSystem(); if (organ.InsertOrganization(data, LoginAccountId, LoginStaffName, out strErrText)) { return Json(string.Empty); } else { return Json(strErrText); } } return View(model); }
public ActionResult ModifyOrganization(string id) { string strErrText; //生成Model数据 OrganizationSystem organ = new OrganizationSystem(); Organization data = organ.LoadOrganization(long.Parse(id), LoginAccountId, LoginStaffName, out strErrText); if (data == null) { throw new Exception(strErrText); } OrganizationViewModel model = new OrganizationViewModel(); model.Id = data.Id; model.Name = data.Name; model.ParentId = data.ParentId; model.CountryName = data.CountryName; model.StateName = data.ProvinceName; model.CityName = data.CityName; model.Address = data.Address; model.PostalCode = data.PostalCode; model.Remark = data.Remark; //生成上级组织部门下拉列表项 List<Organization> listOrganization = organ.LoadOrganizations(LoginAccountId, LoginStaffName, out strErrText); if (listOrganization == null) { throw new Exception(strErrText); } List<SelectListItem> selectListOrganization = new List<SelectListItem>(); selectListOrganization.Add(new SelectListItem { Text = string.Empty, Value = "0" }); selectListOrganization.AddRange(from o in listOrganization where !o.FullPath.StartsWith(data.FullPath) orderby o.FullName select new SelectListItem { Text = o.FullName, Value = o.Id.ToString() }); ViewData["Organizations"] = new SelectList(selectListOrganization, "Value", "Text", model.ParentId); //生成国家下拉列表项 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["Countries"] = new SelectList(selectListCountry, "Value", "Text", model.CountryName); //生成空的省份下拉列表项 List<Province> listState = null; if (!string.IsNullOrEmpty(model.CountryName)) { listState = dd.LoadProvincesByCountry(model.CountryName, 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["States"] = new SelectList(selectListState, "Value", "Text", model.StateName); //生成空的城市下拉列表项 List<City> listCity = null; if (!string.IsNullOrEmpty(model.StateName)) { listCity = dd.LoadCitysByProvince(model.CountryName, model.StateName, 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["Cities"] = new SelectList(selectListCity, "Value", "Text", model.CityName); return View(model); }