/// <summary> /// 更新已有编辑器用户权限 /// </summary> /// <param name="userRight">用户权限</param> /// <returns>SystemData.ReturnValue</returns> public short UpdateUserRight(UserRightBase userRight) { if (userRight == null || GlobalMethods.Misc.IsEmptyString(userRight.UserID)) return SystemData.ReturnValue.PARAM_ERROR; if (base.MedQCAccess == null) return SystemData.ReturnValue.PARAM_ERROR; string szField = string.Format("{0}='{1}'", SystemData.UserRightTable.RIGHT_CODE, userRight.GetRightCode()); string szCondition = string.Format("{0}='{1}' AND {2}='{3}'" , SystemData.UserRightTable.USER_ID, userRight.UserID , SystemData.UserRightTable.RIGHT_TYPE, UserRightBase.GetRightTypeName(userRight.RightType)); string szTable = SystemData.DataTable.USER_RIGHT; string szSQL = string.Format(SystemData.SQL.UPDATE, szTable, szField, szCondition); int count = 0; try { count = base.MedQCAccess.ExecuteNonQuery(szSQL, CommandType.Text); } catch (Exception ex) { LogManager.Instance.WriteLog("RightAccess.UpdateUserRight", new string[] { "szSQL" }, new object[] { szSQL }, ex); return SystemData.ReturnValue.EXCEPTION; } return (count <= 0) ? SystemData.ReturnValue.RES_NO_FOUND : SystemData.ReturnValue.OK; }
/// <summary> /// 查询获取指定的用户是否已配置权限 /// </summary> /// <param name="szUserID">用户ID</param> /// <param name="rightType">用户权限类型</param> /// <param name="nCount">返回的记录数</param> /// <returns>SystemData.ReturnValue</returns> private short ExistRightInfo(string szUserID, UserRightType rightType, ref int nCount) { if (GlobalMethods.Misc.IsEmptyString(szUserID)) return SystemData.ReturnValue.PARAM_ERROR; if (base.MedQCAccess == null) return SystemData.ReturnValue.PARAM_ERROR; string szCondition = string.Format("{0}='{1}'AND {2}='{3}'" , SystemData.UserRightTable.USER_ID, szUserID , SystemData.UserRightTable.RIGHT_TYPE, UserRightBase.GetRightTypeName(rightType)); string szSQL = string.Format(SystemData.SQL.SELECT_WHERE, "COUNT(*)", SystemData.DataTable.USER_RIGHT, szCondition); nCount = 0; try { object objValue = base.MedQCAccess.ExecuteScalar(szSQL, CommandType.Text); if (objValue == null || objValue == System.DBNull.Value) nCount = 0; if (!int.TryParse(objValue.ToString(), out nCount)) nCount = 0; } catch (Exception ex) { LogManager.Instance.WriteLog("RightAccess.ExistRightInfo", new string[] { "SQL" }, new object[] { szSQL }, "SQL执行失败!", ex); return SystemData.ReturnValue.EXCEPTION; } return SystemData.ReturnValue.OK; }
/// <summary> /// 获取所有编辑器用户权限 /// </summary> /// <param name="rightType">用户权限类型</param> /// <param name="lstUserRight">用户权限信息列表</param> /// <returns>SystemData.ReturnValue</returns> public short GetUserRight(UserRightType rightType, ref List<UserRightBase> lstUserRight) { if (base.MedQCAccess == null) return SystemData.ReturnValue.PARAM_ERROR; string szField = string.Format("{0},{1},{2}" , SystemData.UserRightTable.USER_ID, SystemData.UserRightTable.RIGHT_CODE , SystemData.UserRightTable.RIGHT_DESC); string szTable = SystemData.DataTable.USER_RIGHT; DbParameter[] param = new DbParameter[1]{new DbParameter(SystemData.UserRightTable.RIGHT_TYPE , UserRightBase.GetRightTypeName(rightType))}; string szCondition = string.Format("{0}='{1}' or {0}='MRQC'", SystemData.UserRightTable.RIGHT_TYPE ,SystemData.UserRightTable.RIGHT_TYPE); string szSQL = string.Format(SystemData.SQL.SELECT_WHERE, szField, szTable, szCondition); IDataReader dataReader = null; try { dataReader = base.MedQCAccess.ExecuteReader(szSQL, CommandType.Text, ref param); if (dataReader == null || dataReader.IsClosed || !dataReader.Read()) return SystemData.ReturnValue.RES_NO_FOUND; if (lstUserRight == null) lstUserRight = new List<UserRightBase>(); lstUserRight.Clear(); do { UserRightBase userRight = UserRightBase.Create(rightType); userRight.UserID = dataReader.GetString(0).Trim(); if (!dataReader.IsDBNull(2)) userRight.RightDesc = dataReader.GetString(2); if (!dataReader.IsDBNull(1)) userRight.SetRightCode(dataReader.GetString(1)); lstUserRight.Add(userRight); } while (dataReader.Read()); return SystemData.ReturnValue.OK; } catch (Exception ex) { LogManager.Instance.WriteLog("RightAccess.GetUserRight", new string[] { "szSQL" }, new object[] { szSQL }, ex); return SystemData.ReturnValue.EXCEPTION; } finally { base.MedQCAccess.CloseConnnection(false); } }
/// <summary> /// 保存用户权限 /// </summary> /// <param name="userRight">用户权限</param> /// <returns>SystemData.ReturnValue</returns> public short SaveUserRight(UserRightBase userRight) { if (userRight == null || GlobalMethods.Misc.IsEmptyString(userRight.UserID)) return SystemData.ReturnValue.PARAM_ERROR; int count = 0; short shRet = this.ExistRightInfo(userRight.UserID, userRight.RightType, ref count); if (shRet != SystemData.ReturnValue.OK) return shRet; if (count > 0) return this.UpdateUserRight(userRight); if (base.MedQCAccess == null) return SystemData.ReturnValue.PARAM_ERROR; string szField = string.Format("{0},{1},{2},{3}" , SystemData.UserRightTable.USER_ID, SystemData.UserRightTable.RIGHT_CODE , SystemData.UserRightTable.RIGHT_DESC, SystemData.UserRightTable.RIGHT_TYPE); string szValue = string.Format("'{0}','{1}','{2}','{3}'" , userRight.UserID, userRight.GetRightCode().Replace('0','1') , userRight.RightDesc, UserRightBase.GetRightTypeName(userRight.RightType)); string szTable = SystemData.DataTable.USER_RIGHT; string szSQL = string.Format(SystemData.SQL.INSERT, szTable, szField, szValue); count = 0; try { count = base.MedQCAccess.ExecuteNonQuery(szSQL, CommandType.Text); } catch (Exception ex) { LogManager.Instance.WriteLog("RightAccess.SaveUserRight", new string[] { "szSQL" }, new object[] { szSQL }, ex); return SystemData.ReturnValue.EXCEPTION; } return (count > 0) ? SystemData.ReturnValue.OK : SystemData.ReturnValue.ACCESS_ERROR; }