Ejemplo n.º 1
0
        /// <summary>
        /// 添加按钮
        /// </summary>
        public void AddButton()
        {
            var requestData = JSONHelper.GetModel <Dictionary <string, object> >(RequestParameters.dataStr);
            EHECD_MenuButtonDTO addbutton = JSONHelper.GetModel <EHECD_MenuButtonDTO>(requestData["btn"].ToString());
            string menuID = requestData["menuID"].ToString();
            //菜单业务对象
            IMenuManager menubll = DI.DIEntity.GetInstance().GetImpl <IMenuManager>();

            CreateSyslogInfo();
            addbutton = menubll.AddButton(addbutton, menuID, RequestParameters.dynamicData);

            if (addbutton != null)
            {
                //从session获取用户的权限和菜单等信息
                var userRoleMenu = GetSessionInfo(SessionInfo.USER_MENUS /*用户的权限和菜单等信息*/) as UserRoleMenuInfo;

                if (userRoleMenu != null)
                {
                    //构建返回给界面的节点信息
                    result.Data = new
                    {
                        id         = addbutton.ID,
                        attributes = new { type = "btn" },
                        text       = addbutton.sButtonName,
                        iconCls    = addbutton.sIcon
                    };

                    //从会话用户菜单中找到这个按钮所属的按钮并将其添加进去
                    Parallel.For(0, userRoleMenu.AllMenu.Count, (index, state) =>
                    {
                        if (userRoleMenu.AllMenu[index].ID.ToString() == menuID)
                        {
                            userRoleMenu.AllMenu[index].Buttons.Add(new UserMenuButton
                            {
                                ID          = addbutton.ID,
                                iOrder      = addbutton.iOrder,
                                sButtonName = addbutton.sButtonName,
                                sDataID     = addbutton.sDataID,
                                sIcon       = addbutton.sIcon
                            });
                            state.Stop();
                            return;
                        }
                    });

                    //重新获取菜单结构
                    userRoleMenu.UserMenu = InitMenu(userRoleMenu.AllMenu);
                    SetSessionInfo(SessionInfo.USER_MENUS /*用户的权限和菜单等信息*/, userRoleMenu);
                    result.Succeeded = true;
                }
                else
                {
                    result.Succeeded = false;
                    result.Msg       = "会话菜单缓存获取失败";
                    return;
                }
            }
            else
            {
                result.Succeeded = false;
                result.Msg       = "添加菜单按钮失败,请联系管理员";
            }
        }