Beispiel #1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     if (this.RoleId > 0)
     {
         RoleGetResponse roleGetResponse = LocalApi.Execute(new RoleGetRequest()
         {
             RoleId = this.RoleId
         });
         this.dialogTitle.Content = "修改角色";
         if (roleGetResponse.Role != null)
         {
             this.RoleName = roleGetResponse.Role.RoleName;
             this.Remark   = roleGetResponse.Role.Remark;
             List <string> permissionCodes = ((IEnumerable <string>)(roleGetResponse.Role.PermissionCodes ?? "").Split(',')).Where <string>(m => !string.IsNullOrEmpty(m)).ToList();
             this.Menus      = this.BuildMenuCodes(PermissionNode.BuildPermissionNodes((LocalApi.Execute(new PermissionListRequest())).Permissions), permissionCodes);
             permissionCodes = null;
         }
     }
     else
     {
         this.dialogTitle.Content = "添加角色";
         this.Menus = this.BuildMenuCodes(PermissionNode.BuildPermissionNodes((LocalApi.Execute(new PermissionListRequest())).Permissions), new List <string>());
     }
     this.DataContext = this;
 }
Beispiel #2
0
        /// <summary>
        /// 用于前端组织结构权限管理界面加载整个权限树
        /// </summary>
        public async Task <object> LoadPermissionNodes()
        {
            var list = new List <PermissionNode>();

            var apps = await Store.ModelStore.LoadAllApplicationAsync();

            //TODO:***暂简单实现加载全部,待优化为加载特定类型
            var allFolders = await Store.ModelStore.LoadAllFolderAsync();

            var allModels = await Store.ModelStore.LoadAllModelAsync();

            var folders     = allFolders.Where(t => t.TargetModelType == ModelType.Permission);
            var permissions = allModels.Where(t => t.ModelType == ModelType.Permission);

            for (int i = 0; i < apps.Length; i++)
            {
                var appNode = new PermissionNode(apps[i].Name);
                list.Add(appNode);

                var folderIndex = new Dictionary <Guid, PermissionNode>();
                //加载文件夹
                var rootFolder = folders.SingleOrDefault(t => t.AppId == apps[i].Id);
                if (rootFolder != null)
                {
                    LoopAddFolder(folderIndex, appNode, rootFolder);
                }
                //加载PermissionModels
                var appPermissions = permissions.Where(t => t.AppId == apps[i].Id).Cast <PermissionModel>();
                foreach (var p in appPermissions)
                {
                    var modelNode = new PermissionNode(p);
                    if (p.FolderId.HasValue)
                    {
                        if (folderIndex.TryGetValue(p.FolderId.Value, out PermissionNode folderNode))
                        {
                            folderNode.Childs.Add(modelNode);
                        }
                        else
                        {
                            appNode.Childs.Add(modelNode);
                        }
                    }
                    else
                    {
                        appNode.Childs.Add(modelNode);
                    }
                }
            }

            return(list);
        }
Beispiel #3
0
        private static void LoopAddFolder(Dictionary <Guid, PermissionNode> dic, PermissionNode parent, ModelFolder folder)
        {
            var parentNode = parent;

            if (folder.Parent != null)
            {
                var node = new PermissionNode(folder.Name);
                dic.Add(folder.Id, node);
                parent.Childs.Add(node);
                parentNode = node;
            }

            if (folder.HasChilds)
            {
                for (int i = 0; i < folder.Childs.Count; i++)
                {
                    LoopAddFolder(dic, parentNode, folder.Childs[i]);
                }
            }
        }
