/// <summary> /// 编辑及新增 /// </summary> /// <param name="id"></param> /// <param name="pid">上级菜单ID</param> /// <returns></returns> public ActionResult Edit(int id, int pid = 0) { Dictionary <int, string> dicRquestType = new Dictionary <int, string>(); foreach (CS.Common.FW.Enums.ReportType source in Enum.GetValues(typeof(CS.Common.FW.Enums.ReportType))) { dicRquestType.Add((int)source, source.ToString()); } var dt = BF_MENU.Instance.GetTableFields("ID,PID,NAME", "IS_ENABLE = ?", 1); var obj = new List <object>(); obj.Add( new { id = 0, pId = 0, name = BLL.FW.BF_SYS_CONFIG.SystemName }); foreach (DataRow dr in dt.Rows) { obj.Add( new { id = Convert.ToInt32(dr["ID"]), pId = Convert.ToInt32(dr["PID"]), name = dr["NAME"].ToString() }); } ViewBag.Result = false; ViewBag.Message = string.Empty; ViewBag.DIC_MENUS = SerializeObject(obj); ViewBag.DIC_REQUEST_TYPE = dicRquestType; List <string> iconNames = LoadIconNames(); ViewBag.LoadIconNames = "var iconNames = " + SerializeObject(LoadIconNames()) + ";"; BF_MENU.Entity entity = new BF_MENU.Entity(); if (id > 0) { entity = BF_MENU.Instance.GetEntityByKey <BF_MENU.Entity>(id); if (entity == null) { ViewBag.Message = "菜单不存在"; entity = new BF_MENU.Entity(); entity.ID = -1; } } else { entity.PID = pid; } ModelState.Clear(); return(View(entity)); }
public ActionResult Edit(BF_MENU.Entity entity) { JsonResultData result = new JsonResultData(); try { if (entity.IS_SHOW_NAV == 1 && BF_MENU.Instance.IsSetMenus(entity.PID) == false)//是否超过三级 { result.IsSuccess = false; result.Message = "增加的菜单层级不能超过3级,请重新选择上层父级"; return(Json(result, JsonRequestBehavior.AllowGet)); } Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("PID", entity.PID); dic.Add("NAME", entity.NAME); dic.Add("ORDER_NUM", entity.ORDER_NUM); dic.Add("URL", entity.URL); dic.Add("IS_SHOW_NAV", entity.IS_SHOW_NAV); if (string.IsNullOrWhiteSpace(entity.ICON) == false) { dic.Add("FONT", "layui-icon"); dic.Add("ICON", entity.ICON); } dic.Add("REPORT_TYPE", entity.REPORT_TYPE); dic.Add("REPORT_ID", entity.REPORT_ID); dic.Add("UPDATE_UID", SystemSession.UserID); dic.Add("UPDATE_TIME", DateTime.Now); if (entity.ID > 0) { //修改 int i = BF_MENU.Instance.UpdateByKey(dic, entity.ID); if (i > 0) { result.IsSuccess = true; result.Message = "更新成功"; } else { result.Message = "出现了未知错误"; } } else { //是否启用(默认) dic.Add("IS_ENABLE", 1); //是否为内置菜单(默认) dic.Add("IS_DEFAULT", 0); //创建者 dic.Add("CREATE_UID", SystemSession.UserID); //创建时间 dic.Add("CREATE_TIME", DateTime.Now); //添加 int i = BF_MENU.Instance.Add(dic); if (i > 0) { result.IsSuccess = true; result.Message = "添加成功"; } else { result.Message = "出现了未知错误"; } } } catch (Exception ex) { result.Message = ex.Message; } return(Json(result, JsonRequestBehavior.AllowGet)); }