/// <summary> /// 获取权限树 /// </summary> /// <returns></returns> protected string GetRightTree() { List <Right> rights = new URBasicInfoService().GetRights(SelectedSysID); List <RightItem> selectedRights = UserID > 0 ? new URRightsService().GetUserRights(SelectedSysID, UserID) : new URRightsService().GetRoleRights(RoleID); StringBuilder jsonBuilder = new StringBuilder("["); for (int i = 0; i < rights.Count(); i++) { Right right = rights.ElementAt(i); jsonBuilder.AppendFormat("{{\"id\":\"{0}\",\"pId\":\"{1}\",\"name\":\"{2}\",\"open\":{3}", right.ID, right.ParentID, right.Name, "true"); RightItem rr = selectedRights.FirstOrDefault(r => r.RightID == right.ID); if (rr != null) { jsonBuilder.Append(",\"checked\":true"); if (rr.FromRole) { jsonBuilder.Append(",\"disabled\":true"); } } jsonBuilder.Append("},"); } return(jsonBuilder.ToString().TrimEnd(',') + "]"); }
/// <summary> /// 绑定数据 /// </summary> private void DisplayData() { try { URBasicInfoService biService = new URBasicInfoService(); //特定用户类型要限定特定角色 List <Role> rangeRoles = biService.GetRoles(SelectedSysID); User user = biService.GetUser(UserID); if (user.AccountType == UserTypeOptions.Channel) { rangeRoles = rangeRoles.Where(a => a.RoleType == RoleTypeOptions.Channel).ToList(); } else if (user.AccountType == UserTypeOptions.ChannelPartner) { rangeRoles = rangeRoles.Where(a => a.RoleType == RoleTypeOptions.ChannelPartner).ToList(); } cbkListrole.DataSource = rangeRoles; cbkListrole.DataTextField = "Name"; cbkListrole.DataValueField = "ID"; cbkListrole.DataBind(); List <int> selectedRoleIds = new URRightsService().GetUserRoles(SelectedSysID, UserID); foreach (ListItem item in cbkListrole.Items) { if (selectedRoleIds.Exists(a => int.Parse(item.Value) == a)) { item.Selected = true; } } } catch (NotRightException) { AlertBack("您没有权限执行此操作"); } }
/// <summary> /// 获取所有用户信息 /// </summary> private void ExportToExcel() { Response.Clear(); Response.ContentEncoding = Encoding.UTF8; string fileName = string.Format("Users[{0:yyyyMMdd}].xls", DateTime.Now); if (Request.UserAgent.ToLower().IndexOf("msie") > -1) { fileName = HttpUtility.UrlPathEncode(fileName); } if (Request.UserAgent.ToLower().IndexOf("firefox") > -1) { Response.AddHeader("Content-Type", "application/vnd.ms-excel"); Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); } else { Response.AddHeader("Content-Type", "application/vnd.ms-excel"); Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); } Dictionary <int, HashSet <int> > userSofts; List <Soft> allSofts; List <User> users = new URBasicInfoService().GetReportUsers(out userSofts, out allSofts); Response.Write(@"<table border=""1"" cellpadding=""0"" cellspacing=""0"">"); Response.Write(@"<tr style=""text-align:center;font-weight:bold;""><td>ID</td><td>用户名</td><td>真实姓名</td><td>类型</td><td>邮箱</td><td>部门</td><td>最后登录时间</td><td>状态</td>"); foreach (Soft soft in allSofts) { Response.Write(string.Format("<td>{0}</td>", soft.Name)); } Response.Write("</tr>"); foreach (User user in users) { Response.Write(string.Format(@"<tr style=""text-align:center;""><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6:yyyy-MM-dd HH:mm:ss}</td><td>{7}</td>" , user.ID , user.Account , user.TrueName , URBasicInfoService.GetUserTypeDescipt(user.AccountType) , user.Email , user.Department , user.LastLoginTime , user.Status == StatusOptions.Valid ? "启用" : "禁用")); foreach (Soft soft in allSofts) { if (userSofts.ContainsKey(user.ID) && userSofts[user.ID].Contains(soft.ID)) { Response.Write("<td>√</td>"); } else { Response.Write("<td></td>"); } } Response.Write("</tr>"); } Response.Write("</table>"); Response.Flush(); }
/// <summary> /// 获取指定用户的可选择产品列表 /// </summary> /// <returns></returns> private List <Soft> GetUserSofts(int userId) { List <Soft> softs = new URBasicInfoService().GetSofts(); List <RightItem> softRights = new URRightsService().GetUserSoftRights(userId); List <Soft> userSofts = (from a in softs join b in softRights on a.ID equals b.RightID select a).ToList(); return(userSofts); }
protected void Page_Load(object sender, EventArgs e) { ReturnUrl = HttpUtility.UrlEncode(Request.RawUrl); URBasicInfoService biService = new URBasicInfoService(); List <SystemInfo> list = biService.GetSystems(); repeaData.DataSource = list; repeaData.DataBind(); }
/// <summary> /// 加载产品权限 /// </summary> private void BindSofts() { URBasicInfoService biService = new URBasicInfoService(); URRightsService rightService = new URRightsService(); List <Soft> softs = biService.GetSofts(); List <ProjectSource> projectSources = biService.GetProjectSources(); List <RightItem> selectedSofts = UserID > 0 ? rightService.GetUserSoftRights(UserID) : rightService.GetRoleSoftRights(RoleID); List <RightItem> selectedProjectSources = UserID > 0 ? rightService.GetUserProjectSourceRights(UserID) : rightService.GetRoleProjectSourceRights(RoleID); List <RightItem> resIds = new List <RightItem>(); //产品管理员不能设置资源查看权限 if (loginService.LoginUser.AccountType != UserTypeOptions.ProductAdmin && UserID > 0) { resIds = rightService.GetUserResRights(UserID); } softs.ForEach(soft => { var item = new ListItem("[" + soft.OutID.ToString().PadLeft(6, '0') + "]" + soft.Name, soft.ID.ToString()); RightItem ri = selectedSofts.FirstOrDefault(f => f.RightID == soft.ID); item.Selected = ri != null; item.Enabled = ri == null || !ri.FromRole; item.Attributes.Add("stype", soft.SoftType.ToString()); item.Attributes.Add("intype", "checkbox"); if (soft.SoftType == SoftTypeOptions.InternalSoft || soft.SoftType == SoftTypeOptions.MultiSofts) { cbkListSoft.Items.Add(item); } else { cbkListSoftout.Items.Add(item); } }); if (resIds.Count > 0) { txtResIdList.Text = string.Join(", ", resIds.Select(a => a.RightID.ToString()).ToArray()); } projectSources.ForEach(projectSource => { var item = new ListItem("[" + projectSource.ProjectSourceID + "]" + projectSource.Name, projectSource.ProjectSourceID.ToString()); RightItem ri = selectedProjectSources.FirstOrDefault(f => f.RightID == projectSource.ProjectSourceID); item.Selected = ri != null; item.Enabled = ri == null || !ri.FromRole; item.Attributes.Add("intype", "checkbox"); cbkProjectSource.Items.Add(item); }); }
/// <summary> /// 绑定数据(该方法已经包含权限验证) /// </summary> private void BindData() { URBasicInfoService biService = new URBasicInfoService(); int pageIndex = string.IsNullOrEmpty(Request["page"]) ? 1 : Convert.ToInt32(Request["page"]); int pageSize = string.IsNullOrEmpty(Request["pagesize"]) ? 15 : Convert.ToInt32(Request["pagesize"]); int count = 0; List <User> list = biService.GetUsers(SystemID, Status, AccountType, Keyword, IsOnlyWhiteUser, pageIndex, pageSize, ref count); repeaData.DataSource = list; repeaData.DataBind(); AspNetPager1.RecordCount = count; AspNetPager1.PageSize = pageSize; AspNetPager1.CurrentPageIndex = pageIndex; }
private void BindData() { URBasicInfoService biService = new URBasicInfoService(); int pageIndex = string.IsNullOrEmpty(Request["page"]) ? 1 : Convert.ToInt32(Request["page"]); int pageSize = string.IsNullOrEmpty(Request["pagesize"]) ? 15 : Convert.ToInt32(Request["pagesize"]); int count = 0; List <Role> list = biService.GetRoles(SelectedSysID, pageIndex, pageSize, ref count); repeaData.DataSource = list; repeaData.DataBind(); AspNetPager1.RecordCount = count; AspNetPager1.PageSize = pageSize; AspNetPager1.CurrentPageIndex = pageIndex; }