Beispiel #4
0
 public PermissionNodeAttribute(PermissionNode node)
 {
     Node = node;
 }
        private void tvwMenu_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            PermissionNode tag = (PermissionNode)tvwMenu.SelectedItem;

            if (tag == null)
            {
                return;
            }
            if ((tag != this.lastSelectdChildNode) && (this.lastSelectdChildNode != null))
            {
                //this.lastSelectdChildNode.Button.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
            }
            this.lastSelectdChildNode = tag;
            //tag.Button.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/TengDa.UI;component/image/menu_child_button_bg.png", UriKind.Absolute)));//state_abnormal.png

            switch (tag.Code)
            {
            case "Situation.Standby":
                MainMonitorPage MonitorPage = new MainMonitorPage();
                NavigatePage(tag.Text, MonitorPage);
                break;

            //case "Situation.Standby":
            //    this.mainPage.Navigate(new Uri("BakingPage.xaml", UriKind.Relative));
            //    break;
            case "UserManager.Personal":
                PersonalInfoPage page = new PersonalInfoPage();
                NavigatePage(tag.Text, page);
                //this.mainPage.Navigate(new Uri("Views/PersonalInfoPage.xaml", UriKind.Relative));
                break;

            case "UserManager.User":
                UserManagerPage userPage = new UserManagerPage();
                NavigatePage(tag.Text, userPage);
                //this.mainPage.Navigate(new Uri("Views/UserManagerPage.xaml", UriKind.Relative));
                break;

            case "UserManager.Role":
                RoleManagerPage RolePage = new RoleManagerPage();
                NavigatePage(tag.Text, RolePage);
                break;

            case "ChuckingManager.ChuckingInfoPage":
                ChuckingInfoPage ChuckingPage = new ChuckingInfoPage();
                NavigatePage(tag.Text, ChuckingPage);
                break;

            case "MESManager.MESInfoPage":
                MESInfoPage MESPage = new MESInfoPage();
                NavigatePage(tag.Text, MESPage);
                break;

            case "MonitorView.TemperaturePage":
                TemperaturePage Tempe = new TemperaturePage();
                NavigatePage(tag.Text, Tempe);
                break;

            case "MonitorView.RunLogPage":
                RunLogPage log = new RunLogPage();
                NavigatePage(tag.Text, log);
                break;

            case "MonitorView.HistoryTemPage":
                HistoryTemPage htp = new HistoryTemPage();
                NavigatePage(tag.Text, htp);
                break;

            case "MonitorView.HistoryErrorPage":
                HistoryErrorPage hep = new HistoryErrorPage();
                NavigatePage(tag.Text, hep);
                break;

            case "MonitorView.MANUDebugging":
                MANUDebuggingPage manud = new MANUDebuggingPage();
                NavigatePage(tag.Text, manud);
                break;
            }
            popusBottom.IsOpen = false;
        }
Beispiel #6
0
        static void CreateGroup(string name, bool guest, string parent, byte r, byte g, byte b, string[] nodes, IDbConnection ctx, IDbTransaction txn,
                                string chatPrefix = null,
                                string chatSuffix = null)
#endif

        {
#if ENTITY_FRAMEWORK_7
            var grp = new Group()
            {
                Name          = name,
                ApplyToGuests = guest,
                Parent        = parent,
                Chat_Red      = r,
                Chat_Green    = g,
                Chat_Blue     = b,
                Chat_Prefix   = chatPrefix,
                Chat_Suffix   = chatSuffix
            };
            ctx.Groups.Add(grp);

            ctx.SaveChanges(); //Save to get the ID

            foreach (var nd in nodes)
            {
                var node = ctx.Nodes.SingleOrDefault(x => x.Node == nd && x.Permission == Permission.Permitted);
                if (node == null)
                {
                    ctx.Nodes.Add(node = new NodePermission()
                    {
                        Node       = nd,
                        Permission = Permission.Permitted
                    });

                    ctx.SaveChanges();
                }

                ctx.GroupNodes.Add(new GroupNode()
                {
                    GroupId = grp.Id,
                    NodeId  = node.Id
                });
            }

            ctx.SaveChanges();
#elif DAPPER
            var grp = new Group()
            {
                Name          = name,
                ApplyToGuests = guest,
                Parent        = parent,
                Chat_Red      = r,
                Chat_Green    = g,
                Chat_Blue     = b,
                Chat_Prefix   = chatPrefix,
                Chat_Suffix   = chatSuffix
            };


            grp.Id = ctx.Insert(grp, txn);
            foreach (var nd in nodes)
            {
                var node = ctx.SingleOrDefault <PermissionNode>(new { Node = nd, Permission = Permission.Permitted }, transaction: txn);
                if (node == null)
                {
                    node = new PermissionNode()
                    {
                        Node       = nd,
                        Permission = Permission.Permitted
                    };
                    node.Id = ctx.Insert(node, transaction: txn);
                }

                ctx.Insert(new GroupNode()
                {
                    GroupId = grp.Id,
                    NodeId  = node.Id
                }, transaction: txn);
            }
#endif
        }