/// <summary> /// 添加操作码 /// </summary> /// <param name="keyCode"></param> /// <param name="name"></param> /// <param name="menuId"></param> /// <param name="isValid"></param> /// <param name="desc"></param> /// <returns></returns> public JsonMessage Insert(string keyCode, string name, string menuId, bool isValid, string desc) { JsonMessage jsonMsg = new JsonMessage(); //返回Json int result = -1; //类型(成功 、失败) try { DataTable dt = _menuOpApp.GetByCodeOrName(menuId, name, keyCode); if (!ValidateHelper.IsDataTableNotData(dt)) { throw new CustomException(0, " 添加操作码失败,操作码名称或代码重复"); } SysMenuOptModel model = new SysMenuOptModel(); model.MO_CODE = keyCode; model.MO_NAME = name; model.MENU_ID = menuId; model.IS_ABLED = isValid ? 1 : 0; model.MO_DESC = desc; model.CREATE_USER = UserID; model.LM_USER = UserID; result = _menuOpApp.Insert(model); jsonMsg = ServiceResult.Message(1, "添加操作码成功"); } catch (CustomException ex) { jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message); } catch (Exception ex) { jsonMsg = ServiceResult.Message(-1, ex.Message); WriteSystemException(ex, this.GetType(), OPT_MODEL, "为菜单[" + menuId + "]添加操作码[" + keyCode + "]失败"); } //写入log WriteSystemLog(jsonMsg, CREATE, OPT_MODEL, menuId + ":" + keyCode + ":添加操作码"); return(jsonMsg); }
/// <summary> /// 添加操作码 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(SysMenuOptModel model) { StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO SYS_MENU_OPT"); sql.AppendLine(" (MO_CODE, MO_NAME, MENU_ID, IS_ABLED, MO_DESC, CREATE_USER, LM_USER)"); sql.AppendLine("VALUES"); sql.AppendLine(" ($MO_CODE, $MO_NAME, $MENU_ID, $IS_ABLED, $MO_DESC, $CREATE_USER, $LM_USER)"); SQLParameter[] parms = { new SQLParameter("MO_CODE", typeof(string), model.MO_CODE), new SQLParameter("MO_NAME", typeof(string), model.MO_NAME), new SQLParameter("MENU_ID", typeof(string), model.MENU_ID), new SQLParameter("IS_ABLED", typeof(int), model.IS_ABLED), new SQLParameter("MO_DESC", typeof(string), model.MO_DESC), new SQLParameter("CREATE_USER", typeof(string), model.CREATE_USER), new SQLParameter("LM_USER", typeof(string), model.LM_USER), }; int result = DB.CustomExecuteWithReturn(new SQLParamCondition(sql.ToString(), parms)); return(result); }
public JsonMessage Insert(string menuName, string parentId, string code, string link, string icon, int sort, string type, string desc, bool isable, bool isend) { JsonMessage jsonMsg = new JsonMessage(); //返回Json int result = -1; //类型(成功 、失败) _menuRep.BeginTransaction(); try { DataTable dt = _menuRep.GetByCodeOrName(code, menuName); if (!ValidateHelper.IsDataTableNotData(dt)) { throw new CustomException(0, "添加失败,菜单名称或编码已存在"); } SysMenuModel model = new SysMenuModel(); model.MENU_ID = GuidHelper.GenerateComb().ToString().ToUpper(); model.MENU_NAME = menuName; model.PARENT_ID = parentId; model.MENU_CODE = code; model.MENU_PATH = link; model.MENU_ICON = icon; model.MENU_SORT = sort; model.MENU_TYPE = type; model.MENU_DESC = desc; model.IS_ABLED = isable ? 1 : 0; model.IS_END = isend ? 1 : 0; model.CREATE_USER = UserID; model.LM_USER = UserID; result = _menuRep.Insert(model); if (result == 1) { SysMenuOptModel optModel = new SysMenuOptModel(); optModel.MO_CODE = "browse"; optModel.MO_NAME = "浏览"; optModel.MENU_ID = model.MENU_ID; optModel.IS_ABLED = 1; optModel.MO_DESC = "请勿删除,默认添加项,误删除请重新添加上"; optModel.CREATE_USER = UserID; optModel.LM_USER = UserID; _menuOptRep.Insert(optModel); _rightRep.InsertSysRight(model.CREATE_USER, model.LM_USER); } _menuRep.CommitTransaction(); jsonMsg = ServiceResult.Message(1, "菜单添加成功"); } catch (CustomException ex) { _menuRep.RollbackTransaction(); jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message); } catch (Exception ex) { _menuRep.RollbackTransaction(); jsonMsg = ServiceResult.Message(-1, ex.Message); WriteSystemException(ex, this.GetType(), OPT_MODEL, code + ":添加系统菜单失败"); } //写入log WriteSystemLog(jsonMsg, CREATE, OPT_MODEL, code + ":添加系统菜单"); return(jsonMsg); }