/// <summary> /// 新增权限 /// </summary> /// <param name="pEntity"></param> /// <returns></returns> public static int AddPrivileges(PrivilegeEntity pEntity) { string sqlCommand = string.Format(@"INSERT INTO Base_Privilege ( PrivilegeId,PrivilegeName,PrivilegeCode,ParentPrivilegeId,ParentPrivilegeName,PrivilegeType,Library,NameSpace,MenuPic,Displayorder,Status,Remark ) VALUES ( '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}' )", pEntity.PrivilegeId, pEntity.PrivilegeName, pEntity.PrivilegeCode, pEntity.ParentPrivilegeId, pEntity.ParentPrivilegeName, (int)pEntity.PrivilegeType, pEntity.Library, pEntity.NameSpace, pEntity.MenuPic, pEntity.Displayorder, (int)pEntity.Status, pEntity.Remark); return DbHelper.ExecuteNonQuery(sqlCommand); }
/// <summary> /// 读取权限 /// </summary> /// <param name="loginId">登录ID</param> /// <param name="privilegeId"></param> /// <returns></returns> public PrivilegeEntity ReadPrivileges(string loginId, string privilegeId) { PrivilegeEntity pEntity = new PrivilegeEntity(); if (ComFunction.ExistUserLoginID(loginId) == false) { pEntity.Result = false; pEntity.Desc = ResCode.UL003Desc; return pEntity; } try { DataTable dt = ComFunction.ReadPrivileges(privilegeId); foreach (DataRow dr in dt.Rows) { pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.PrivilegeCode = dr["PrivilegeCode"].ToString(); pEntity.ParentPrivilegeId = dr["ParentPrivilegeId"].ToString(); pEntity.ParentPrivilegeName = dr["ParentPrivilegeName"].ToString(); pEntity.PrivilegeType = (PrivilegeType)dr["PrivilegeType"]; pEntity.Library = dr["Library"].ToString(); pEntity.NameSpace = dr["NameSpace"].ToString(); pEntity.MenuPic = dr["MenuPic"].ToString(); pEntity.Displayorder = (int)dr["Displayorder"]; pEntity.Status = (Status)dr["Status"]; pEntity.Remark = dr["Remark"].ToString(); } pEntity.Desc = "获取系统权限成功!"; pEntity.Result = true; } catch (Exception ex) { pEntity.Result = false; pEntity.Desc = "获取权限记录出错,原因:" + ex.ToString(); ManagerLog.WriteErr(ex); } return pEntity; }
/// <summary> /// 获取用户顶部菜单 /// </summary> /// <param name="loginId"></param> /// <param name="userId"></param> /// <param name="list"></param> /// <returns></returns> public EntityBase GetPrivilegeTopMenu(string loginId, string userId, ref List<PrivilegeEntity> list) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { DataTable dt = ComFunction.GetPrivilegeTopMenu(userId); PrivilegeEntity pEntity = null; foreach (DataRow dr in dt.Rows) { pEntity = new PrivilegeEntity(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeCode = dr["PrivilegeCode"].ToString(); pEntity.MenuPic = dr["MenuPic"].ToString(); list.Add(pEntity); } entityBase.Desc = "获取顶部菜单成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("获取顶部菜单出错,原因:", ex); } return entityBase; }
/// <summary> /// 获取带有角色标记的所有权限记录集 /// </summary> /// <param name="loginId"></param> /// <param name="roleId"></param> /// <param name="list"></param> /// <returns></returns> public EntityBase GetPrivilegesWithRoleSign(string loginId, string roleId, ref List<PrivilegeEntity> list) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { DataTable dt = ComFunction.GetPrivilegesWithRoleSign(roleId); PrivilegeEntity pEntity = null; foreach (DataRow dr in dt.Rows) { pEntity = new PrivilegeEntity(); pEntity.Check = Convert.ToBoolean(dr["ISCHECK"]); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.PrivilegeCode = dr["PrivilegeCode"].ToString(); pEntity.ParentPrivilegeId = dr["ParentPrivilegeId"].ToString(); pEntity.ParentPrivilegeName = dr["ParentPrivilegeName"].ToString(); pEntity.PrivilegeType = (PrivilegeType)dr["PrivilegeType"]; pEntity.Library = dr["Library"].ToString(); pEntity.NameSpace = dr["NameSpace"].ToString(); pEntity.MenuPic = dr["MenuPic"].ToString(); pEntity.Displayorder =(int)dr["Displayorder"]; pEntity.Status = (Status)dr["Status"]; pEntity.Remark = dr["Remark"].ToString(); list.Add(pEntity); } entityBase.Desc = "获取系统所有角色成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("获取角色记录数出错,原因:", ex); } return entityBase; }
/// <summary> /// 获取系统角色权限列表 /// </summary> /// <param name="loginId"></param> /// <param name="roleID"></param> /// <param name="list"></param> /// <returns></returns> public EntityBase GetPrivilegesRole(string loginId, string roleID, ref List<PrivilegeEntity> list) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { DataTable dt = ComFunction.GetPrivilegesRole(roleID); PrivilegeEntity pEntity = null; foreach (DataRow dr in dt.Rows) { pEntity = new PrivilegeEntity(); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeName = dr["PRIVILEGENAME"].ToString(); pEntity.ParentPrivilegeId = dr["ParentPrivilegeId"].ToString(); list.Add(pEntity); } entityBase.Desc = "获取系角色权限成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("获取系角色权限出错,原因:", ex); } return entityBase; }
/// <summary> /// leftMenu菜单 /// </summary> /// <param name="loginId"></param> /// <param name="currentPrivilegID"></param> /// <param name="userid"></param> /// <param name="list"></param> /// <returns></returns> public EntityBase GetPrivilegesByParentID(string loginId, string currentPrivilegID, string userid, ref List<PrivilegeEntity> list) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { DataTable dt = ComFunction.GetPrivilegesByParentID(currentPrivilegID, userid); PrivilegeEntity pEntity = null; foreach (DataRow dr in dt.Rows) { pEntity = new PrivilegeEntity(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeCode = dr["PrivilegeCode"].ToString(); pEntity.MenuPic = dr["MenuPic"].ToString(); pEntity.Library = dr["Library"].ToString(); pEntity.NameSpace = dr["NameSpace"].ToString(); pEntity.MenuPic = dr["MenuPic"].ToString(); list.Add(pEntity); } entityBase.Desc = "获取系统所有角色成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("获取角色记录数出错,原因:", ex); } return entityBase; }
/// <summary> /// 获取所以权限 /// </summary> /// <param name="loginId">登录ID</param> /// <param name="list">权限集合</param> /// <returns>权限集合</returns> public EntityBase GetPrivileges(string loginId, ref List<PrivilegeEntity> list) { TradeUser reftradeuser = new TradeUser(); if (ComFunction.ExistUserLoginID(loginId,ref reftradeuser) == false) { return entityBase; } try { DataTable dt = ComFunction.GetPrivileges(); PrivilegeEntity pEntity = null; string PrivilegeName = string.Empty; foreach (DataRow dr in dt.Rows) { PrivilegeName = dr["PrivilegeName"].ToString(); if (("手工报价" == PrivilegeName || "历史数据" == PrivilegeName || "汇率/水" == PrivilegeName) && "ADMIN" != reftradeuser.Account.ToUpper() && "ROOT" != reftradeuser.Account.ToUpper()) { continue; }//只有ADMIN和ROOT账户才返回以上3个权限 pEntity = new PrivilegeEntity(); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.ParentPrivilegeId = dr["ParentPrivilegeId"].ToString(); pEntity.ParentPrivilegeName = dr["ParentPrivilegeName"].ToString(); pEntity.Displayorder = (int)dr["Displayorder"]; list.Add(pEntity); } entityBase.Desc = "获取获取所以权限成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("获取获取所以权限记录数出错,原因:", ex); } return entityBase; }
/// <summary> /// 获取父权限列表 /// </summary> /// <returns></returns> public EntityBase GetPrivilegeParentLit(string loginId, ref List<PrivilegeEntity> list) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { DataTable dt = ComFunction.GetPrivilegeParentLit(); PrivilegeEntity pEntity = null; foreach (DataRow dr in dt.Rows) { pEntity = new PrivilegeEntity(); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.PrivilegeCode = dr["PrivilegeCode"].ToString(); pEntity.ParentPrivilegeId = dr["ParentPrivilegeId"].ToString(); pEntity.ParentPrivilegeName = dr["ParentPrivilegeName"].ToString(); pEntity.PrivilegeType = (PrivilegeType)dr["PrivilegeType"]; pEntity.Library = dr["Library"].ToString(); pEntity.NameSpace = dr["NameSpace"].ToString(); pEntity.MenuPic = dr["MenuPic"].ToString(); pEntity.Displayorder = (int)dr["Displayorder"]; pEntity.Status = (Status)dr["Status"]; pEntity.Remark = dr["Remark"].ToString(); list.Add(pEntity); } entityBase.Desc = "获取获取父权限列表成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("获取获取父权限列表记录数出错,原因:", ex); ManagerLog.WriteErr(ex); } return entityBase; }
/// <summary> /// 新增权限 /// </summary> /// <param name="loginId">登录ID</param> /// <param name="pEntity"></param> /// <returns></returns> public EntityBase AddPrivileges(string loginId, PrivilegeEntity pEntity) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { if (ComFunction.AddPrivileges(pEntity) > 0) { entityBase.Result = true; entityBase.Desc = "权限新增成功"; } else { entityBase.Result = false; entityBase.Desc = "权限新增失败"; } } catch (Exception ex) { entityBase.Result = false; entityBase.Desc = "权限新增失败,原因:" + ex.ToString(); ManagerLog.WriteErr(ex); } return entityBase; }
/// <summary> /// 检查控件权限集合 /// </summary> /// <param name="loginId"></param> /// <param name="userId"></param> /// <param name="type"></param> /// <param name="list"></param> /// <returns></returns> public EntityBase ValidataUserRole(string loginId, string userId, string type, ref List<PrivilegeEntity> list) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { DataTable dt = ComFunction.ValidataUserRole(userId, type); PrivilegeEntity pEntity = null; foreach (DataRow dr in dt.Rows) { pEntity = new PrivilegeEntity(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeCode = dr["PrivilegeCode"].ToString(); list.Add(pEntity); } entityBase.Desc = "获取系统所有角色成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("获取角色记录数出错,原因:", ex); } return entityBase; }
/// <summary> /// 根据用户ID获取所有权限 /// </summary> /// <param name="loginId">登录ID</param> /// <param name="userId"></param> /// <param name="list"></param> /// <returns></returns> public EntityBase UserRolePrivileges(string loginId, string userId, ref List<PrivilegeEntity> list) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { DataTable dt = ComFunction.UserRolePrivileges(userId); PrivilegeEntity pEntity = null; foreach (DataRow dr in dt.Rows) { pEntity = new PrivilegeEntity(); pEntity.PrivilegeId = dr["PrivilegeId"].ToString(); pEntity.PrivilegeName = dr["PrivilegeName"].ToString(); pEntity.ParentPrivilegeId = dr["ParentPrivilegeId"].ToString(); pEntity.ParentPrivilegeName = dr["ParentPrivilegeName"].ToString(); list.Add(pEntity); } entityBase.Desc = "根据用户ID获取所有权限成功!"; entityBase.Result = true; } catch (Exception ex) { SetException("根据用户ID获取所有权限记录出错,原因:", ex); } return entityBase; }
/// <summary> /// 修改权限数据 /// </summary> /// <param name="loginId"></param> /// <param name="pEntity"></param> /// <returns></returns> public EntityBase UpdatePrivileges(string loginId, PrivilegeEntity pEntity) { if (ComFunction.ExistUserLoginID(loginId) == false) { return entityBase; } try { if (ComFunction.UpdatePrivileges(pEntity) > 0) { entityBase.Result = true; entityBase.Desc = "权限修改成功"; } else { entityBase.Result = false; entityBase.Desc = "权限修改失败"; } } catch (Exception ex) { SetException("权限修改失败,原因:", ex); } return entityBase; }
/// <summary> /// 修改权限 /// </summary> /// <param name="pEntity"></param> /// <returns></returns> public static int UpdatePrivileges(PrivilegeEntity pEntity) { string sqlCommand = string.Format(@"UPDATE Base_Privilege SET PrivilegeName = '{1}',PrivilegeCode = '{2}',ParentPrivilegeId = '{3}',ParentPrivilegeName = '{4}', PrivilegeType = '{5}',Library = '{6}',NameSpace = '{7}',MenuPic = '{8}',Displayorder = '{9}',Status = '{10}', Remark = '{10}' WHERE PrivilegeId = '{0}'", pEntity.PrivilegeId, pEntity.PrivilegeName, pEntity.PrivilegeCode, pEntity.ParentPrivilegeId, pEntity.ParentPrivilegeName, (int)pEntity.PrivilegeType, pEntity.Library, pEntity.NameSpace, pEntity.MenuPic, pEntity.Displayorder, (int)pEntity.Status, pEntity.Remark); return DbHelper.ExecuteNonQuery(sqlCommand); }