/// <summary> /// 更新权限按钮标识 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateRightOpt(SysRightOptModel model) { StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE SYS_RIGHT_OPT SET IS_ABLED = $IS_ABLED WHERE MENU_ID = $MENU_ID AND ROLE_ID=$ROLE_ID AND MO_CODE=$MO_CODE"); SQLParameter[] parms = { new SQLParameter("IS_ABLED", typeof(int), model.IS_ABLED), new SQLParameter("MENU_ID", typeof(string), model.MENU_ID), new SQLParameter("ROLE_ID", typeof(string), model.ROLE_ID), new SQLParameter("MO_CODE", typeof(string), model.MO_CODE) }; int result = DB.CustomExecuteWithReturn(new SQLParamCondition(sql.ToString(), parms)); return(result); }
/// <summary> /// 添加权限按钮标识 /// </summary> /// <param name="model"></param> /// <returns></returns> public int InsertRightOpt(SysRightOptModel model) { StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO SYS_RIGHT_OPT"); sql.AppendLine(" (MENU_ID, ROLE_ID, MO_CODE, IS_ABLED, CREATE_USER, LM_USER)"); sql.AppendLine("VALUES"); sql.AppendLine(" ($MENU_ID, $ROLE_ID, $MO_CODE, $IS_ABLED, $CREATE_USER, $LM_USER)"); SQLParameter[] parms = { new SQLParameter("MENU_ID", typeof(string), model.MENU_ID), new SQLParameter("ROLE_ID", typeof(string), model.ROLE_ID), new SQLParameter("MO_CODE", typeof(string), model.MO_CODE), new SQLParameter("IS_ABLED", typeof(int), model.IS_ABLED), 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); }
/// <summary> /// 分配角色权限 /// </summary> /// <param name="menu_id"></param> /// <param name="role_id"></param> /// <param name="mo_codes"></param> /// <param name="isValid"></param> /// <returns></returns> public JsonMessage UpdateRight(string menu_id, string role_id, string mo_codes, bool isValid) { JsonMessage jsonMsg = new JsonMessage(); //返回Json int result = -1; //类型(成功 、失败) _rightRep.BeginTransaction(); try { int cc = _rightRep.UpdateRightOptByMenuIdAndRoleId(menu_id, role_id); string[] mo_code = mo_codes.Split(','); foreach (string code in mo_code) { SysRightOptModel model = new SysRightOptModel(); model.MENU_ID = menu_id; model.ROLE_ID = role_id; model.MO_CODE = code; model.IS_ABLED = isValid ? 1 : 0; model.CREATE_USER = UserID; model.LM_USER = UserID; //判断RightOpt是否存在,有就更新 否则就添加 if (_rightRep.UpdateRightOpt(model) < 1) { _rightRep.InsertRightOpt(model); } } //_rightRep.InsertSysRight(UserID, UserID); _rightRep.UpdateRightFlagByMenuIdAndRoleId(1, menu_id, role_id); DataTable dt3 = _menuRep.GetById(menu_id);//获取父级ID if (dt3.Rows.Count > 0) { string tmp_parentId = dt3.Rows[0]["PARENT_ID"].ToString(); DataTable dt4 = _rightRep.GetRightByMenuParentIdAndRoleId(tmp_parentId, role_id); if (dt4.Rows.Count > 0) { _rightRep.UpdateRightFlagByMenuIdAndRoleId(1, tmp_parentId, role_id); } else { _rightRep.UpdateRightFlagByMenuIdAndRoleId(0, tmp_parentId, role_id); } } result = 1; _rightRep.CommitTransaction(); jsonMsg = ServiceResult.Message(1, "操作成功"); } catch (Exception ex) { _rightRep.RollbackTransaction(); jsonMsg = ServiceResult.Message(-1, ex.Message); WriteSystemException(ex, this.GetType(), OPT_MODEL, "分配角色权限失败"); } //写入log WriteSystemLog(jsonMsg, UPDATE, OPT_MODEL, "分配角色权限"); return(jsonMsg); }