Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if(!IsPostBack)
     {
         var id = Request["Id"];
         try
         {
            
             BindStatus();
             if(String.IsNullOrEmpty(id))
             {
                 hfId.Value = "";
                 ViewState["OpStatues"] = "Add";
                 var role = new Role();
                 DataBindHelper<Role>.Bind(form1, role);
                 Session["Role"] = role;
                 btnPrivilege.Visible = false;
                 btnUser.Visible = false;
                 Session.Remove("RoleCondtion");
             }
             else
             {
                 hfId.Value = id;
                 ViewState["OpStatues"] = "Update";
                 var guidRoleId = new Guid(id);
                 ViewState["guidRoleId"] = id;
                 BindControl(guidRoleId);
                 btnPrivilege.Visible = true;
                 btnUser.Visible = true;
             }
            
            
         }
         catch
         {
             Page.ClientScript.RegisterStartupScript(GetType(), ""
                                              , "alert('加载数据失败!')", true);
         }
         
     }
 }
Exemple #2
0
     private void FixupRole(Role previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.SysUser_Role.Contains(this))
         {
             previousValue.SysUser_Role.Remove(this);
         }
 
         if (Role != null)
         {
             if (!Role.SysUser_Role.Contains(this))
             {
                 Role.SysUser_Role.Add(this);
             }
 
             RoleID = Role.RoleID;
         }
         else if (!skipKeys)
         {
             RoleID = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Role")
                 && (ChangeTracker.OriginalValues["Role"] == Role))
             {
                 ChangeTracker.OriginalValues.Remove("Role");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Role", previousValue);
             }
             if (Role != null && !Role.ChangeTracker.ChangeTrackingEnabled)
             {
                 Role.StartTracking();
             }
         }
     }
 /// <summary>
 /// 添加角色 
 /// </summary>
 /// <param name="item"></param>
 public void Add(Role item)
 {
     _roleRepository.Add(item);
     _roleRepository.UnitOfWork.Commit();
 }
 /// <summary>
 /// 修改角色
 /// </summary>
 /// <param name="item"></param>
 public void Modify(Role item)
 {
     _roleRepository.Modify(item);
 }
        /// <summary>
        /// 读取页面数据
        /// </summary>
        /// <param name="role"></param>
        private void GetDataSourceFormTree(Role role)
        {
            if (role == null)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('加载数据失败!')", true);
                return;
            }
            var nodes = trvwAppModule.GetAllNodes();
            if (nodes != null && nodes.Count > 0)
            {
                foreach (RadTreeNode node in nodes)
                {
                    if (node.Nodes.Count > 0)
                    {
                        var id = node.Value;
                        if (!String.IsNullOrEmpty(id) && !node.Checked)
                        {
                            var modelId = new Guid(id);
                            var rolePrivilege = role.Role_Privilege.Where(it => it.ModuleID == modelId).SingleOrDefault();
                            if (rolePrivilege != null)
                                role.Role_Privilege.Remove(rolePrivilege);
                        }
                        continue;
                    }
                    if (node.Nodes.Count == 0)
                    {
                        var parentNode = node.ParentNode;
                        if (parentNode == null) continue;
                        var modelId = new Guid(parentNode.Value);
                        var rolePrivilege = role.Role_Privilege.Where(it => it.ModuleID == modelId).SingleOrDefault();
                        if (!node.Checked)
                        {
                            if (rolePrivilege != null)
                            {
                                rolePrivilege.PrivilegeDesc = rolePrivilege.PrivilegeDesc & (~(-Convert.ToInt32(node.Value)));
                            }
                            continue;
                        }
                        if (rolePrivilege != null)
                        {
                            rolePrivilege.PrivilegeDesc = rolePrivilege.PrivilegeDesc | Convert.ToInt32(node.Value);
                        }
                        else
                        {
                            rolePrivilege = new Role_Privilege
                            {
                                Role_PrivilegeID = Guid.NewGuid(),
                                RoleID = role.RoleID,
                                ModuleID = modelId
                            };
                            rolePrivilege.PrivilegeDesc = rolePrivilege.PrivilegeDesc | Convert.ToInt32(node.Value);
                            rolePrivilege.CreateTime = DateTime.Now;
                            role.Role_Privilege.Add(rolePrivilege);
                        }

                    }
                }
            }
        }
 /// <summary>
 /// 获取数据
 /// </summary>
 private void GetDataFromPage(Role role)
 {
     if (role == null) return;
     var dataSouce = (IList<SysUser>) Session["lvwUserSource"];
     role.SysUser_Role.Clear();
     if (dataSouce == null || dataSouce.Count == 0)
     {
         return;
     }
     foreach (var item in dataSouce)
     {
         var rp = new SysUser_Role
                      {
                          SysUser_RoleID = Guid.NewGuid(),
                          RoleID = role.RoleID,
                          UID = item.UID
                      };
         role.SysUser_Role.Add(rp);
     }
 }