/// <summary> /// 增加权限记录, 如果存在则更新 /// 返回影响的行数,失败返回0 /// </summary> /// <param name="pid">页面ID</param> /// <param name="btnRightExp">按钮权限表达式</param> /// <param name="aid">管理员ID</param> public int AddOrUpdate(int pid, string btnRightExp, bool updateWhenExists, params int[] aid) { int result = 0; Safe.Base.Contract.IDbHelper qmnobj = SQLHelpers.TcAdmin(); qmnobj.SetHandClose(false); try { if (aid != null) { foreach (int item in aid) { string pname = "p_AddUpdateAdminRight"; SqlParameter[] parameters = { new SqlParameter("@aid", SqlDbType.Int, 4), new SqlParameter("@pid", SqlDbType.Int, 4), new SqlParameter("@btnRightExp", SqlDbType.NVarChar, 20), new SqlParameter("@updateWhenExists", true) }; parameters[0].Value = item; parameters[1].Value = pid; parameters[2].Value = btnRightExp; result = result + qmnobj.ExecuteProc(pname, false, parameters).ReturnValue; } } } finally { qmnobj.EndConnection(); } return(result); }
/// <summary> /// 批量更新权限 /// 返回受影响的行数 /// </summary> /// <param name="aids">管理员ID数组</param> /// <param name="info">权限集合</param> public int UpdateRights(int[] aids, Dictionary <int, string> info) { int result = 0; Safe.Base.Contract.IDbHelper qmnobj = SQLHelpers.TcAdmin(); qmnobj.SetHandClose(false); try { foreach (int aid in aids) { foreach (KeyValuePair <int, string> item in info) { string pname = "p_AddUpdateAdminRight"; SqlParameter[] parameters = { new SqlParameter("@aid", aid), new SqlParameter("@pid", item.Key), new SqlParameter("@btnRightExp", item.Value), new SqlParameter("@updateWhenExists", true) }; result = result + qmnobj.ExecuteProc(pname, false, parameters).ReturnValue; } } } finally { qmnobj.EndConnection(); } return(result); }
/// <summary> /// 增加或更新数据, 如果存在则更新 /// </summary> /// <param name="pid">页面ID</param> /// <param name="btnRightExp">访问权限</param> /// <param name="gids">组ID</param> /// <returns></returns> public int AddOrUpdate(int pid, string btnRightExp, bool updateWhenExists, params int[] gids) { int result = 0; Safe.Base.Contract.IDbHelper qmnobj = SQLHelpers.TcAdmin(); qmnobj.SetHandClose(false); try { if (gids != null) { foreach (int gid in gids) { string pname = "p_AddUpdateGroupRight"; SqlParameter[] parameters = { new SqlParameter("@gid", gid), new SqlParameter("@pid", pid), new SqlParameter("@btnRightExp", btnRightExp), new SqlParameter("@updateWhenExists", updateWhenExists) }; result = result + qmnobj.ExecuteProc(pname, false, parameters).ReturnValue; } } } finally { qmnobj.EndConnection(); } return(result); }
/// <summary> /// 根据用户名获取一个管理员信息实体 /// <param name="aname">用户名</param> /// </summary> public MR_Admin GetModel(string aname, string ip) { Safe.Base.Contract.IDbHelper dbHelper = SQLHelpers.TcAdmin(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AID,AName,ANickName,IP,Email,R_Admin.GID ,R_Admin.ALastTime from R_Admin "); strSql.Append(" where AName=@AName "); SqlParameter[] parameters = { new SqlParameter("@AName", aname) }; DataTable dtbl = dbHelper.ExecuteFillDataTable(strSql.ToString(), parameters); if (dtbl.Rows.Count > 0) { MR_Admin result = Safe.Base.Utility.ModelConvertHelper <MR_Admin> .ToModel(dtbl.Rows[0]); dbHelper.ExecuteNonQuery("UPDATE R_Admin SET ALastTime=getdate() , IP=@ip Where AID=@aid", new SqlParameter("@aid", result.AID), new SqlParameter("@ip", ip)); return(result); } else { return(null); } } finally { dbHelper.EndConnection(); } }
/// <summary> /// 取得组的预设菜单, 不含隐藏目录 /// </summary> /// <param name="groupID">组ID</param> /// <param name="parentID">用户ID</param> /// <param name="includeChild">是否同时取子节点</param> /// <returns></returns> public IList <MR_PageInfo> GetList(int groupID, int parentID, bool includeChild) { IList <MR_PageInfo> result = new List <MR_PageInfo>(); Safe.Base.Contract.IDbHelper tqmn = SQLHelpers.TcAdmin(); tqmn.SetHandClose(false); try { GetChilds(groupID, parentID, includeChild, ref result, ref tqmn); return(result); } finally { tqmn.EndConnection(); } }
/// <summary> /// 删除管理员对某个页面的访问权限(会同时删除子页面,不含隐藏页)返回1 /// </summary> /// <param name="PID">页面ID</param> /// <param name="AID">管理员ID</param> public int Delete(int PID, IList <int> AID) { Safe.Base.Contract.IDbHelper dbhelper = SQLHelpers.TcAdmin(); dbhelper.SetHandClose(true); try { foreach (int taid in AID) { Delete(PID, taid, dbhelper); } } finally { dbhelper.EndConnection(); } return(1); }
private void Delete(int PID, int AID, Safe.Base.Contract.IDbHelper dbhelper) { IList <MR_PageInfo> childs = GetChild(PID, AID, ref dbhelper); if (childs != null) { foreach (MR_PageInfo tmp in childs) { Delete(tmp.PID, AID, dbhelper); } } string cmdText = "delete from R_AdminRight where AID=@AID and PID=@PID"; SqlParameter[] parameters = { new SqlParameter("@AID", AID), new SqlParameter("@PID", PID) }; dbhelper.ExecuteNonQuery(cmdText, parameters); }
/// <summary> /// 取得管理员在某个页面下是否有子项 /// </summary> /// <param name="pid"></param> /// <param name="aid"></param> /// <returns></returns> private IList <MR_PageInfo> GetChild(int pid, int aid, ref Safe.Base.Contract.IDbHelper dbhelper) { StringBuilder sb = new StringBuilder(); sb.Append("SELECT R_PageInfo.* FROM R_PageInfo LEFT JOIN R_AdminRight on R_AdminRight.PID = R_PageInfo.PID WHERE R_AdminRight.AID=@aid and R_PageInfo.ParentID=@pid "); DataTable dt = dbhelper.ExecuteFillDataTable(sb.ToString(), new SqlParameter("@aid", aid), new SqlParameter("@pid", pid)); if (dt == null) { return(null); } if (dt.Rows.Count == 0) { return(null); } return(Safe.Base.Utility.ModelConvertHelper <MR_PageInfo> .ToModels(dt)); }
/// <summary> /// 登录后取得对应权限,不含隐藏菜单 /// </summary> /// <param name="adminId">管理员ID</param> /// <param name="parentID">父节点ID</param> /// <param name="includeChild">是否同时取子节点</param> public IList <MR_PageInfo> GetMenus(int adminId, int parentID, bool includeChild, bool updateClickTime) { IList <MR_PageInfo> result = new List <MR_PageInfo>(); Safe.Base.Contract.IDbHelper tqmn = SQLHelpers.TcAdmin(); tqmn.SetHandClose(false); try { GetChilds(adminId, parentID, includeChild, ref result, ref tqmn); if (result != null && result.Count > 0 && updateClickTime) { string sql = "UPDATE R_AdminRight SET ClickTimes=ClickTimes+1 WHERE AID=@AID AND PID=@PID"; tqmn.ExecuteNonQuery(sql, new SqlParameter("@AID", adminId), new SqlParameter("@PID", parentID)); } return(result); } finally { tqmn.EndConnection(); } }
private void GetChilds(int adminId, int parentID, bool incluedChild, ref IList <MR_PageInfo> result, ref Safe.Base.Contract.IDbHelper dbhelper) { StringBuilder sb = new StringBuilder(); sb.Append("select a.*,b.btnrightexp from r_pageinfo as a left join r_adminright as b on a.pid=b.pid where b.aid=@aid and a.parentID=@parentID order by a.Queue asc, b.ClickTimes desc"); SqlParameter[] sqlparams = new SqlParameter[] { new SqlParameter("@aid", adminId), new SqlParameter("@parentID", parentID) }; DataTable tbl = SQLHelpers.TcAdmin().ExecuteFillDataTable(sb.ToString(), sqlparams); result = Safe.Base.Utility.ModelConvertHelper <MR_PageInfo> .ToModels(tbl); //该结点的子节点 if (incluedChild && result != null) { foreach (MR_PageInfo tmpc in result) { IList <MR_PageInfo> childs = null; GetChilds(adminId, tmpc.PID, incluedChild, ref childs, ref dbhelper); tmpc.Childs = childs.ToList(); } } }
private void GetChilds(int groupId, int parentID, bool incluedChild, ref IList <MR_PageInfo> result, ref Safe.Base.Contract.IDbHelper dbhelper) { StringBuilder sb = new StringBuilder(); sb.Append("select a.*,b.btnrightexp from r_pageinfo as a left join R_GroupRight as b on a.pid=b.pid where b.gid=@gid and a.parentID=@parentID"); SqlParameter[] sqlparams = new SqlParameter[] { new SqlParameter("@gid", groupId), new SqlParameter("@parentID", parentID) }; DataTable tbl = SQLHelpers.TcAdmin().ExecuteFillDataTable(sb.ToString(), sqlparams); IList <MR_PageInfo> tmp = Safe.Base.Utility.ModelConvertHelper <MR_PageInfo> .ToModels(tbl); //该结点的子节点 if (tmp != null) { foreach (MR_PageInfo tmpc in tmp) { if (!result.Contains(tmpc)) { result.Add(tmpc); if (incluedChild) { GetChilds(groupId, tmpc.PID, incluedChild, ref result, ref dbhelper); } } } } }