public void BuildAccessTree(AccessPermissionTree tree)
 {
     this.Dispatcher.BeginInvoke((Action<AccessPermissionTree>)delegate(AccessPermissionTree result)
     {
         this.AccessTree.ItemsSource = result.CategoryNodes;
     }, tree);
 }
 public void UpdateRolePermission(int roleId, int editType, string roleName, AccessPermissionTree accessTree, DataPermissionTree dataTree, Action<bool> EndUpdatePermission)
 {
     this._ServiceProxy.BeginUpdateRolePermission(roleId, editType, roleName, accessTree, dataTree, delegate(IAsyncResult ar)
     {
         bool isSuccess = this._ServiceProxy.EndUpdateRolePermission(ar);
         EndUpdatePermission(isSuccess);
     }, null);
 }
        public static void UpdateRolePermission(int roleId,int editType, string roleName, AccessPermissionTree accessTree, DataPermissionTree dataTree)
        {
            string xmlAccessTree = string.Empty;
            string xmlDataTree = string.Empty;
            if (editType == 1)
            {
                StringBuilder accessStr = new StringBuilder();
                accessStr.Append("<AccessTree>");
                foreach (CategoryNode cate in accessTree.CategoryNodes)
                {
                    foreach (ModuleNode module in cate.ModuleNodes)
                    {
                        foreach (OperationNode operation in module.OperationNodes)
                        {
                            accessStr.AppendFormat("<Access Id=\"{0}\"/>", operation.Id);
                        }
                    }
                }
                accessStr.Append("</AccessTree>");
                xmlAccessTree = accessStr.ToString();

                StringBuilder dataStr = new StringBuilder();
                dataStr.Append("<DataTree>");
                foreach (DataPermission data in dataTree.DataPermissions)
                {
                    foreach (ExChangeSystem sys in data.ExChangeSystems)
                    {
                        foreach (Target target in sys.Targets)
                        {
                            dataStr.AppendFormat("<Data Id=\"{0}\"/>", target.TargetId);
                        }
                    }
                }
                dataStr.Append("</DataTree>");
                xmlDataTree = dataStr.ToString();
            }
            using (SqlConnection sqlConnection = DataAccess.GetSqlConnection())
            {
                SqlCommand command = sqlConnection.CreateCommand();
                command.CommandText = "dbo.UpdateRolePermission";
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@roleId", roleId));
                if (editType ==0)
                {
                    command.Parameters.Add(new SqlParameter("@roleName", roleName));
                }
                if (editType == 1)
                {
                    command.Parameters.Add(new SqlParameter("@xmlAccessTree", xmlAccessTree));
                    command.Parameters.Add(new SqlParameter("@xmlDataTree", xmlDataTree));
                }
                command.ExecuteNonQuery();
            }
        }
 public bool UpdateRolePermission(int roleId,int editType, string roleName, AccessPermissionTree accessTree, DataPermissionTree dataTree)
 {
     UserDataAccess.UpdateRolePermission(roleId,editType,roleName,accessTree,dataTree);
     return true;
 }
 public static AccessPermissionTree GetAccessPermissionTree(int roleId)
 {
     AccessPermissionTree tree = new AccessPermissionTree();
     using (SqlConnection sqlConnection = DataAccess.GetSqlConnection())
     {
         SqlCommand command = sqlConnection.CreateCommand();
         command.CommandText = "dbo.InitAccessPermissionTree";
         command.CommandType = System.Data.CommandType.StoredProcedure;
         command.Parameters.Add(new SqlParameter("@roleId", roleId));
         SqlDataReader reader = command.ExecuteReader();
         while (reader.Read())
         {
             CategoryNode node = new CategoryNode();
             node.Id = (int)reader.GetValue(0);
             node.CategoryDescription = reader.GetValue(1).ToString();
             tree.CategoryNodes.Add(node);
         }
         reader.NextResult();
         while (reader.Read())
         {
             ModuleNode node = new ModuleNode();
             node.Id = (int)reader.GetValue(0);
             node.ModuleDescription = reader.GetValue(2).ToString();
             tree.CategoryNodes.Find(c => c.Id == (int)reader.GetValue(1)).ModuleNodes.Add(node);
         }
         reader.NextResult();
         while (reader.Read())
         {
             OperationNode node = new OperationNode();
             node.Id = (Guid)reader.GetValue(2);
             node.OperationDescription = reader.GetValue(3).ToString();
             tree.CategoryNodes.Find(c => c.Id == (int)reader.GetValue(0)).ModuleNodes.Find(m => m.Id == (int)reader.GetValue(1)).OperationNodes.Add(node);
         }
     }
     return tree;
 }