public ActionResult NewGoodsType() { string strErrText; //生成上级货物类别下拉列表项 DDSystem dd = new DDSystem(); List<GoodsType> listGoodsType = dd.LoadGoodsTypes(LoginAccountId, LoginStaffName, out strErrText); if (listGoodsType == null) { throw new Exception(strErrText); } List<SelectListItem> selectListGoodsType = new List<SelectListItem>(); selectListGoodsType.Add(new SelectListItem { Text = string.Empty, Value = "0" }); selectListGoodsType.AddRange(from o in listGoodsType orderby o.FullName select new SelectListItem { Text = o.FullName, Value = o.Id.ToString() }); ViewData["GoodsTypes"] = new SelectList(selectListGoodsType, "Value", "Text"); //创建空的Model GoodsTypeViewModel model = new GoodsTypeViewModel(); return View(model); }
public ActionResult NewGoodsType(GoodsTypeViewModel model) { if (ModelState.IsValid) { //创建数据 GoodsType data = new GoodsType(); data.Name = model.Name; data.ParentId = model.ParentId; data.Remark = model.Remark ?? string.Empty; //保存数据 string strErrText; DDSystem dd = new DDSystem(); if (dd.InsertGoodsType(data, LoginAccountId, LoginStaffName, out strErrText)) { return Json(string.Empty); } else { return Json(strErrText); } } return View(model); }
public ActionResult ModifyGoodsType(string id) { string strErrText; //生成Model数据 DDSystem dd = new DDSystem(); GoodsType data = dd.LoadGoodsType(long.Parse(id), LoginAccountId, LoginStaffName, out strErrText); if (data == null) { throw new Exception(strErrText); } GoodsTypeViewModel model = new GoodsTypeViewModel(); model.Id = data.Id; model.Name = data.Name; model.ParentId = data.ParentId; model.Remark = data.Remark; List<GoodsType> listGoodsType = dd.LoadGoodsTypes(LoginAccountId, LoginStaffName, out strErrText); if (listGoodsType == null) { throw new Exception(strErrText); } List<SelectListItem> selectlistGoodsType = new List<SelectListItem>(); selectlistGoodsType.Add(new SelectListItem { Text = string.Empty, Value = "0" }); selectlistGoodsType.AddRange(from t in listGoodsType where !t.FullPath.StartsWith(data.FullPath) orderby t.FullName select new SelectListItem { Text = t.FullName, Value = t.Id.ToString() }); ViewData["GoodsTypes"] = new SelectList(selectlistGoodsType, "Value", "Text", model.ParentId); return View(model); }