protected void btnSave_Click(object sender, EventArgs e)
        {
            List <int> softIds = new List <int>();

            foreach (ListItem item in cbkListSoft.Items)
            {
                if (item.Selected)
                {
                    softIds.Add(int.Parse(item.Value));
                }
            }
            foreach (ListItem item in cbkListSoftout.Items)
            {
                if (item.Selected)
                {
                    softIds.Add(int.Parse(item.Value));
                }
            }
            List <int> projectSources = new List <int>();

            foreach (ListItem item in cbkProjectSource.Items)
            {
                if (item.Selected)
                {
                    projectSources.Add(int.Parse(item.Value));
                }
            }
            List <int> resIds = new List <int>();

            if (txtResIdList.Text.Length > 0)
            {
                string[] resids = txtResIdList.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string resid in resids)
                {
                    int id = 0;
                    if (int.TryParse(resid.Trim(), out id))
                    {
                        resIds.Add(id);
                    }
                }
            }
            URRightsService rightService = new URRightsService();

            if (UserID > 0)
            {
                rightService.AddUserSoftRights(UserID, softIds);
                rightService.AddUserProjectSourceRights(UserID, projectSources);
                if (loginService.LoginUser.AccountType != UserTypeOptions.ProductAdmin)
                {
                    rightService.AddUserResRights(UserID, resIds);
                }
            }
            else if (RoleID > 0)
            {
                rightService.AddRoleSoftRights(RoleID, softIds);
                rightService.AddRoleProjectSourceRights(RoleID, projectSources);
            }

            Response.Redirect(ReturnUrl);
        }
Exemple #2
0
 /// <summary>
 /// 绑定数据
 /// </summary>
 private void DisplayData()
 {
     try
     {
         cbkSystems.DataSource     = loginService.AdminSystems;
         cbkSystems.DataTextField  = "Name";
         cbkSystems.DataValueField = "ID";
         cbkSystems.DataBind();
         cbkAdminSystems.DataSource     = loginService.AdminSystems;
         cbkAdminSystems.DataTextField  = "Name";
         cbkAdminSystems.DataValueField = "ID";
         cbkAdminSystems.DataBind();
         List <UserSystem> selectedUserSystems = new URRightsService().GetUserSystems(UserID);
         foreach (ListItem item in cbkSystems.Items)
         {
             if (selectedUserSystems.Exists(a => int.Parse(item.Value) == a.SystemID))
             {
                 item.Selected = true;
             }
         }
         foreach (ListItem item in cbkAdminSystems.Items)
         {
             if (selectedUserSystems.Exists(a => int.Parse(item.Value) == a.SystemID && a.Admin))
             {
                 item.Selected = true;
             }
         }
     }
     catch (NotRightException)
     {
         AlertBack("您没有权限执行此操作");
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (RoleID > 0)
         {
             int sysId = GetQueryString("sysId").ToInt32(0);
             if (sysId <= 0)
             {
                 throw new NotRightException();
             }
             ddlSystems.DataSource = loginService.AdminSystems.Where(a => a.ID == sysId);
         }
         else
         {
             List <UserSystem> userSystems = new URRightsService().GetUserSystems(UserID);
             ddlSystems.DataSource = loginService.AdminSystems.Where(a => userSystems.Exists(b => a.ID == b.SystemID));
         }
         ddlSystems.DataTextField  = "Name";
         ddlSystems.DataValueField = "ID";
         ddlSystems.DataBind();
         ddlSystems.SelectedValue = Request["sysId"];
         ddlSystems.AutoPostBack  = true;
     }
     PageTitle = string.Format("为{0}【{1}】设置权限", UserID > 0 ? "用户" : "角色", GetQueryString("name"));
 }
Exemple #4
0
 /// <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>
        /// <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);
        }
        /// <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);
            });
        }
Exemple #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         List <UserSystem> userSystems = new URRightsService().GetUserSystems(UserID);
         ddlSystems.DataSource     = loginService.AdminSystems.Where(a => userSystems.Exists(b => a.ID == b.SystemID));
         ddlSystems.DataTextField  = "Name";
         ddlSystems.DataValueField = "ID";
         ddlSystems.DataBind();
         ddlSystems.SelectedValue = Request["sysId"];
         ddlSystems.AutoPostBack  = true;
         DisplayData();
     }
 }